@ali-i18n-fe/dada-component
Version:
27 lines (21 loc) • 718 B
JavaScript
const merge = require("webpack-merge");
const uniq = require("lodash/uniq");
exports.mergeWebpack = function (...mergeConfigs) {
const otherConfigs = [];
const totalExternals = [];
const moduleConfig = merge.smart(
...mergeConfigs.map(({ module, externals, ...restConfig }) => {
otherConfigs.push(restConfig);
totalExternals.push(
...(Array.isArray(externals) ? externals : [externals])
);
return { module };
})
);
const resultConfig = merge(...otherConfigs);
const result = Object.assign(resultConfig, moduleConfig);
result.externals = uniq(totalExternals)
.filter(Boolean)
.reduce((prev, item) => Object.assign(prev, item), {});
return result;
};