Skip to content

Repository files navigation

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 - pass false to disable process polyfilling
  • global - pass false to disable global polyfilling
  • buffer - pass false to disable Buffer polyfilling
  • dirname - pass false to disable __dirname polyfilling
  • filename - pass false to disable __filename polyfilling
  • baseDir which is used for resolving __dirname and __filename.

examples

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.

Maintained by Playcode

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages