babel-plugin-webpack-dynamic-import
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    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

    Via .babelrc (Recommended)

    .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']
    });

    Install

    npm i babel-plugin-webpack-dynamic-import

    DownloadsWeekly Downloads

    3

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    10.2 kB

    Total Files

    8

    Last publish

    Collaborators

    • sampsonli