1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.mergeConfigs = void 0;
|
4 | const webpack_merge_1 = require("webpack-merge");
|
5 | const lodash_1 = require("lodash");
|
6 | const DEFAULT_MERGE_RULES = {
|
7 | module: {
|
8 | rules: {
|
9 | test: webpack_merge_1.CustomizeRule.Match,
|
10 | use: {
|
11 | loader: webpack_merge_1.CustomizeRule.Match,
|
12 | options: webpack_merge_1.CustomizeRule.Merge,
|
13 | },
|
14 | },
|
15 | },
|
16 | };
|
17 | function mergeConfigs(webpackConfig1, webpackConfig2, mergeRules = DEFAULT_MERGE_RULES, replacePlugins = false) {
|
18 | const mergedConfig = (0, webpack_merge_1.mergeWithRules)(mergeRules)(webpackConfig1, webpackConfig2);
|
19 | if (webpackConfig1.plugins && webpackConfig2.plugins) {
|
20 | const conf1ExceptConf2 = (0, lodash_1.differenceWith)(webpackConfig1.plugins, webpackConfig2.plugins, (item1, item2) => item1.constructor.name === item2.constructor.name);
|
21 | if (!replacePlugins) {
|
22 | const conf1ByName = (0, lodash_1.keyBy)(webpackConfig1.plugins, 'constructor.name');
|
23 | webpackConfig2.plugins = webpackConfig2.plugins.map(p => conf1ByName[p.constructor.name] ? (0, lodash_1.merge)(conf1ByName[p.constructor.name], p) : p);
|
24 | }
|
25 | mergedConfig.plugins = [...conf1ExceptConf2, ...webpackConfig2.plugins];
|
26 | }
|
27 | return mergedConfig;
|
28 | }
|
29 | exports.mergeConfigs = mergeConfigs;
|
30 |
|
\ | No newline at end of file |