From 8b07f7566363b24de367aecfeb6e74a39eb54e12 Mon Sep 17 00:00:00 2001 From: Nathan Isaac Date: Thu, 29 Nov 2018 13:54:45 -0800 Subject: [PATCH] Add dynamic import note regarding babel preset env (#1877) --- docs/plugin-syntax-dynamic-import.md | 27 ++++++++++++++++++- .../plugin-syntax-dynamic-import.md | 27 ++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/docs/plugin-syntax-dynamic-import.md b/docs/plugin-syntax-dynamic-import.md index 0e9fa667be..539218a559 100644 --- a/docs/plugin-syntax-dynamic-import.md +++ b/docs/plugin-syntax-dynamic-import.md @@ -32,7 +32,32 @@ babel --plugins @babel/plugin-syntax-dynamic-import script.js ```javascript require("@babel/core").transform("code", { - plugins: ["@babel/plugin-syntax-dynamic-import"] + plugins: ["@babel/plugin-syntax-dynamic-import"], }); ``` +## Working with Webpack and @babel/preset-env + +Currently, `@babel/preset-env` is unaware that using `import()` with [Webpack relies on `Promise` internally](https://webpack.js.org/guides/code-splitting/#dynamic-imports). Environments which do not have builtin support for `Promise`, like Internet Explorer, will require both the `promise` and `iterator` polyfills be added manually. + +```js +// webpack config +const config = { + entry: [ + "core-js/modules/es6.promise", + "core-js/modules/es6.array.iterator", + path.resolve(__dirname, "src/main.js"), + ], + // ... +}; +``` + +or + +```js +// src/main.js +import "core-js/modules/es6.promise"; +import "core-js/modules/es6.array.iterator"; + +// ... +``` diff --git a/website/versioned_docs/version-7.0.0/plugin-syntax-dynamic-import.md b/website/versioned_docs/version-7.0.0/plugin-syntax-dynamic-import.md index 92ea93b969..f6e5ee5152 100644 --- a/website/versioned_docs/version-7.0.0/plugin-syntax-dynamic-import.md +++ b/website/versioned_docs/version-7.0.0/plugin-syntax-dynamic-import.md @@ -33,7 +33,32 @@ babel --plugins @babel/plugin-syntax-dynamic-import script.js ```javascript require("@babel/core").transform("code", { - plugins: ["@babel/plugin-syntax-dynamic-import"] + plugins: ["@babel/plugin-syntax-dynamic-import"], }); ``` +## Working with Webpack and @babel/preset-env + +Currently, `@babel/preset-env` is unaware that using `import()` with [Webpack relies on `Promise` internally](https://webpack.js.org/guides/code-splitting/#dynamic-imports). Environments which do not have builtin support for `Promise`, like Internet Explorer, will require both the `promise` and `iterator` polyfills be added manually. + +```js +// webpack config +const config = { + entry: [ + "core-js/modules/es6.promise", + "core-js/modules/es6.array.iterator", + path.resolve(__dirname, "src/main.js"), + ], + // ... +}; +``` + +or + +```js +// src/main.js +import "core-js/modules/es6.promise"; +import "core-js/modules/es6.array.iterator"; + +// ... +```