babel-plugin-nodejs-module-shim
A babel plugin to shim Node.js build-in modules and global objects.
Example
{ const process = a:1 return processa;} if processenvNODE_ENV === 'TEST' ↓ ↓ ↓ ↓ ↓ ↓ var process = ; { const process = a: 1 ; return processa;} if processenvNODE_ENV === 'TEST' {}
Notice
Polyfills for Node.js core libraries from node-libs-browser are used if available.
By default, this plugin will polyfill each library if there is a known polyfill.
The following modules child_process
、cluster
、dgram
、dns
、fs
、module
、net
、readline
、repl
、tls
are not supported polyfill.
But you could use empty
option as below mentioned to provide an empty object.
Install
npm install --save babel-plugin-nodejs-module-shim
Usage
Via .babelrc
or babel-loader.
"plugins": "nodejs-module-shim"
Options
Option | Defaults | Description |
---|---|---|
prefix | '' | prefix + shimModulePath. See example below. |
empty | [] | provide an empty object for the module that is not supported by polyfill. See example below. |
More examples
["nodejs-module-shim", { prefix: 'PREFIX' }]
process; ↓ ↓ ↓ ↓ ↓ ↓ var process = ; process;
["nodejs-module-shim", { emprty: ['fs'] }]
var fs = ; ↓ ↓ ↓ ↓ ↓ ↓ var fs = {};