Skip to content

Commit

Permalink
add plugin hook: chainWebpackConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Jul 6, 2018
1 parent 8495d6d commit e2feca7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packages/af-webpack/src/getConfig/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Config from 'webpack-chain';
import { join, dirname, resolve, relative } from 'path';
import { existsSync } from 'fs';
import assert from 'assert';
import { getPkgPath, shouldTransform } from './es5ImcompatibleVersions';
import resolveDefine from './resolveDefine';
import { applyWebpackConfig } from './applyWebpackConfig';
Expand Down Expand Up @@ -294,5 +295,13 @@ export default function(opts) {
require('./prod').default(webpackConfig, opts);
}

if (opts.chainConfig) {
assert(
typeof opts.chainConfig === 'function',
`opts.chainConfig should be function, but got ${opts.chainConfig}`,
);
opts.chainConfig(webpackConfig);
}

return applyWebpackConfig(opts.cwd, webpackConfig.toConfig());
}
15 changes: 14 additions & 1 deletion packages/umi-build-dev/src/getWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,24 @@ export default function(service = {}) {
}),
}),
};

// 修改传给 af-webpack 的配置项
// deprecated
afWebpackOpts = service.applyPlugins('modifyAFWebpackOpts', {
initialValue: afWebpackOpts,
});

let webpackConfig = getConfig(afWebpackOpts);
// 通过 webpack-chain 扩展 webpack 配置
let webpackConfig = getConfig(afWebpackOpts, {
webpackChain(webpackConfig) {
service.applyPlugins('chainWebpackConfig', {
args: { webpackConfig },
});
},
});

// 直接修改 webpack 对象
// deprecated
webpackConfig = service.applyPlugins('modifyWebpackConfig', {
initialValue: webpackConfig,
});
Expand Down

0 comments on commit e2feca7

Please sign in to comment.