|
1 |
| -babel-brunch |
2 |
| -=========== |
| 1 | +## babel-brunch |
| 2 | + |
3 | 3 | Brunch plugin using [babel](https://github.com/babel/babel) to turn latest
|
4 | 4 | ECMAScript standard code into vanilla ES5 with no runtime required.
|
5 | 5 |
|
6 | 6 | All the `.js` files in your project will be run through the babel compiler,
|
7 | 7 | except those it is configured to ignore, unless you use the `pattern` option.
|
8 | 8 |
|
9 |
| -Additionally, starting Brunch 2.7.3, babel-brunch will also compile NPM dependencies. |
| 9 | +Additionally, starting Brunch 2.7, babel-brunch will also compile NPM dependencies. |
| 10 | + |
| 11 | +## Installation |
10 | 12 |
|
11 |
| -Installation |
12 |
| ------------- |
13 | 13 | `npm install --save-dev babel-brunch`
|
14 | 14 |
|
15 |
| -Usage |
16 |
| ------ |
| 15 | +## Configuration |
17 | 16 |
|
18 |
| -- **No configuration is required by default.** `es2015` and `es2016` presets are included. |
19 |
| -- To add **React** preset: |
20 |
| - - Execute `npm install --save-dev babel-preset-react`, then adjust the `presets` option in `brunch-config.js`: |
21 |
| - - `plugins: {babel: {presets: ['es2015', 'es2016', 'react']}}` |
22 |
| -- Default behavior is to handle `js` files which are not dependencies and `jsx` files if you enable React preset. |
23 |
| -- To specify preset options: `{presets: [['transform-es2015-template-literals', { spec: true }]]}` |
| 17 | +[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. |
24 | 18 |
|
25 |
| -Configuration |
26 |
| -------------- |
| 19 | +### Using React; or any other plugin |
27 | 20 |
|
28 |
| -Set [babel options](https://babeljs.io/docs/usage/options) in your brunch |
29 |
| -config (such as `brunch-config.js`) except for `filename` and `sourceMap` |
30 |
| -which are handled internally. |
| 21 | +Install a plugin: |
31 | 22 |
|
32 |
| -This plugin uses, by default, |
33 |
| -[babel-preset-env](https://github.com/babel/babel-preset-env/). |
34 |
| -To configure, use `env` option: |
| 23 | +``` |
| 24 | +npm insall --save-dev babel-preset-react |
| 25 | +``` |
| 26 | + |
| 27 | +Then, make sure Brunch sees it: |
35 | 28 |
|
36 |
| -```js |
37 |
| -plugins: { |
| 29 | +```javascript |
| 30 | +exports.plugins = { |
38 | 31 | babel: {
|
39 |
| - env: { |
40 |
| - targets: { |
41 |
| - safari: 7, // explicitly |
42 |
| - browsers: '>2%' // with browserslist query |
43 |
| - } |
44 |
| - } |
| 32 | + presets: ['latest', 'react'] |
45 | 33 | }
|
46 | 34 | }
|
47 | 35 | ```
|
48 |
| -Without providing any options, behavior will be like using [babel-preset-latest](https://babeljs.io/docs/plugins/preset-latest/) (es2015, es2016, es2017). |
49 | 36 |
|
50 |
| -To use no preset, set the configuration option to an empty array. |
| 37 | +Optionally, you can configure the preset: |
| 38 | + |
| 39 | +`presets: [ 'latest', ['transform-es2015-template-literals', {spec: true}] ]` |
51 | 40 |
|
52 |
| -Additionally, you can set an `ignore` value to specify which `.js` files in |
53 |
| -your project should not be compiled by babel. By default, `ignore` is set to |
54 |
| -`/^(bower_components|vendor)/`. |
55 | 41 |
|
56 |
| -You can also set `pattern` to a regular expression that will match the file |
57 |
| -paths you want compiled by babel, which will override the standard behavior of |
58 |
| -compiling every `.js` file. |
| 42 | +### Ignoring node modules |
59 | 43 |
|
60 |
| -```js |
61 |
| -plugins: { |
| 44 | +``` |
| 45 | +exports.plugins = { |
62 | 46 | babel: {
|
63 |
| - presets: ['es2015', 'es2016', 'react'], // es2015, es2016 are defaults |
64 | 47 | ignore: [
|
65 |
| - /^(bower_components|vendor)/, |
| 48 | + /^node_modules/, |
66 | 49 | 'app/legacyES5Code/**/*'
|
67 |
| - ], |
68 |
| - pattern: /\.(es6|jsx)$/ // js and jsx are defaults. |
| 50 | + ] |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +### Changing which files would be compiled by babel |
| 56 | + |
| 57 | +``` |
| 58 | +exports.plugins = { |
| 59 | + babel: { |
| 60 | + pattern: /\.es7$/ // By default, JS|JSX|ES6 are used. |
69 | 61 | }
|
70 | 62 | }
|
71 | 63 | ```
|
72 | 64 |
|
73 |
| -Change Log |
74 |
| ----------- |
| 65 | +Set [babel options](https://babeljs.io/docs/usage/options) in your brunch |
| 66 | +config (such as `brunch-config.js`) except for `filename` and `sourceMap` |
| 67 | +which are handled internally. |
| 68 | + |
| 69 | +## Change Log |
75 | 70 | [See release notes page on GitHub](https://github.com/babel/babel-brunch/releases)
|
76 | 71 |
|
77 |
| -License |
78 |
| -------- |
| 72 | +## License |
| 73 | + |
79 | 74 | [ISC](https://raw.github.com/babel/babel-brunch/master/LICENSE)
|
0 commit comments