Skip to content

STRML/babel-preset-es2015-maybe-webpack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 envs.

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published