Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport changes to previous versions
- Loading branch information
1 parent
4605a08
commit 5a3e804
Showing
13 changed files
with
902 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
website/versioned_docs/version-7.4.0/plugin-syntax-dynamic-import.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
--- | ||
id: version-7.4.0-babel-plugin-syntax-dynamic-import | ||
title: @babel/plugin-syntax-dynamic-import | ||
sidebar_label: syntax-dynamic-import | ||
original_id: babel-plugin-syntax-dynamic-import | ||
--- | ||
|
||
## Installation | ||
|
||
```sh | ||
npm install --save-dev @babel/plugin-syntax-dynamic-import | ||
``` | ||
|
||
## Usage | ||
|
||
### Via `.babelrc` (Recommended) | ||
|
||
**.babelrc** | ||
|
||
```json | ||
{ | ||
"plugins": ["@babel/plugin-syntax-dynamic-import"] | ||
} | ||
``` | ||
|
||
### Via CLI | ||
|
||
```sh | ||
babel --plugins @babel/plugin-syntax-dynamic-import script.js | ||
``` | ||
|
||
### Via Node API | ||
|
||
```javascript | ||
require("@babel/core").transform("code", { | ||
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. | ||
|
||
For example, with `core-js@3`: | ||
|
||
```js | ||
// webpack config | ||
const config = { | ||
entry: [ | ||
"core-js/modules/es.promise", | ||
"core-js/modules/es.array.iterator", | ||
path.resolve(__dirname, "src/main.js"), | ||
], | ||
// ... | ||
}; | ||
``` | ||
|
||
or | ||
|
||
```js | ||
// src/main.js | ||
import "core-js/modules/es.promise"; | ||
import "core-js/modules/es.array.iterator"; | ||
|
||
// ... | ||
``` | ||
|
||
This is the same for `core-js@2`, except the imports paths are slightly different: | ||
|
||
```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"; | ||
|
||
// ... | ||
``` |
Oops, something went wrong.