You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Quasar应用生产构建无法移除console.log()问题求助

Quasar生产构建无法移除console.log()的问题

我没法在Quasar应用的生产构建中移除console.log()。我查过StackOverflow、Quasar论坛和GitHub上的相关解决方案,这些方案都说能解决问题,但生产构建里还是有console.log的输出和警告。

我试过以下几种不同的quasar.conf.js配置组合:

配置组合1

module.exports = function (api) {
    build: {
      uglifyOptions: {
        compress: { drop_console: true },
      },
      devtool: 'source-map',
      sourceMap: true,      
      chainWebpack(chain) {
        chain.optimization.minimizer('js').tap((args) => {
          args[0].terserOptions.compress.drop_console = true
          args[0].terserOptions.compress.drop_debugger = true
          return args
        })
      }
    }
}

配置组合2

module.exports = function (api) {
    build: {
      uglifyOptions: {
        compress: { drop_console: true },
      }
    }
}

配置组合3

module.exports = function (api) {
    build: {
      chainWebpack(chain) {
        chain.optimization.minimizer('js').tap((args) => {
          args[0].terserOptions.compress.drop_console = true
          args[0].terserOptions.compress.drop_debugger = true
          return args
        })
      }
    }
}

执行quasar inspect -c build -p optimization.minimizer命令后,输出如下:

[
  TerserPlugin {
    options: {
      test: /\.[cm]?js(\?.*)?$/i {
        [lastIndex]: 0
      },
      minimizer: {
        options: {
          compress: {
            drop_console: true,
            drop_debugger: true
          }
        }
      }
    }
]

我的eslintrc.js配置如下:

module.exports = {
  rules: {
    // allow async-await
    'generator-star-spacing': 'off',
    // allow paren-less arrow functions
    'arrow-parens': 'off',
    'one-var': 'off',
    'optional-chaning': 0,
    'import/first': 'off',
    'import/named': 'error',
    'import/namespace': 'error',
    'import/default': 'error',
    'import/export': 'error',
    'import/extensions': 'off',
    'import/no-unresolved': 'off',
    'import/no-extraneous-dependencies': 'off',
    'prefer-promise-reject-errors': 'off',
    'vue/multi-word-component-names': 0,
    // allow debugger during development only
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  },
}

内容的提问来源于stack exchange,提问作者whoacowboy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 13:50:31