This Babel plugin allows you to remove .js and .jsx extensions from JavaScript import statements.
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=ES5import Mylib from './myLib.js' // Will throw "ERROR - namespace never provided"
import Mylib from './myLib' // Won't throw 🕶$ npm install babel-plugin-remove-import-js-extensionInput
import Mylib from './myLib.js'
import MyFancyComponent from './MyFancyComponent.jsx'Out
import Mylib from './myLib'
import MyFancyComponent from './MyFancyComponent'.babelrc
{
"plugins": ["babel-plugin-remove-import-js-extension"]
}$ babel --plugins babel-plugin-remove-import-js-extension script.jsrequire("babel-core").transform("code", {
plugins: ["babel-plugin-remove-import-js-extension"]
});