babel-preset-es2015-maybe-webpack
v1.3.1
Published
An es2015 preset that can dynamically exclude the ES6 module plugin based on env.
Downloads
45
Maintainers
Readme
babel-preset-es2015-maybe-webpack
Using Webpack2 with Babel is difficult. Webpack >= 2 understands ES6 import/export
natively, so you don't want
to use the full babel-preset-es2015. You want to have all of your babel options in your .babelrc
, but there
is no good way to override a single preset in babel-loader
while keeping the rest of your .babelrc
intact,
including env
s.
This preset is for you if you've already tried to parse your .babelrc
yourself (hint, use json5
).
How it Works
Add the following to the top of your webpack config:
process.env.WEBPACK_VERSION = require('webpack/package.json').version;
If this preset detects that Webpack >= 2 is being used, it will exclude transform-es2015-modules-commonjs
.
Install
Install both this preset, and the core 'babel-preset-es2015' that it modifies:
$ npm install --save-dev babel-preset-es2015-maybe-webpack babel-preset-es2015
Usage
Hint: You can get [loose] mode by using es2015-maybe-webpack/loose
.
Via .babelrc
(Recommended)
.babelrc
{
"presets": ["es2015-maybe-webpack"]
}
Via CLI
$ babel script.js --presets es2015-maybe-webpack
Via Node API
require("babel-core").transform("code", {
presets: ["es2015-maybe-webpack"]
})