A Babel transform that turns imports into lazily loaded commonjs requires
Last updated 4 years ago by develar .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @develar/babel-plugin-transform-inline-imports-commonjs 
SYNC missed versions from official npm registry.


This plugin should be used instead of babel-plugin-transform-es2015-modules-commonjs

Build Status


$ npm install babel-plugin-transform-inline-imports-commonjs


This plugin transforms ES modules (import and export), into CommonJS require and module.exports. imports are transformed into lazily loaded memoized requires. So the require call is deferred until the imported identifier is referenced. This allows you to write idiomatic code without the performance costs of loading code up-front (I/O, parsing, and executing).

Transform example


import bigModule from 'big-module';

export default function(val) {
  return bigModule.doExpensiveThing(val);


'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true

exports.default = function (val) {
  return (_bigModule || _bigModule2()).default.doExpensiveThing(val);

var _bigModule;

function _bigModule2() {
  return _bigModule = _interopRequireDefault(require('big-module'));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }



The same settings that are available for babel-plugin-transform-es2015-modules-commonjs are available for babel-plugin-transform-inline-imports-commonjs:

// without options
  "plugins": ["transform-inline-imports-commonjs"]

// with options
  "plugins": [
    ["transform-inline-imports-commonjs", {
      "allowTopLevelThis": true,
      "strict": false,
      "loose": true

Additional settings

  • excludeNodeBuiltins (default: false)

    • Do not apply "inline-imports" toNode builtin modules. These modules are usually already in the module cache, so there may be no need to lazily load them.
    import * as path from 'path'; // transforms to plain `require` with interop
    import foo from 'bar'; // transforms to inline import

Current Tags

  • 1.1.1                                ...           latest (4 years ago)

1 Versions

  • 1.1.1                                ...           4 years ago

Copyright 2014 - 2016 © taobao.org |