Skip to content
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

Multiple Webpack Configurations with cleanupOutputBeforeBuild #1141

Open
fisherspoon opened this issue Jul 29, 2022 · 1 comment
Open

Multiple Webpack Configurations with cleanupOutputBeforeBuild #1141

fisherspoon opened this issue Jul 29, 2022 · 1 comment

Comments

@fisherspoon
Copy link

I found an example of using different build configs, but there is a question how to get around the problem with overwriting files that were created by executing another config?

https://symfony.com/doc/current/frontend/encore/advanced-config.html#defining-multiple-webpack-configurations

// define the first configuration

Encore
    .setOutputPath('public/build/first_build/')
    .setPublicPath('/build/first_build')
    .addEntry('app', './assets/app.js')
    .cleanupOutputBeforeBuild()
    .addStyleEntry('global', './assets/styles/global.scss')
    .enableSassLoader()
    .autoProvidejQuery()
    .enableVersioning(Encore.isProduction())
    .enableSourceMaps(!Encore.isProduction())
;

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

// Set a unique name for the config (needed later!)
firstConfig.name = 'firstConfig';

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

// define the second configuration
Encore
    .setOutputPath('public/build/second_build/')
    .setPublicPath('/build/second_build')
    .cleanupOutputBeforeBuild()
    .addEntry('mobile', './assets/mobile.js')
    .addStyleEntry('mobile', './assets/styles/mobile.less')
    .enableLessLoader()
    .enableVersioning(Encore.isProduction())
    .enableSourceMaps(!Encore.isProduction())
;

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

// Set a unique name for the config (needed later!)
secondConfig.name = 'secondConfig';

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

Let's say I collected the files with the first and second commands
npm run dev -- --config-name firstConfig
npm run dev -- --config-name secondConfig

and i have 2 files in /assets (global4534634.css, mobile13353.css)
but if I run again
npm run dev -- --config-name secondConfig
cleanupOutputBeforeBuild remove global4534634.css file and create new file mobile9469346.css

cleanupOutputBeforeBuild have some options for skip files or remove only files what starts with some name, fore example 'mobile*.*'?

@carsonbot
Copy link

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants