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/output/legal-comments.md.
close
  • 简体中文
  • output.legalComments

    • 类型: 'linked' | 'inline' | 'none'
    • 默认值: 'linked'

    配置内置 JavaScript 压缩器处理 legal comments 的方式。此选项在启用 JavaScript 压缩 时生效,不控制 CSS 注释。

    Legal comments 指包含 @license、@preserve,或以 //!、/*! 开头的 JavaScript 注释。默认情况下,Rsbuild 会将它们提取到独立的许可证文件中。

    例如 React 的 LICENSE 注释:

    /**
     * @license React
     * react.production.js
     *
     * Copyright (c) Meta Platforms, Inc. and affiliates.
     *
     * This source code is licensed under the MIT license found in the
     * LICENSE file in the root directory of this source tree.
     */

    可选值

    你可以通过 legalComments 来配置如何处理 legal comments:

    linked

    将所有 legal comments 移至 *.LICENSE.txt 文件,并通过注释链接到它们。

    rsbuild.config.js
    export default {
      output: {
        legalComments: 'linked',
      },
    };

    .LICENSE.txt 文件不会被页面加载,因此它们不会影响页面的性能。

    inline

    在压缩后的 JavaScript 中保留 legal comments。这可能会导致输出文件的体积变大。

    rsbuild.config.js
    export default {
      output: {
        legalComments: 'inline',
      },
    };

    none

    移除所有 legal comments。

    rsbuild.config.js
    export default {
      output: {
        legalComments: 'none',
      },
    };
    Tip

    移除 license 注释可能会违反部分开源软件的许可协议要求。在使用此选项前,请确认你具有移除这些注释的权利。