Merging config with multiple targets
See original GitHub issueI’m after using multiple targets to have a server side config and a client side config packaged. Where one targets node and the other uses the default web target.
webpack.base.js
let clientConfig = {
entry: "./src/website/js/App.tsx"
}
let serverConfig = {
entry: "./src/server/server.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].js",
},
target: "node"
};
}
webpack.config.js
let clientConfig = {
devtool: "source-map"
};
module.exports = webpackMerge(config, [clientConfig]);
Before the merge the json looks healthy:
[ { entry: './src/website/js/App.tsx' },
{ entry: './src/server/server.js',
output: { path: 'C:\\Dev\\dist', filename: '[name].js' },
target: 'node' } ]
But the output from the merge looks like it’s become a single object and hence now fails with the typical errors 'output.filename' is required ...
{ '0':
{ entry: './src/website/js/App.tsx',
devtool: 'source-map',
module: { rules: [Object] },
output: { filename: '[name].js' },
plugins: [ [Object], [Object] ] },
'1':
{ entry: './src/server/server.js',
output: { path: 'C:\\Dev\\dist', filename: '[name].js' },
target: 'node' } }
Issue Analytics
- State:
- Created 7 years ago
- Comments:18 (17 by maintainers)
Top Results From Across the Web
Combined documentation of multiple targets - Swift-DocC
When merging documentation archives, cross-target links to documentation archives that that are not passed as input will be transformed by DocC.
Read more >How to build for multiple targets with webpack? - Stack Overflow
In my common config, I was using clean-webpack-plugin: plugins: [ new CleanWebpackPlugin(), ... ] Obviously, when building the second target ...
Read more >Understanding and using the multi-target exporter pattern
This guide will introduce you to the multi-target exporter pattern. To achieve this we will: describe the multi-target exporter pattern and why it...
Read more >Composing Configuration - SurviveJS
In this case, you would point to the targets through webpack --config parameter and merge common configuration through module.exports = merge(common, config); ....
Read more >Configure multi-targeting - NET MAUI - Microsoft Learn
Combine filename and folder multi-targeting ; <!-- Android --> · Condition="$(TargetFramework.StartsWith('net7.0-android')) != true"> · Remove="**\ ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks. I think I see a way that could be a good compromise:
module.exports = { clientConfig, serverConfig };.module.exports = [merge(base.clientConfig, clientConfig), base.serverConfig];module.exports = [base.clientConfig, base.serverConfig];It’s a bit more code than in the ideal solution. The key insight is that base.js doesn’t have to care about composition at all. It’s enough if it exposes the configuration fragments you compose later. In production you can skip merging entirely as earlier. During development you tweak the client configuration. If you needed to tweak the server too, it would be possible there.
I thought about expanding webpack-merge to support what you need but that would lead to a special case to document (also something for users to remember). That said, it could be sensible to write a multi-compiler friendly variant which performs merge based on array position like in your example.
@ggirard07 Yeah, let’s close. Good call.