|
| 1 | +Advanced Webpack Config |
| 2 | +======================= |
| 3 | + |
| 4 | +Quite simply, Encore generates the Webpack configuration that's used in your |
| 5 | +``webpack.config.js`` file. Encore doesn't support adding all of Webpack's |
| 6 | +`configuration options`_, because many can be easy added on your own. |
| 7 | + |
| 8 | +For example, suppose you need to set `Webpack's watchOptions`_ setting. To do that, |
| 9 | +modify the config it after fetching the it from Encore: |
| 10 | + |
| 11 | +.. code-block:: javascript |
| 12 | +
|
| 13 | + // webpack.config.js |
| 14 | +
|
| 15 | + var Encore = require('@symfony/webpack-encore'); |
| 16 | +
|
| 17 | + // ... all Encore config here |
| 18 | +
|
| 19 | + // fetch the config, then modify it! |
| 20 | + var config = Encore.getWebpackConfig(); |
| 21 | + config.watchOptions = { poll: true, ignored: /node_modules/ }; |
| 22 | +
|
| 23 | + // other examples: add an alias or extension |
| 24 | + // config.resolve.alias.local = path.resolve(__dirname, './resources/src'); |
| 25 | + // config.resolve.extensions.push('json'); |
| 26 | + |
| 27 | +
|
| 28 | + // export the final config |
| 29 | + module.exports = config; |
| 30 | +
|
| 31 | +But be careful not to accidentally override any config from Encore: |
| 32 | + |
| 33 | +.. code-block:: javascript |
| 34 | +
|
| 35 | + // webpack.config.js |
| 36 | + // ... |
| 37 | +
|
| 38 | + // GOOD - this modifies the config.resolve.extensions array |
| 39 | + // config.resolve.extensions.push('json'); |
| 40 | +
|
| 41 | + // BAD - this replaces any extensions added by Encore |
| 42 | + // config.resolve.extensions = ['json']; |
| 43 | +
|
| 44 | +.. _`configuration options`: https://webpack.js.org/configuration/ |
| 45 | +.. _`Webpack's watchOptions`: https://webpack.js.org/configuration/watch/#watchoptions |
0 commit comments