使用自定义Angular Builder,我试图从缩小/优化中排除整个模块。
Webpack .md
文件说
排除
类型:字符串| RegExp |数组默认值:未定义要排除的文件。
我可以使用此设置排除整个目录(这是节点模块)吗?
当前代码为
export default class CustomizeTerserBrowserBuilder extends BrowserBuilder {
public buildWebpackConfig(root: any, projectRoot: any, host: any, options: any): any {
const webpackConfig = super.buildWebpackConfig(root, projectRoot, host, options);
if (
webpackConfig.optimization &&
webpackConfig.optimization.minimizer &&
Array.isArray(webpackConfig.optimization.minimizer)
) {
const terserPlugin = (webpackConfig.optimization.minimizer as any[]).find(
minimizer => minimizer instanceof TerserPlugin
);
if (terserPlugin) {
terserPlugin.options.exclude = [/node_modules/];
}
}
return webpackConfig;
}
}
答案 0 :(得分:1)
也许您正在寻找这个
module.exports = {
optimization: {
minimizer: [
new TerserPlugin({
exclude: /node_modules/,
}),
],
},
};