Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

babel-plugin-webpack-dynamic-import

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-webpack-dynamic-import

code-splitting your module

latest
npmnpm
Version
1.0.1
Version published
Weekly downloads
2
-50%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-webpack-dynamic-import

Babel plugin to transpile import() to a deferred require.ensure(). and add below code, you can control your module hot reload more flexible

require.ensure([], (require) => {
     const result = require(SOURCE);
     resolve(result);
     if(module.hot) {
        Promise.resolve().then(() => {
            typeof result.onUpdate === 'function' && module.hot.accept(SOURCE, () => {
                result.onUpdate(require(SOURCE));
            });
        })
     }
}, MODEL);

you can declare onUpdate method on your module when changing

NOTE: Babylon >= v6.12.0 is required to correctly parse dynamic imports.

Installation

npm install babel-plugin-webpack-dynamic-import --save-dev

Usage

.babelrc

{
  "plugins": ["webpack-dynamic-import"]
}

Options

{
  "plugins": "webpack-dynamic-import"
}

Via CLI

$ babel --plugins dynamic-import-node script.js

Via Node API

require('babel-core').transform('code', {
  plugins: ['webpack-dynamic-import']
});

Keywords

import

FAQs

Package last updated on 25 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts