Skip to content

Instantly share code, notes, and snippets.

@kumavis
Last active December 18, 2015 01:19
Show Gist options
  • Save kumavis/5703360 to your computer and use it in GitHub Desktop.
Save kumavis/5703360 to your computer and use it in GitHub Desktop.
Notes for making "black_magic" for node-browserify

any node package in the browser

browserify makes this possible for many modules, but the browser is a different environment (ex: no file system access) so we're going to need a few things if we want to run just anything:

1- browser versions of the native modules

2- a way to get browserify use them

  • current version of browserify ("2.17.3") uses browser-resolve "0.1.1" which supplies the builtins that were later removed

  • you can manually add a browser fs implementation to that version of browser-resolve's /builtin/fs.js (to modify the core modules used by global browserify look here: /usr/local/share/npm/lib/node_modules/browserify/node_modules/browser-resolve/builtin )

  • or you could get this branch of browserify that lets you specify global module overrides when bundling

3- a native-grade implementation of process

@kumavis
Copy link
Author

kumavis commented Jun 4, 2013

1 - some native modules also need extending
path.js is missing ["sep","exists","existsSync","_makeLong"]
presumably b/c they require the file-system

EDIT
["exists", "existsSync"] are deprecated
"sep" is just "/" (on this machine)
and "_makeLong" is function (path) {\n return path;\n } (on this machine)

so no biggy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment