Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional information for plugin-syntax-dynamic-import #2197

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
suggestions from PR comments
Gunnar Gabrielson committed Mar 12, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit c443214cc2a128e95f65cfcc8c54f31587b1a10b
8 changes: 4 additions & 4 deletions docs/plugin-syntax-dynamic-import.md
Original file line number Diff line number Diff line change
@@ -4,14 +4,14 @@ title: @babel/plugin-syntax-dynamic-import
sidebar_label: syntax-dynamic-import
---

`@babel/plugin-syntax-dynamic-import` is needed to enable parsing for import().
`@babel/plugin-syntax-dynamic-import` is needed to enable parsing for `import()`.

In Babel 7.8.0 it's enabled by default, so this plugin shouldn't be needed if you are using `@babel/core@>7.8.0`.
This plugin is enabled by default since Babel 7.8.0, so you shouldn't need to enable this plugin separately.

If you want to transpile import():
**Usage notes:**

1. If you are using `@babel/preset-env`, it's automatically handled
2. If you are using Webpack or Rollup, you shouldn't transpile import() with Babel and let the bundler handle it for you
2. If you are using Webpack or Rollup, you shouldn't transpile `import()` with Babel and let the bundler handle it for you
3. Otherwise, you need `@babel/plugin-proposal-dynamic-import`


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gunn4r Can you rebase on upstream? We have removed versioned_docs so I think only this section is required.

Original file line number Diff line number Diff line change
@@ -5,15 +5,13 @@ sidebar_label: syntax-dynamic-import
original_id: babel-plugin-syntax-dynamic-import
---

`@babel/plugin-syntax-dynamic-import` is needed to enable parsing for import().
`babel-plugin-syntax-dynamic-import` is needed to enable parsing for `import()`.

In Babel 7.8.0 it's enabled by default, so this plugin shouldn't be needed if you are using `@babel/core@>7.8.0`.
**Usage notes:**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are using babel-preset-env, it's automatically handled

I don't think this applies for v6?

Otherwise, you need babel-plugin-proposal-dynamic-import

babel-plugin-proposal-dynamic-import doesn't exist :)

Should we link to https://github.com/airbnb/babel-plugin-dynamic-import-node?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 oops!

Yeah maybe something like:

Otherwise, consider using babel-plugin-dynamic-import-node.

@nicolo-ribaudo Just just verify, can you confirm that babel-preset-env (v6) does not automatically handle this? If not, I'll strike that line.

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo Mar 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, it's only supported in Babel 7 (7.5.0)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I'll strike that line.


If you want to transpile import():

1. If you are using `@babel/preset-env`, it's automatically handled
2. If you are using Webpack or Rollup, you shouldn't transpile import() with Babel and let the bundler handle it for you
3. Otherwise, you need `@babel/plugin-proposal-dynamic-import`
1. If you are using `babel-preset-env`, it's automatically handled
2. If you are using Webpack or Rollup, you shouldn't transpile `import()` with Babel and let the bundler handle it for you
3. Otherwise, you need `babel-plugin-proposal-dynamic-import`

## Installation

Original file line number Diff line number Diff line change
@@ -5,14 +5,12 @@ sidebar_label: syntax-dynamic-import
original_id: babel-plugin-syntax-dynamic-import
---

`@babel/plugin-syntax-dynamic-import` is needed to enable parsing for import().
`@babel/plugin-syntax-dynamic-import` is needed to enable parsing for `import()`.

In Babel 7.8.0 it's enabled by default, so this plugin shouldn't be needed if you are using `@babel/core@>7.8.0`.

If you want to transpile import():
**Usage notes:**

1. If you are using `@babel/preset-env`, it's automatically handled
2. If you are using Webpack or Rollup, you shouldn't transpile import() with Babel and let the bundler handle it for you
2. If you are using Webpack or Rollup, you shouldn't transpile `import()` with Babel and let the bundler handle it for you
3. Otherwise, you need `@babel/plugin-proposal-dynamic-import`

## Installation
Original file line number Diff line number Diff line change
@@ -5,14 +5,12 @@ sidebar_label: syntax-dynamic-import
original_id: babel-plugin-syntax-dynamic-import
---

`@babel/plugin-syntax-dynamic-import` is needed to enable parsing for import().
`@babel/plugin-syntax-dynamic-import` is needed to enable parsing for `import()`.

In Babel 7.8.0 it's enabled by default, so this plugin shouldn't be needed if you are using `@babel/core@>7.8.0`.

If you want to transpile import():
**Usage notes:**

1. If you are using `@babel/preset-env`, it's automatically handled
2. If you are using Webpack or Rollup, you shouldn't transpile import() with Babel and let the bundler handle it for you
2. If you are using Webpack or Rollup, you shouldn't transpile `import()` with Babel and let the bundler handle it for you
3. Otherwise, you need `@babel/plugin-proposal-dynamic-import`

## Installation
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
id: version-7.8.0-babel-plugin-syntax-dynamic-import
title: @babel/plugin-syntax-dynamic-import
sidebar_label: syntax-dynamic-import
original_id: babel-plugin-syntax-dynamic-import
---

`@babel/plugin-syntax-dynamic-import` is needed to enable parsing for `import()`.

This plugin is enabled by default since Babel 7.8.0, so you shouldn't need to enable this plugin separately.

**Usage notes:**

1. If you are using `@babel/preset-env`, it's automatically handled
2. If you are using Webpack or Rollup, you shouldn't transpile `import()` with Babel and let the bundler handle it for you
3. Otherwise, you need `@babel/plugin-proposal-dynamic-import`


## Installation

```sh
npm install --save-dev @babel/plugin-syntax-dynamic-import
```

## Usage

### With a configuration file (Recommended)

```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";

// ...
```