Skip to content

Commit

Permalink
docs(cn): update translations about tree shaking
Browse files Browse the repository at this point in the history
  • Loading branch information
Yucohny committed Dec 18, 2023
1 parent 0538937 commit cf9f9dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/content/configuration/module.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ module.exports = {

`bool`

表明模块的哪一部份包含副作用。详情参阅 [Tree Shaking](/guides/tree-shaking/#mark-the-file-as-side-effect-free)
表明模块的哪一部份包含副作用。请参阅 [Tree Shaking](/guides/tree-shaking/#mark-the-file-as-side-effect-free) 以了解更多信息

## Rule.test $#ruletest$

Expand Down
14 changes: 7 additions & 7 deletions src/content/configuration/optimization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ module.exports = {

`boolean = true` `string: 'flag'`

告知 webpack 去辨识 `package.json` 中的 [`副作用`](https://github.com/webpack/webpack/blob/master/examples/side-effects/README.md) 标记或规则,以跳过那些当导出不被使用且被标记不包含副作用的模块
告诉 webpack 去辨识 `package.json` 中的 [`sideEffects`](https://github.com/webpack/webpack/blob/master/examples/side-effects/README.md) 标记或规则,以跳过那些当导出不被使用且被标记为不包含副作用的模块

**package.json**

Expand All @@ -508,11 +508,11 @@ module.exports = {
}
```

T> 请注意的是 `(副作用)sideEffects` 需要在 npm 模块的 `package.json` 文件中,但并不意味着你需要在你自己的引用那个大模块的项目中的
T> 请注意,`sideEffects` 应该位于 npm 模块的 `package.json` 文件中,但并不意味着你需要在自己项目中引入大模块的
`package.json` 中将 `sideEffects` 设置成 `false`

`optimization.sideEffects` 取决于 [`optimization.providedExports`](#optimizationprovidedexports) 被设置成启用。这个依赖会有构建时间的损耗,但去掉模块会对性能有正面的影响,因为更少的代码被生成。该优化的效果取决于你的代码库
可以尝试这个特性以获取一些可能的性能优化
`optimization.sideEffects` 首先依赖于 [`optimization.providedExports`](#optimizationprovidedexports) 被设置为启用。这个依赖会有构建时间的损耗,但移除模块将生成更少的代码,因此有利于性能的提升。该优化的效果取决于代码库
可以尝试此特性以获取一些可能的性能优化

**webpack.config.js**

Expand All @@ -525,7 +525,7 @@ module.exports = {
};
```

只使用手动 flag,并且不对源码进行分析
如果不想要分析源码,那么可以将其指定为 `flag`

```js
module.exports = {
Expand All @@ -536,9 +536,9 @@ module.exports = {
};
```

此处的 `'flag'` 值在非生产环境默认使用
此处的 `'flag'` 值在非生产环境中默认使用

T> 设置为 `optimization.sideEffects` ,当模块只包含无副作用的语句时,此模块也会被标记为无副作用。
T> 启用 `optimization.sideEffects` ,当模块只包含无副作用的语句时,此模块也会被标记为无副作用。

## optimization.splitChunks $#optimizationsplitchunks$

Expand Down

0 comments on commit cf9f9dc

Please sign in to comment.