【问题标题】:Webpack TerserPlugin - exclude node moduleWebpack TerserPlugin - 排除节点模块
【发布时间】:2019-10-26 17:15:36
【问题描述】:

使用自定义 Angular Builder,我试图从缩小/优化中排除整个模块。

Webpack .md 文件说

排除
类型:String|RegExp|Array 默认值:undefined

要排除的文件。

我可以使用此设置排除整个目录(即节点模块)吗?


当前代码是

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;
  }
}

【问题讨论】:

    标签: angular typescript webpack ecmascript-6 single-page-application


    【解决方案1】:

    也许你正在寻找这个

       module.exports = {
          optimization: {
            minimizer: [
              new TerserPlugin({
                exclude: /node_modules/,
              }),
            ],
          },
        };
    

    【讨论】:

    • 所以这是一个匹配整个node_modules文件夹的正则表达式?
    • @LppEdd 我有类似的配置here
    • 试过了,但它仍然缩小并删除了错误的功能。我认为这是因为我使用 Angular Builder 来修改默认的 TerserPlugin 配置。
    • Infact 文件仍然具有构建优化器扩展名(例如 Viewer.js.pre-build-optimizer.js
    • 试试这个one我想它可能对你有帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 2021-02-13
    • 1970-01-01
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 2020-11-17
    相关资源
    最近更新 更多