@@ -2,8 +2,8 @@ Configuring Babel
22=================
33
44`Babel `_ is automatically configured for all ``.js `` and ``.jsx `` files via the
5- ``babel-loader `` with sensible defaults (e.g. with the ``env `` preset and
6- ``react `` if requested).
5+ ``babel-loader `` with sensible defaults (e.g. with the ``@babel/preset- env `` and
6+ ``@babel/preset- react `` if requested).
77
88Need to extend the Babel configuration further? The easiest way is via
99``configureBabel() ``:
@@ -16,17 +16,37 @@ Need to extend the Babel configuration further? The easiest way is via
1616 Encore
1717 // ...
1818
19- // first, install any presets you want to use (e.g. yarn add babel-preset-es2017)
20- // then, modify the default Babel configuration
2119 .configureBabel (function (babelConfig ) {
2220 // add additional presets
23- babelConfig .presets .push (' es2017 ' );
21+ // babelConfig.presets.push('@babel/preset-flow ');
2422
2523 // no plugins are added by default, but you can add some
2624 // babelConfig.plugins.push('styled-jsx/babel');
25+ }, {
26+ // node_modules is not processed through Babel by default
27+ // but you can whitelist specific modules to process
28+ // include_node_modules: ['foundation-sites']
29+
30+ // or completely control the exclude
31+ // exclude: /bower_components/
2732 })
2833 ;
2934
35+ Configuring Browser Targets
36+ ---------------------------
37+
38+ The ``@babel/preset-env `` preset rewrites your JavaScript so that the final syntax
39+ will work in whatever browsers you want. To configure the browsers that you need
40+ to support, see :ref: `browserslist_package_config `.
41+
42+ After change our "browerslist" config, you will need to manually remove the babel
43+ cache directory:
44+
45+ .. code-block :: terminal
46+
47+ $ On Unix run this command. On Windows, clear this directory manually
48+ $ rm -rf node_modules/.cache/babel-loader/
49+
3050 Creating a .babelrc File
3151------------------------
3252
@@ -37,21 +57,7 @@ Babel, but it has a downside: as soon as a ``.babelrc`` file is present,
3757if you call ``Encore.enableReactPreset() ``, the ``react `` preset will *not *
3858automatically be added to Babel: you must add it yourself in ``.babelrc ``.
3959
40- An example ``.babelrc `` file might look like this:
41-
42- .. code-block :: json
43-
44- {
45- presets: [
46- ['env', {
47- modules: false,
48- targets: {
49- browsers: '> 1%',
50- uglify: true
51- },
52- useBuiltIns: true
53- } ]
54- ]
55- }
60+ As soon as a ``.babelrc `` file is present, it will take priority over the Babel
61+ configuration added by Encore.
5662
5763.. _`Babel` : http://babeljs.io/
0 commit comments