Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update SourceMapDevToolPlugin docs #6262

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions website/docs/en/plugins/webpack/source-map-dev-tool-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,28 @@ new rspack.SourceMapDevToolPlugin(options);

## Options

- `test` (`string` `RegExp` `[string, RegExp]`): Include source maps for modules based on their extension (defaults to .js, .mjs, and .css).
- `test` (`string` `RegExp` `[string, RegExp]`): Include source maps for modules based on their extension (defaults to `.js`, `.mjs`, and `.css`).
- `include` (`string` `RegExp` `[string, RegExp]`): Include source maps for module paths that match the given value.
- `exclude` (`string` `RegExp` `[string, RegExp]`): Exclude modules that match the given value from source map generation.
- `filename` (`string`): Defines the output filename of the SourceMap (will be inlined if no value is provided).
- `append` (`string` `function`): Appends the given value to the original asset. Usually the #sourceMappingURL comment. [url] is replaced with a URL to the source map file. Path parameters are supported: [chunk], [filename] and [contenthash]. Setting append to false disables the appending.
- `append` (`string` `function`): Appends the given value to the original asset. Usually the `#sourceMappingURL` comment. `[url]` is replaced with a URL to the source map file. Path parameters are supported: `[chunk]`, `[filename]` and `[contenthash]`. Setting append to false disables the appending.
- `moduleFilenameTemplate` (`string`): See [`output.devtoolModuleFilenameTemplate`](/en/config/output.html#outputdevtoolmodulefilenametemplate).
- `fallbackModuleFilenameTemplate` (`string`): See link above.
- `namespace` (`string`): See [`output.devtoolNamespace`](/en/config/output.html#outputdevtoolnamespace).
- `module = true` (`boolean`): Indicates whether loaders should generate source maps.
- `columns = true` (`boolean`): Indicates whether column mappings should be used.
- `noSources = false` (`boolean`): Prevents the source file content from being included in the source map.
- `publicPath` (`string`): Emits absolute URLs with public path prefix, e.g. https://example.com/project/.
- `fileContext` (`string`): Makes the [file] argument relative to this directory.
- `sourceRoot` (`string`): Provide a custom value for the sourceRoot property in the SourceMap.
- `publicPath` (`string`): Emits absolute URLs with public path prefix, e.g. `https://example.com/project/`.
- `fileContext` (`string`): Makes the `[file]` argument relative to this directory.
- `sourceRoot` (`string`): Provide a custom value for the `sourceRoot` property in the SourceMap.

:::tip
Setting `module` and/or `columns` to `false` will yield less accurate source maps but will also improve compilation performance significantly.
:::

:::tip
If you want to use a custom configuration for this plugin in [development mode](/config/mode#development), make sure to disable the default one. I.e. set `devtool: false`.
:::

## Examples

Expand Down
34 changes: 22 additions & 12 deletions website/docs/zh/plugins/webpack/source-map-dev-tool-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,34 @@ import { ApiMeta } from '../../../../components/ApiMeta.tsx';
new rspack.SourceMapDevToolPlugin(options);
```

## 配置项
## 选项

支持以下配置项
支持以下选项

- `test` (`string` `RegExp` `[string, RegExp]`):包含基于扩展名的模块的 source map(默认是 .js, .mjs 和 .css)。
- `test` (`string` `RegExp` `[string, RegExp]`):根据模块扩展名,匹配的生成 source map(默认是 `.js`, `.mjs``.css`)。
- `include` (`string` `RegExp` `[string, RegExp]`):使路径与该值匹配的模块生成 source map。
- `exclude` (`string` `RegExp` `[string, RegExp]`):使匹配该值的模块不生成 source map。
- `filename` (`string`):定义生成的 SourceMap 的名称(不设置将默认置为 inlined)。
- `append` (`string` `function`):在原始资源后追加给定值。通常是 #sourceMappingURL 注释。[url] 被替换成 source map 文件的 URL。支持 path 参数:[chunk][filename] 和 [contenthash]。设置 appendfalse 会禁止追加
- `moduleFilenameTemplatestring)`:详见 [`output.devtoolModuleFilenameTemplate`](/zh/config/output.html#outputdevtoolmodulefilenametemplate)。
- `filename` (`string`):定义生成的 source map 的名称(如果未提供值,则内联)。
- `append` (`string` `function`):原始资源后追加给定值。通常是 `#sourceMappingURL` 注释。`[url]` 被替换成 source map 文件的 URL。支持路径参数:`[chunk]`、`[filename]``[contenthash]`。将 `append` 设置为 `false` 可禁用附加操作
- `moduleFilenameTemplate`(`string`):详见 [`output.devtoolModuleFilenameTemplate`](/zh/config/output.html#outputdevtoolmodulefilenametemplate)。
- `fallbackModuleFilenameTemplate` (`string`):详见上面的链接。
- `namespace` (`string`):详见 [`output.devtoolNamespace`](/zh/config/output.html#outputdevtoolnamespace).
- `module = true` (`boolean`):表示 loader 是否生成 source map。
- `columns = true` (`boolean`):表示是否应该使用 column mapping。
- `noSources = false` (`boolean`):防止源文件的内容被包含在 source map 中。
- `publicPath` (`string`):生成带 public path 前缀的绝对 URL,例如:https://example.com/project/。
- `fileContext` (`string`):使得 [file] 参数作为本目录的相对路径。
- `sourceRoot` (`string`):给 SourceMap 中的 sourceRoot 属性提供一个自定义值。
- `module = true` (`boolean`):指示 loader 是否应该生成 source map 文件。
- `columns = true` (`boolean`):指示是否使用 column mapping。
- `noSources = false` (`boolean`):阻止源文件内容被包含在 source map 中。
- `publicPath` (`string`):使用公共路径前缀生成绝对 URL,例如 `https://example.com/project/`。
- `fileContext` (`string`):使 `[file]` 参数相对于这个目录。
- `sourceRoot` (`string`):为 source map 中的 `sourceRoot` 属性提供自定义值。

`fileContext` 选项在你希望将 source map 存储在上级目录以避免绝对 `[url]` 中出现 `../../` 时非常有用。

:::tip 提示
将 `module` 或 `columns` 设置为 `false` 将生成不太准确的 source map,但同时也能显著提高编译性能。
:::

:::tip 提示
如果你想要在[开发模式](/config/mode#development)中为这个插件使用自定义配置,请确保禁用默认配置。即设置 `devtool: false`。
:::

## 示例

Expand Down
Loading