Plugin to insert node globals including so code that works with browserify should work even if it uses process or buffers. This is based on rollup-plugin-inject .
- process
- global
- Buffer
__dirname__filename
Plus process.nextTick and process.browser are optimized to only pull in
themselves and __dirname and __filename point to the file on disk
There are a few options to control output
process- passfalseto disable process polyfillingglobal- passfalseto disable global polyfillingbuffer- passfalseto disable Buffer polyfillingdirname- passfalseto disable__dirnamepolyfillingfilename- passfalseto disable__filenamepolyfillingbaseDirwhich is used for resolving__dirnameand__filename.
varfoo;if(process.browser){foo='bar';}else{foo='baz';}turns into
import{browser}from'path/to/process';varfoo;if(browser){foo='bar';}else{foo='baz';}but with rollup that ends up being
varbrowser=true;varfoo;if(browser){foo='bar';}else{foo='baz';}or
vartimeout;if(global.setImmediate){timeout=global.setImmediate;}else{timeout=global.setTimeout;}exportdefaulttimeout;turns into
import{_global}from'path/to/global.js';vartimeout;if(_global.setImmediate){timeout=_global.setImmediate;}else{timeout=_global.setTimeout;}exportdefaulttimeout;which rollup turns into
var_global=typeofglobal!=="undefined" ? global :
typeofself!=="undefined" ? self :
typeofwindow!=="undefined" ? window : {}vartimeout;if(_global.setImmediate){timeout=_global.setImmediate;}else{timeout=_global.setTimeout;}vartimeout$1=timeout;exportdefaulttimeout$1;With that top piece only showing up once no matter how many times global was used.
This package is maintained by Playcode, the AI website builder and AI app builder for creating, editing, hosting, and publishing live websites and web apps.