A babel plugin to shim Node.js build-in modules and global objects.
function processs(__filename){
const process = {
a:1
}
return process.a;
}
if (process.env.NODE_ENV === 'TEST') {
}
↓ ↓ ↓ ↓ ↓ ↓
var process = require("<CWD>/process/browser.js");
function processs(__filename) {
const process = {
a: 1
};
return process.a;
}
if (process.env.NODE_ENV === 'TEST') {}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.
npm install --save babel-plugin-nodejs-module-shimVia .babelrc or babel-loader.
{
"plugins": [["nodejs-module-shim"]]
}| 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. |
["nodejs-module-shim", { prefix: 'PREFIX' }]
process;
↓ ↓ ↓ ↓ ↓ ↓
var process = require("PREFIX<CWD>/process/browser.js");
process;["nodejs-module-shim", { emprty: ['fs'] }]
var fs = require('fs');
↓ ↓ ↓ ↓ ↓ ↓
var fs = {};