feat: allow user to modify generated webpack config

This commit is contained in:
endiliey 2018-08-30 03:30:44 +08:00
parent 2b5ee3e869
commit 10b1a38762
9 changed files with 172 additions and 3 deletions

28
lib/webpack/utils.js Normal file
View file

@ -0,0 +1,28 @@
const merge = require('webpack-merge');
// Modify the generated webpack config with normal webpack config
function applyConfigureWebpack(userConfig, config, isServer) {
if (typeof userConfig === 'object') {
return merge(config, userConfig);
}
if (typeof userConfig === 'function') {
const res = userConfig(config, isServer);
if (res && typeof res === 'object') {
return merge(config, res);
}
}
return config;
}
// Modify the generated webpack config with webpack-chain API
function applyChainWebpack(userChainWebpack, config, isServer) {
if (userChainWebpack) {
userChainWebpack(config, isServer);
}
}
module.exports = {
applyConfigureWebpack,
applyChainWebpack
};