Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-inline-imports-commonjs

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-inline-imports-commonjs

A Babel transform that turns imports into lazily loaded commonjs requires

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

babel-plugin-transform-inline-imports-commonjs

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

Build Status

Installation

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

Details

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

Before:

import bigModule from 'big-module';

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

After:

'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 }; }

Usage

Configuration

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
  • excludeModules:

    • An array of strings that correspond to module IDs that should not be "inline-import"'ed. For the config "excludeModules": ["atom"]:
    import {TextEditor} from 'atom'; // transforms to plain `require` with interop
    import foo from 'bar'; // transforms to inline import
    
  • excludeNodeBuiltins (default: false)

    • Do not apply "inline-imports" to Node 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
    

Keywords

FAQs

Package last updated on 20 Oct 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc