webpack-encore icon indicating copy to clipboard operation
webpack-encore copied to clipboard

Multiple Webpack Configurations with cleanupOutputBeforeBuild

Open fisherspoon opened this issue 3 years ago • 3 comments

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*.*'?

fisherspoon avatar Jul 29 '22 10:07 fisherspoon

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

carsonbot avatar Nov 08 '24 12:11 carsonbot

@carsonbot no, the bug (?) still exists. Since also the entrypoint.json and the manifest.json gets rewritten, if you deploy in the same directory, the only way to do this, seems to have two seperate output dirs.

joworeiter avatar Feb 21 '25 06:02 joworeiter

Hi, the manifest.json config filename can be changed through Encore.configureManifestPlugin({ fileName: 'manifest-second.json' }).

However, it's true that the entrypoints.json is hardcoded in lib/webpack/entry-points-plugin.js.

Would you mind opening a PR? 🙏🏻

Kocal avatar Feb 21 '25 07:02 Kocal

Thank you for this suggestion. There has not been a lot of activity here for a while. Would you still like to see this feature? Every feature is developed by the community. Perhaps someone would like to try? You can read how to contribute to get started.

carsonbot avatar Aug 22 '25 12:08 carsonbot

Hello? This issue is about to be closed if nobody replies.

carsonbot avatar Sep 05 '25 12:09 carsonbot

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

carsonbot avatar Sep 19 '25 12:09 carsonbot