8000 Explained how to build multiple configurations by javiereguiluz · Pull Request #9130 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Explained how to build multiple configurations #9130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions frontend/encore/advanced-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,48 @@ But be careful not to accidentally override any config from Encore:
// BAD - this replaces any extensions added by Encore
// config.resolve.extensions = ['json'];

Defining Multiple Webpack Configurations
----------------------------------------

Webpack supports passing an `array of configurations`_, which are processed in
parallel. Webpack Encore includes a ``reset()`` object allowing to reset the
state of the current configuration to build a new one:

.. code-block:: javascript

// define the first configuration
Encore
.setOutputPath('web/build/')
.setPublicPath('/build')
.addEntry('app', './assets/js/main.js')
.addStyleEntry('global', './assets/css/global.scss')
.enableSassLoader()
.autoProvidejQuery()
.enableSourceMaps(!Encore.isProduction())
;

// build the first configuration
const firstConfig = Encore.getWebpackConfig();

// reset Encore to build the second config
Encore.reset();

// define the second configuration
Encore
.setOutputPath('web/build/')
.setPublicPath('/build')
.addEntry('mobile', './assets/js/mobile.js')
.addStyleEntry('mobile', './assets/css/mobile.less')
.enableLessLoader()
.enableSourceMaps(!Encore.isProduction())
;

// build the second configuration
const secondConfig = Encore.getWebpackConfig();

// export the final configuration as an array of multiple configurations
module.exports = [firstConfig, secondConfig];

.. _`configuration options`: https://webpack.js.org/configuration/
.. _`Webpack's watchOptions`: https://webpack.js.org/configuration/watch/#watchoptions
.. _`array of configurations`: https://github.com/webpack/docs/wiki/configuration#multiple-configurations
0