Home

Awesome

Transform dynamic import default

<p align="right"> <a href="https://www.npmjs.com/package/babel-plugin-transform-dynamic-import-default"> <img alt="Npm version" src="https://badge.fury.io/js/babel-plugin-transform-dynamic-import-default.svg"> </a> <a href="https://travis-ci.org/59naga/babel-plugin-transform-dynamic-import-default"> <img alt="Build Status" src="https://travis-ci.org/59naga/babel-plugin-transform-dynamic-import-default.svg?branch=master"> </a> </p>

Add .default to dynamicImport using AwaitExpression.

Installation

yarn add babel-plugin-transform-dynamic-import-default

Usage

Real dynamic-import syntax will force the .default, but this plugin will omit it.

// index.js
(async () => {
  var assert = await import("assert");
})();
babel index.js --plugins=transform-dynamic-import-default

becomes:

(async () => {
  var assert = (await import("assert")).default;
})();

If you want to do multiple imports using destructuring objects, this plugin doesn't transform anything.

(async () => {
  var { strictEqual, deepEqual } = await import("assert");
})();

becomes(nothing happens):

(async () => {
  var { strictEqual, deepEqual } = await import("assert");
})();

See also

License

MIT