Namby Pamby Magicians

    babel-plugin-replace-dynamic-import

    1.1.0 • Public • Published

    Replace dynamic import() with a custom function call.

    babel-plugin-replace-dynamic-import

    Babel plugin to replace import(...) with a custom function call. By default it is __import__().

    Use case

    This has a very narrow use case: when you want to parse the same file for both browser and node (using babel/webpack) and still be able to use webpack's code splitting ability.

    This is basically a utility to help reduce code duplication.

    So statements like:

    ...
    const someDynamicImport = import('../path/to/your/module');
    ...

    into a function call

    const someDynamicImport = __import__('../path/to/your/module');

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

    Installation

    yarn add babel-plugin-replace-dynamic-import --dev

    Usage

    Via .babelrc (Recommended)

    .babelrc

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

    Via CLI

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

    Via Node API

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

    Options

    • by: the identifier to replace import with. Defaults to __import__

    Install

    npm i babel-plugin-replace-dynamic-import

    DownloadsWeekly Downloads

    8

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    17 kB

    Total Files

    10

    Last publish

    Collaborators

    • kevinresol