babel-plugin-transform-dynamic-import-to-static

1.0.1 • Public • Published

JavaScript Style Guide code style: prettier Conventional Commits

babel-plugin-transform-dynamic-import-to-static

a babel plugin to convert dynamic import to static import

Purpose

This plugin hoists dynamic imports to static imports, and replaces dynamic import statements with immediately resolved promises, also won't touch static import.

import A from './A'
 
import('./B')

to

import A from './A'
 
import _default from './B'
 
Promise.resolve(_default)

See it in action in astexplorer

Usage

add as plugin to your babel configuration

{
  //...
  "plugins": [
    // ...
    "babel-plugin-transform-dynamic-import-to-static"
  ]
}

Use case

This plugin was made to use with react-hot-loader and react-loadable to ensure hot-reloading works out of the box with a code-split architecture. It is meant to be used only during development.

Readme

Keywords

none

Package Sidebar

Install

npm i babel-plugin-transform-dynamic-import-to-static

Weekly Downloads

30

Version

1.0.1

License

MIT

Unpacked Size

105 kB

Total Files

8

Last publish

Collaborators

  • shriyans