Skip to content

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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"]
});

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published