Browserify is an invaluable tool to pack codes to create SEApp, besides it typical uses of course =)
Here, we pack all its ✨Magic ✨ into a SEApp, you don't have to lug round a whole nested folder of countless dependencies and files.
Making SEApps can be a bliss with makeSea if your app is small. However, if your app is complex and uses countless dependencies, it can be a nightmare, even with the help of browserify.
This is an exploration of bundling the mammoth browserify into a SEApp.
- Pack browserify using itself =) - to say, browerify.packed.js.
- Test it out and figure out what does Not work.
> node browerify.packed.js
...errors erupt...
- Resolve those issues.
- Repeat... until the packed content works.
- browserify's commandline entry point is in `bin/cmd.js' - so wrap it up in a function and export it, if we wish to reuse it programmatically.
- If not, it can be left as is. And it will still be triggered when the SEApp runs.
require.resolve
calls - there're many of these in 2 areas (acorn-node/build.js & browserify/lib/builtins.js). They crash the SEApp.- A solution that works is to just return '.' for all of them - don't know if it breaks anything else under the hood.
if (typeof require.resolve !== 'function') require.resolve = () => '.'; //prepend this faker
browser-pack/index.js
looks for an external_prelude.js
- which fails to be found in a packed environment.- Solution: Copy and paste the contents of
_prelude.js
into the codes instead.
- Solution: Copy and paste the contents of
And surprisingly, that's all it takes, phew~
- Minify browserify.packed.js using babel-minify to further shrink it. To say, browerify.js.
- Well, there's really nothing else needed in this case for a browserify SEApp. Thus, we can use the minified file directly with makeSea to generate the browserify.exe =)
> node makeSea.js browserify.js
...
tada~ browserify.exe is produced.
All browserify's options as per normal. E.g.:
browserify.exe list_of_requires.js --node -o list_of_requires.packed.js