Skip to content

Multiple Webpack Configurations with cleanupOutputBeforeBuild #1141

Open
@fisherspoon

Description

@fisherspoon

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions