babel-plugin-system-import-transformer
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -94,2 +94,10 @@ 'use strict'; | ||
value: function getCommonJSRequirePromise(module) { | ||
if (this.pluginOptions.commonJS && this.pluginOptions.commonJS.useRequireEnsure) { | ||
return this.getCommonJSRequireEnsurePromise(module); | ||
} | ||
return this.getCommonJSPlainRequirePromise(module); | ||
} | ||
}, { | ||
key: 'getCommonJSPlainRequirePromise', | ||
value: function getCommonJSPlainRequirePromise(module) { | ||
var commonJSRequireExpression = this.getCommonJSRequire(module); | ||
@@ -100,2 +108,11 @@ var commonJSRequire = (0, _promiseUtils.createPromiseResolveExpression)(commonJSRequireExpression); | ||
}, { | ||
key: 'getCommonJSRequireEnsurePromise', | ||
value: function getCommonJSRequireEnsurePromise(module) { | ||
// require.ensure([], function(require) { resolve(require(module)); }); | ||
var requireEnsure = _babelArgumentProvider.types.expressionStatement(_babelArgumentProvider.types.callExpression(_babelArgumentProvider.types.memberExpression(_babelArgumentProvider.types.identifier('require'), _babelArgumentProvider.types.identifier('ensure')), [_babelArgumentProvider.types.arrayExpression([]), _babelArgumentProvider.types.functionExpression(null, [_babelArgumentProvider.types.identifier('require')], _babelArgumentProvider.types.blockStatement([_babelArgumentProvider.types.expressionStatement(_babelArgumentProvider.types.callExpression(_babelArgumentProvider.types.identifier('resolve'), [_babelArgumentProvider.types.callExpression(_babelArgumentProvider.types.identifier('require'), [module])]))]))])); | ||
var newPromiseExpression = _babelArgumentProvider.types.newExpression(_babelArgumentProvider.types.identifier('Promise'), [_babelArgumentProvider.types.functionExpression(null, [_babelArgumentProvider.types.identifier('resolve')], _babelArgumentProvider.types.blockStatement([requireEnsure]))]); | ||
return newPromiseExpression; | ||
} | ||
}, { | ||
key: 'getGlobalRequire', | ||
@@ -102,0 +119,0 @@ value: function getGlobalRequire(module) { |
{ | ||
"name": "babel-plugin-system-import-transformer", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Babel plugin that replaces System.import with the equivalent UMD pattern", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -93,2 +93,27 @@ # babel-plugin-system-import-transformer | ||
### commonJS | ||
CommonJS specific options. | ||
#### commonJS.useRequireEnsure | ||
Type: Boolean | ||
Values: [**`false`**/`true`] | ||
When set to `true`, all CommonJS import statements will use Webpack's `require.ensure()` syntax. This enables dynamic module loading in CommonJS (Webpack) and works both for the `UMD` and (of course) `CommonJS` module target types. | ||
```js | ||
{ | ||
"plugins": [ | ||
["system-import-transformer", { "commonJS": { "useRequireEnsure": true } }] | ||
] | ||
} | ||
// the CommonJS code part will look like: | ||
new Promise(function (resolve) { | ||
require.ensure([], function (require) { | ||
resolve(require('./utils/serializer')); | ||
}); | ||
}).then(function(module){ console.log(module); }); | ||
``` | ||
### modules | ||
@@ -132,2 +157,4 @@ Type: String | ||
Syntax specific options. | ||
#### syntax.import | ||
@@ -134,0 +161,0 @@ Type: Boolean |
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
28044
316
171