babel-plugin-transform-inline-imports-commonjs
This plugin should be used instead of babel-plugin-transform-es2015-modules-commonjs
Installation
$ npm install babel-plugin-transform-inline-imports-commonjs
Details
This plugin transforms ES modules (import
and export
), into CommonJS require
and module.exports
. import
s are transformed into lazily loaded memoized require
s. So the require
call is deferred until the imported identifier is referenced. This allows you to write idiomatic code without the performance costs of loading code up-front (I/O, parsing, and executing).
Transform example
Before:
; { return bigModule;}
After:
'use strict'; Object; exports { return _bigModule || default;}; var _bigModule; { return _bigModule = ;} { return obj && obj__esModule ? obj : default: obj ; }
Usage
Configuration
The same settings that are available for babel-plugin-transform-es2015-modules-commonjs
are available for babel-plugin-transform-inline-imports-commonjs
:
// without options "plugins": "transform-inline-imports-commonjs" // with options "plugins": "transform-inline-imports-commonjs" "allowTopLevelThis": true "strict": false "loose": true
Additional settings
-
excludeModules
:- An array of strings that correspond to module IDs that should not be "inline-import"'ed. For the config
"excludeModules": ["atom"]
:
; // transforms to plain `require` with interop; // transforms to inline import - An array of strings that correspond to module IDs that should not be "inline-import"'ed. For the config
-
excludeNodeBuiltins
(default:false
)- Do not apply "inline-imports" to Node builtin modules. These modules are usually already in the module cache, so there may be no need to lazily load them.
; // transforms to plain `require` with interop; // transforms to inline import