rollup-plugin-node-globals
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
- passfalse
to disable process polyfillingglobal
- passfalse
to disable global polyfillingbuffer
- passfalse
to disable Buffer polyfillingdirname
- passfalse
to disable__dirname
polyfillingfilename
- passfalse
to disable__filename
polyfillingbaseDir
which is used for resolving__dirname
and__filename
.
examples
var foo;if processbrowser foo = 'bar'; else foo = 'baz';
turns into
;var foo;if browser foo = 'bar'; else foo = 'baz';
but with rollup that ends up being
var browser = true;var foo;if browser foo = 'bar'; else foo = 'baz';
or
var timeout;if globalsetImmediate timeout = globalsetImmediate; else timeout = globalsetTimeout;;
turns into
;var timeout;if _globalsetImmediate timeout = _globalsetImmediate; else timeout = _globalsetTimeout;;
which rollup turns into
var _global = typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {} var timeout;if _globalsetImmediate timeout = _globalsetImmediate; else timeout = _globalsetTimeout;var timeout$1 = timeout; ;
With that top piece only showing up once no matter how many times global was used.