For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/configure/app/output/source-map.md.
  • 简体中文
  • output.sourceMap

    • 类型:
    type SourceMap =
      | boolean
      | {
          js?: Rspack.Configuration['devtool'];
          css?: boolean;
        };

    用于设置是否生成 source map 文件,以及生成哪一种格式的 source map。

    • 默认值:
    const defaultSourceMap = {
      js: isDev ? 'cheap-module-source-map' : 'hidden-source-map',
      css: isDev,
    };

    在不配置 output.sourceMap 时,Modern.js 的 source map 生成规则与 Rsbuild 配置有差异:

    • 在开发模式构建时,会生成 JS 文件和 CSS 的 source map,便于进行开发调试。
    • 在生产模式构建时,会生成 JS 的 source map 用于堆栈回溯,不生成 CSS 文件的 source map,以提供最佳的构建性能。
    Info

    该配置项的使用方式与 Rsbuild 完全一致。详细信息请参考 Rsbuild - output.sourceMap。