Loading AMD module inside JavaScriptCore

I would like to load a javascript module inside JavascriptCore (on iOS).

I am fetching the text of a file using a normal iOS side HTTP request. So I can parse this whole line into JScontext.

But now I want to load this module and, ideally, resolve any other dependencies, although this is not essential.

I tried using requireJS for node, but it seems to have a lot of dependency errors and it might be a little outdated.

I also tried to steal, but I'm not sure if this is the right way. I tried this too. https://github.com/millermedeiros/nodefy

Basically I want to do what js requires in a browser, but in a pure javascript environment (no browser, no node).

I also want to link everything with a browser, and looked at things like this - RequireJS load string

The problem is when I go to the code browser (require, requirejs) the process fails with unreasonable dependencies?

Can anyone point me in the right direction?

+3


source to share


1 answer


The technologies you are talking about are not completely compatible with each other. Consider a string like require('meow')

. With the browser / webpack / etc, the file to be loaded will be node_modules/meow/main.js

(depending on what package.json says is the main file). In requirejs, this same file will load the path /meow

through the browser or from the baseUrl root of your project. The way to override this is to add config options to requirejs. This is very painful because it effectively forces you to create an entry for each package in node_modules. In short, you can't combine requirejs and browser without a lot of work.

To set up code splitting using a browser or webpack, you need to define a new entry point for the package. Then when you download it from your application you need to download that js package by doing something like fetch('https://myserver.com/bundle2.js').then()...

. There are several tools that can help you do this using a webpack or browser.



Web Story is not very good around this right now (since 2017). Most systems do it differently.

+4


source







All Articles