🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

babel-plugin-transform-import-commonjs

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-import-commonjs

Transform ES2015 import to CommonJS require

1.0.0
latest
Source
npm
Version published
Weekly downloads
14
-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-transform-import-commonjs

Fork of https://github.com/kiurchv/babel-plugin-transform-system-import-commonjs that compiles import instead of System.import, now that the import() proposal has been accepted.

Babel plugin that transforms ES2015 import into CommonJS require.

https://github.com/tc39/proposal-dynamic-import

How this works

This plugin transforms

var myModule = "./path/to/myModule";

import(myModule).then(function (module) {
  console.log(module);
});

to

var myModule = "./path/to/myModule";

new Promise(function(resolve) {
  resolve(require(myModule));
}.bind(this)).then(function (module) {
  console.log(module);
});

Requirements

You need support for Promise, use polyfill if needed.

Installation

$ npm install babel-plugin-transform-import-commonjs

Usage

.babelrc

{
  "plugins": ["transform-import-commonjs"]
}

Via CLI

$ babel --plugins transform-import-commonjs script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["transform-import-commonjs"]
});

Keywords

babel-plugin

FAQs

Package last updated on 15 Dec 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