Support function-type webpack configs
See original GitHub issueFunction-type config support added in webpack 2 is super useful for making conditional configs. I wrote a tiny package that wraps webpack-merge and adds support for merging function configs, but it seems like it could very easily be a supported feature in webpack-merge.
Here’s how I’d envision it working:
// this needs a better name
const webpackMerge = require('webpack-merge/config-function');
const mergeStrategy = {/* ... */};
module.exports = webpackMerge.smartStrategy(mergeStrategy)(
(env, options) => ({
output: {
filename: env.useHash ? '[name]-[].js' : '[name].js',
},
}),
// ...
);
Merge functions imported from webpack-merge/config-function (name extremely WIP) would be the same merge functions provided by webpack-merge, but each function would return a config function instead of a config object. This returned function would take the parameters given to it by the webpack/webpack-dev-server CLI and pass them on to each config function. Functions would be called and the result would be merged using the merge functions from webpack-merge. Essentially, each merge function would be a lightweight wrapper around the parent merge function.
If this is something that’s of interest to you, I can cook up a PR.
This could very easily be extended to support Promise configs as well (as mentioned in #81).
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:29 (11 by maintainers)

Top Related StackOverflow Question
@5arias a workaround that I’m using right now is as follows:
in my webpack.dev.js I do
and in my webpack.common.js
That said, I’d love to see this functionality added!
@Joonpark13
This looks great but how do you run your builds from npm scripts? Having
looks like over-configuration: both
dev/developmentandprod/productionin command. The config itself should define all needed params.