webpack-encore
webpack-encore copied to clipboard
Multiple Webpack Configurations with cleanupOutputBeforeBuild
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?
// 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*.*'?
Thank you for this issue. There has not been a lot of activity here for a while. Has this been resolved?
@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.
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? 🙏🏻
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.
Hello? This issue is about to be closed if nobody replies.
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!