/babel-plugin-remove-import-js-extension

Remove .js and .jsx extensions from `import` statements

Primary LanguageJavaScriptMIT LicenseMIT

babel-plugin-remove-import-js-extension

This Babel plugin allows you to remove .js and .jsx extensions from JavaScript import statements.

Why this plugin ?

If you too are using the Google Closure Compiler to transpile ES5 to ES6, you should have noticed that it requires you to leave off the .js entension for modules. (Sources: Here). For instance,

$ java -jar closure-compiler-v20160822.jar --language_in=ECMASCRIPT6 --js main.js --language_out=ES5
import Mylib from './myLib.js' // Will throw "ERROR - namespace never provided"
import Mylib from './myLib' // Won't throw 🕶

Installation

$ npm install babel-plugin-remove-import-js-extension

Example

Input

import Mylib from './myLib.js'
import MyFancyComponent from './MyFancyComponent.jsx'

Out

import Mylib from './myLib'
import MyFancyComponent from './MyFancyComponent'

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["babel-plugin-remove-import-js-extension"]
}

Via CLI

$ babel --plugins babel-plugin-remove-import-js-extension script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["babel-plugin-remove-import-js-extension"]
});