babel-plugin-transform-inline-imports-commonjs
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "babel-plugin-transform-inline-imports-commonjs", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A Babel transform that turns imports into lazily loaded commonjs requires", | ||
@@ -20,3 +20,4 @@ "keywords": [ | ||
"dependencies": { | ||
"babel-plugin-transform-strict-mode": "^6.8.0" | ||
"babel-plugin-transform-strict-mode": "^6.8.0", | ||
"builtin-modules": "^1.1.1" | ||
}, | ||
@@ -23,0 +24,0 @@ "devDependencies": { |
@@ -74,1 +74,11 @@ # babel-plugin-transform-inline-imports-commonjs | ||
``` | ||
#### Additional settings | ||
* `excludeNodeBuiltins` (default: `false`) | ||
- Do not apply "inline-imports" to[Node builtin modules](https://github.com/sindresorhus/builtin-modules/blob/v1.1.1/builtin-modules.json). These modules are usually already in the module cache, so there may be no need to lazily load them. | ||
```js | ||
import * as path from 'path'; // transforms to plain `require` with interop | ||
import foo from 'bar'; // transforms to inline import | ||
``` |
'use strict'; | ||
const pathModule = require('path'); | ||
const builtinModules = new Set(require('builtin-modules/static')); | ||
@@ -190,9 +191,2 @@ const THIS_BREAK_KEYS = [ | ||
const filename = pathModule.basename(source, pathModule.extname(source)); | ||
const memoizedID = | ||
path.scope.generateUidIdentifier(filename); | ||
const memoizedFunction = | ||
path.scope.generateUidIdentifier('load' + memoizedID.name); | ||
// require(moduleID); | ||
@@ -206,2 +200,26 @@ const requireCallExpression = buildRequire(t.stringLiteral(source)).expression; | ||
if (this.opts.excludeNodeBuiltins && builtinModules.has(source)) { | ||
// var memoizedID; | ||
const declID = path.scope.generateUidIdentifier(source); | ||
const varDecl = t.variableDeclaration('var', [ | ||
t.variableDeclarator(declID, wrappedRequireCall) | ||
]); | ||
// Copy location from the original import statement for sourcemap | ||
// generation. | ||
if (imports[source]) { | ||
varDecl.loc = imports[source].loc; | ||
} | ||
if (typeof blockHoist === 'number' && blockHoist > 0) { | ||
varDecl._blockHoist = blockHoist; | ||
} | ||
topNodes.push(varDecl); | ||
return requires[cacheKey] = declID; | ||
} | ||
const filename = pathModule.basename(source, pathModule.extname(source)); | ||
const memoizedID = | ||
path.scope.generateUidIdentifier(filename); | ||
const memoizedFunction = | ||
path.scope.generateUidIdentifier('load' + memoizedID.name); | ||
// var memoizedID; | ||
@@ -208,0 +226,0 @@ const memoizerVarDecl = |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22669
4
446
84
2
+ Addedbuiltin-modules@^1.1.1
+ Addedbuiltin-modules@1.1.1(transitive)