0.3.0 • Published 7 years ago
babel-plugin-nodejs-module-shim v0.3.0
babel-plugin-nodejs-module-shim
A babel plugin to shim Node.js build-in modules and global objects.
Example
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') {}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-shimUsage
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 = require("PREFIX<CWD>/process/browser.js");
process; ["nodejs-module-shim", { emprty: ['fs'] }]
var fs = require('fs');
↓ ↓ ↓ ↓ ↓ ↓
var fs = {};