I am currently working on a custom Angular Builder and I need to exclude an entire module from the minification/optimization process.
According to the Webpack .md
file:
exclude
Type: String|RegExp|Array Default: undefinedThis setting is used to specify files to be excluded.
My question is, can I use this setting to exclude an entire directory (like the node module)?
This is the code snippet I am currently using:
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;
}
}