Skip to content

Commit 8e086fe

Browse files
committed
minor symfony#9130 Explained how to build multiple configurations (javiereguiluz)
This PR was merged into the 3.3 branch. Discussion ---------- Explained how to build multiple configurations This fixes symfony#8129 and it's based on these comments: symfony/webpack-encore#48 (comment) Commits ------- a86a3d6 Explained how to build multiple configurations
2 parents bb487a1 + a86a3d6 commit 8e086fe

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

frontend/encore/advanced-config.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,48 @@ But be careful not to accidentally override any config from Encore:
4040
// BAD - this replaces any extensions added by Encore
4141
// config.resolve.extensions = ['json'];
4242
43+
Defining Multiple Webpack Configurations
44+
----------------------------------------
45+
46+
Webpack supports passing an `array of configurations`_, which are processed in
47+
parallel. Webpack Encore includes a ``reset()`` object allowing to reset the
48+
state of the current configuration to build a new one:
49+
50+
.. code-block:: javascript
51+
52+
// define the first configuration
53+
Encore
54+
.setOutputPath('web/build/')
55+
.setPublicPath('/build')
56+
.addEntry('app', './assets/js/main.js')
57+
.addStyleEntry('global', './assets/css/global.scss')
58+
.enableSassLoader()
59+
.autoProvidejQuery()
60+
.enableSourceMaps(!Encore.isProduction())
61+
;
62+
63+
// build the first configuration
64+
const firstConfig = Encore.getWebpackConfig();
65+
66+
// reset Encore to build the second config
67+
Encore.reset();
68+
69+
// define the second configuration
70+
Encore
71+
.setOutputPath('web/build/')
72+
.setPublicPath('/build')
73+
.addEntry('mobile', './assets/js/mobile.js')
74+
.addStyleEntry('mobile', './assets/css/mobile.less')
75+
.enableLessLoader()
76+
.enableSourceMaps(!Encore.isProduction())
77+
;
78+
79+
// build the second configuration
80+
const secondConfig = Encore.getWebpackConfig();
81+
82+
// export the final configuration as an array of multiple configurations
83+
module.exports = [firstConfig, secondConfig];
84+
4385
.. _`configuration options`: https://webpack.js.org/configuration/
4486
.. _`Webpack's watchOptions`: https://webpack.js.org/configuration/watch/#watchoptions
87+
.. _`array of configurations`: https://github.com/webpack/docs/wiki/configuration#multiple-configurations

0 commit comments

Comments
 (0)