Skip to content

Commit

Permalink
docs: enhance legal comments configuration documentation (#4473)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Feb 2, 2025
1 parent 7a6c913 commit acb92d0
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 16 deletions.
60 changes: 52 additions & 8 deletions website/docs/en/config/output/legal-comments.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,68 @@
- **Type:** `'linked' | 'inline' | 'none'`
- **Default:** `'linked'`

Configure how to handle the legal comment.
Configure how to handle the legal comments.

## What are legal comments?

A "legal comment" is considered to be any statement-level comment in JS or rule-level comment in CSS that contains @license or @preserve or that starts with //! or /\*!. These comments are preserved in output files by default since that follows the intent of the original authors of the code.

This behavior can be configured by using one of the following options:
For example, the `LICENSE` comment in React:

```js
/**
* @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.
*/
```

## Optional values

- `linked`: Extract all legal comments to a .LEGAL.txt file and link to them with a comment.
- `inline`: Preserve all legal comments in original position.
- `none`: Remove all legal comments.
You can configure how to handle legal comments by using one of the following options:

## Example
### `linked`

Remove all legal comments:
Extract all legal comments to `*.LICENSE.txt` files and link to them with a comment.

```js
```js title="rsbuild.config.js"
export default {
output: {
legalComments: 'linked',
},
};
```

`.LICENSE.txt` files are not loaded by the page, so they won't affect the page's performance.

### `inline`

Preserve all legal comments in the original position. This may increase the size of the output bundles.

```js title="rsbuild.config.js"
export default {
output: {
legalComments: 'inline',
},
};
```

### `none`

Remove all legal comments.

```js title="rsbuild.config.js"
export default {
output: {
legalComments: 'none',
},
};
```

:::tip
Removing license comments may violate the terms of some software licenses. Please ensure you have the right to remove these comments before using this option.
:::
60 changes: 52 additions & 8 deletions website/docs/zh/config/output/legal-comments.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,68 @@
- **类型:** `'linked' | 'inline' | 'none'`
- **默认值:** `'linked'`

配置 legal comment 的处理方式。
配置 legal comments 的处理方式。

legal comment 是 JS 或 CSS 文件中的一些特殊注释,这些注释包含 `@license``@preserve`,或是以 `//!` 开头。默认情况下,这些注释保留在输出文件中,因为这遵循了代码原作者的意图。
## 什么是 legal comments?

你可以通过 `legalComments` 来配置相关行为:
Legal comments 是 JS 或 CSS 文件中的一些特殊注释,这些注释包含 `@license``@preserve`,或是以 `//!` 开头。默认情况下,这些注释保留在输出文件中,因为这遵循了代码原作者的意图。

- `linked`:将所有 legal comments 移至 .LEGAL.txt 文件并通过注释链接到它们。
- `inline`:保留所有 legal comments。
- `none`:移除所有 legal comments。
例如 React 的 `LICENSE` 注释:

## 示例
```js
/**
* @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` 文件,并通过注释链接到它们。

```js title="rsbuild.config.js"
export default {
output: {
legalComments: 'linked',
},
};
```

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

### `inline`

保留所有 legal comments 在代码的原始位置。这可能会导致输出文件的体积变大。

```js title="rsbuild.config.js"
export default {
output: {
legalComments: 'inline',
},
};
```

### `none`

移除所有 legal comments。

```js
```js title="rsbuild.config.js"
export default {
output: {
legalComments: 'none',
},
};
```

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

0 comments on commit acb92d0

Please sign in to comment.