Skip to content

Dynamic import transform #9551

@nicolo-ribaudo

Description

@nicolo-ribaudo

We currently only support parsing of import(foo), and ask people to use wither webpack or babel-plugin-dynamic-import-node to transpile it.

I think that we can easily add it to @babel/plugin-transform-modules-* (or create new @babel/plugin-proposal-dynamic-import-* packages):

// input
import(source)

// commonjs
new Promise(resolve => resolve(_interopRequireWildcard(require(source))))

// amd
new Promise(resolve => require([source], imports => resolve(_interopRequireWildcard(imports))))

// systemjs
System.import(source)

My preference would be to add this feature (behind an option) to the existing plugins, since we can't transpile import() without also transpiling es6 import/export.
If you prefer the separte plugins, we could add an "internal option" to @babel/plugin-transform-modules-* which is enabled by @babel/plugin-proposal-dynamic-import. If the modules plugin is not enabled, @babel/plugin-proposal-dynamic-import would throw an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    outdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions