For AI agents: the complete documentation index is available at https://rsbuild.rs/zh/llms.txt, the full documentation bundle is available at https://rsbuild.rs/zh/llms-full.txt, and this page is available as Markdown at https://rsbuild.rs/zh/config/performance/remove-console.md.
close
  • 简体中文
  • performance.removeConsole

    • 类型: boolean | ConsoleType[]
    • 默认值: false

    是否在 JavaScript 压缩时移除 console.[methodName] 调用。此选项需要启用 JavaScript 压缩 才能生效。

    参数中的副作用会被保留。例如,移除 console.log(doWork()) 后,仍会执行 doWork()。

    全部移除

    当 removeConsole 被设置为 true 时,会移除所有类型的 console.[methodName]:

    rsbuild.config.ts
    export default {
      performance: {
        removeConsole: true,
      },
    };

    指定类型

    你也可以指定仅移除特定类型的 console.[methodName],比如移除 console.log 和 console.warn:

    rsbuild.config.ts
    export default {
      performance: {
        removeConsole: ['log', 'warn'],
      },
    };

    目前支持配置以下类型的 console:

    type ConsoleType = 'log' | 'info' | 'warn' | 'error' | 'table' | 'group';