Skip to content

Commit

Permalink
Remove backwards-incompatible babel-preset-env.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Feb 15, 2017
1 parent b358ca0 commit e231444
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 50 deletions.
89 changes: 42 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,74 @@
babel-brunch
===========
## babel-brunch

Brunch plugin using [babel](https://github.com/babel/babel) to turn latest
ECMAScript standard code into vanilla ES5 with no runtime required.

All the `.js` files in your project will be run through the babel compiler,
except those it is configured to ignore, unless you use the `pattern` option.

Additionally, starting Brunch 2.7.3, babel-brunch will also compile NPM dependencies.
Additionally, starting Brunch 2.7, babel-brunch will also compile NPM dependencies.

## Installation

Installation
------------
`npm install --save-dev babel-brunch`

Usage
-----
## Configuration

- **No configuration is required by default.** `es2015` and `es2016` presets are included.
- To add **React** preset:
- Execute `npm install --save-dev babel-preset-react`, then adjust the `presets` option in `brunch-config.js`:
- `plugins: {babel: {presets: ['es2015', 'es2016', 'react']}}`
- Default behavior is to handle `js` files which are not dependencies and `jsx` files if you enable React preset.
- To specify preset options: `{presets: [['transform-es2015-template-literals', { spec: true }]]}`
[babel-preset-latest](https://babeljs.io/docs/plugins/preset-latest/) (es2015, es2016, es2017) **is used by default**, you don't need to adjust config to have it.

Configuration
-------------
### Using React; or any other plugin

Set [babel options](https://babeljs.io/docs/usage/options) in your brunch
config (such as `brunch-config.js`) except for `filename` and `sourceMap`
which are handled internally.
Install a plugin:

This plugin uses, by default,
[babel-preset-env](https://github.com/babel/babel-preset-env/).
To configure, use `env` option:
```
npm insall --save-dev babel-preset-react
```

Then, make sure Brunch sees it:

```js
plugins: {
```javascript
exports.plugins = {
babel: {
env: {
targets: {
safari: 7, // explicitly
browsers: '>2%' // with browserslist query
}
}
presets: ['latest', 'react']
}
}
```
Without providing any options, behavior will be like using [babel-preset-latest](https://babeljs.io/docs/plugins/preset-latest/) (es2015, es2016, es2017).

To use no preset, set the configuration option to an empty array.
Optionally, you can configure the preset:

`presets: [ 'latest', ['transform-es2015-template-literals', {spec: true}] ]`

Additionally, you can set an `ignore` value to specify which `.js` files in
your project should not be compiled by babel. By default, `ignore` is set to
`/^(bower_components|vendor)/`.

You can also set `pattern` to a regular expression that will match the file
paths you want compiled by babel, which will override the standard behavior of
compiling every `.js` file.
### Ignoring node modules

```js
plugins: {
```
exports.plugins = {
babel: {
presets: ['es2015', 'es2016', 'react'], // es2015, es2016 are defaults
ignore: [
/^(bower_components|vendor)/,
/^node_modules/,
'app/legacyES5Code/**/*'
],
pattern: /\.(es6|jsx)$/ // js and jsx are defaults.
]
}
}
```

### Changing which files would be compiled by babel

```
exports.plugins = {
babel: {
pattern: /\.es7$/ // By default, JS|JSX|ES6 are used.
}
}
```

Change Log
----------
Set [babel options](https://babeljs.io/docs/usage/options) in your brunch
config (such as `brunch-config.js`) except for `filename` and `sourceMap`
which are handled internally.

## Change Log
[See release notes page on GitHub](https://github.com/babel/babel-brunch/releases)

License
-------
## License

[ISC](https://raw.github.com/babel/babel-brunch/master/LICENSE)
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class BabelCompiler {

opts.sourceMap = !!config.sourceMaps;
if (!opts.presets) {
opts.presets = [['env', opts.env]];
opts.presets = ['latest'];
// ['env', opts.env]
}
if (!opts.plugins) opts.plugins = [];

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@
"dependencies": {
"anymatch": "^1.0.0",
"babel-core": "^6.0.0",
"babel-preset-env": "^1.1.8",
"babel-preset-latest": "^6.22.0",
"loggy": "~1.0.1"
},
"devDependencies": {
"babel-plugin-transform-es2015-template-literals": "^6.8.0",
"babel-plugin-transform-node-env-inline": "^6.1.18",
"babel-preset-es2015": "^6.22.0",
"mocha": "^2.0.0",
"eslint": "^2.0.0"
}
Expand Down

0 comments on commit e231444

Please sign in to comment.