Skip to content

Commit a61a07e

Browse files
authored
Merge branch 'cn' into sync-d054d465-1
2 parents 6ed067d + ca89c3e commit a61a07e

File tree

13 files changed

+778
-1100
lines changed

13 files changed

+778
-1100
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"@babel/plugin-proposal-class-properties": "^7.17.12",
8888
"@babel/preset-env": "^7.19.4",
8989
"@babel/preset-react": "^7.18.6",
90-
"@mdx-js/loader": "^2.0.0-next.9",
90+
"@mdx-js/loader": "^2.3.0",
9191
"@octokit/auth-action": "^2.0.2",
9292
"@octokit/rest": "^19.0.5",
9393
"@pmmmwh/react-refresh-webpack-plugin": "next",
@@ -97,7 +97,7 @@
9797
"copy-webpack-plugin": "^11.0.0",
9898
"css-loader": "^6.7.1",
9999
"css-minimizer-webpack-plugin": "^4.2.2",
100-
"cypress": "^10.11.0",
100+
"cypress": "^12.7.0",
101101
"directory-tree": "^3.3.1",
102102
"directory-tree-webpack-plugin": "^1.0.3",
103103
"duplexer": "^0.1.1",
@@ -115,13 +115,13 @@
115115
"husky": "^8.0.1",
116116
"hyperlink": "^5.0.4",
117117
"jest": "^29.2.2",
118-
"lightningcss": "^1.16.0",
118+
"lightningcss": "^1.19.0",
119119
"lint-staged": "^13.0.3",
120120
"lodash": "^4.17.21",
121121
"markdownlint": "^0.26.2",
122122
"markdownlint-cli": "^0.32.2",
123123
"mdast-util-to-string": "^3.1.0",
124-
"mini-css-extract-plugin": "^2.6.1",
124+
"mini-css-extract-plugin": "^2.7.2",
125125
"mkdirp": "^1.0.4",
126126
"modularscale-sass": "^3.0.3",
127127
"node-fetch": "^3.2.10",
@@ -198,7 +198,7 @@
198198
"style-loader": "^3.3.1",
199199
"tailwindcss": "^3.2.1",
200200
"tap-spot": "^1.1.2",
201-
"textlint": "^11.8.2",
201+
"textlint": "^13.3.1",
202202
"textlint-rule-heading": "^1.0.10",
203203
"unist-util-visit": "^4.1.1",
204204
"webpack": "^5.74.0",

src/content/api/normalmodulefactory-hooks.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ NormalModuleFactory.hooks.someHook.for('identifier').tap(/* ... */);
8686

8787
`HookMap<SyncBailHook>`
8888

89-
`Parser` 实例创建后调用`parserOptions`[module.parser](/configuration/module/#moduleparser) 中对应标识符或空对象的选项。
89+
`Parser` 实例创建之前调用`parserOptions`[module.parser](/configuration/module/#moduleparser) 中对应标识符或空对象的选项。
9090

9191
- 钩子参数:`identifier`
9292

@@ -116,7 +116,7 @@ NormalModuleFactory.hooks.someHook.for('identifier').tap(/* ... */);
116116

117117
`HookMap<SyncBailHook>`
118118

119-
`Generator` 实例创建后调用`generatorOptions`[module.parser](/configuration/module/#modulegenerator) 中对应标识符或空对象的选项。
119+
`Generator` 实例创建之前调用`generatorOptions`[module.parser](/configuration/module/#modulegenerator) 中对应标识符或空对象的选项。
120120

121121
- 钩子参数:`identifier`
122122

src/content/concepts/under-the-hood.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module.exports = {
6666
这会创建出两个名为 `home``about` 的 chunk 组。
6767
每个 chunk 组都有一个包含一个模块的 chunk:`./home.js` 对应 `home``./about.js` 对应 `about`
6868

69-
> 一个 chunk 组中可能有多个 chunk。例如,[SplitChunksPlugin](/plugins/split-chunks-plugin/) 会将一个 chunk 拆分为一个或多个 chunk。
69+
> 一个 chunk 组中可能有多个 chunk。例如,[SplitChunksPlugin](/plugins/split-chunks-plugin/) 会将一个 chunk 组拆分为一个或多个 chunk。
7070
7171
## chunk $#chunks$
7272

src/content/contribute/plugin-patterns.mdx

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
11
---
2-
title: Plugin Patterns
2+
title: 插件模式
33
sort: 5
44
contributors:
55
- nveenjain
66
- EugeneHlushko
77
- benglynn
8+
- Yucohny
9+
translators:
10+
- jsbugwang
811
---
912

10-
Plugins grant unlimited opportunity to perform customizations within the webpack build system. This allows you to create custom asset types, perform unique build modifications, or even enhance the webpack runtime while using middleware. The following are some features of webpack that become useful while writing plugins.
13+
webpack 构建系统中,能够通过插件进行定制,这赋予了无限的可能性。这使你可以创建自定义资源类型,执行唯一的构建修改,甚至可以使用中间件来增强 webpack 运行时。下面是在编写插件时非常有用一些 webpack 的功能。
1114

12-
## Exploring assets, chunks, modules, and dependencies $#exploring-assets-chunks-modules-and-dependencies$
15+
## 检索遍历资源、chunk、模块和依赖 $#exploring-assets-chunks-modules-and-dependencies$
1316

14-
After a compilation is sealed, all structures within the compilation may be traversed.
17+
在执行完成编译的封存阶段后,编译的所有结构都可以遍历。
1518

1619
```javascript
1720
class MyPlugin {
1821
apply(compiler) {
1922
compiler.hooks.emit.tapAsync('MyPlugin', (compilation, callback) => {
20-
// Explore each chunk (build output):
23+
// 检索每个(构建输出的)chunk
2124
compilation.chunks.forEach((chunk) => {
22-
// Explore each module within the chunk (built inputs):
25+
// 检索 chunk 中(内置输入的)的每个模块:
2326
chunk.getModules().forEach((module) => {
24-
// Explore each source file path that was included into the module:
27+
// 检索模块中包含的每个源文件路径:
2528
module.buildInfo &&
2629
module.buildInfo.fileDependencies &&
2730
module.buildInfo.fileDependencies.forEach((filepath) => {
28-
// we've learned a lot about the source structure now...
31+
// 我们现在已经对源结构有不少了解……
2932
});
3033
});
3134

32-
// Explore each asset filename generated by the chunk:
35+
// 检索由 chunk 生成的每个资源文件名:
3336
chunk.files.forEach((filename) => {
34-
// Get the asset source for each file generated by the chunk:
37+
// 获取 chunk 生成的每个文件的资源源代码:
3538
var source = compilation.assets[filename].source();
3639
});
3740
});
@@ -43,21 +46,21 @@ class MyPlugin {
4346
module.exports = MyPlugin;
4447
```
4548

46-
- `compilation.modules`: A set of modules (built inputs) in the compilation. Each module manages the build of a raw file from your source library.
49+
- `compilation.modules`:编译后的(内置输入的)模块数组。每个模块管理控制来源代码库中的原始文件的构建。
4750

48-
W> **Deprecation warning**: Array functions will still work.
51+
W> **弃用警告**:数组函数依然可用。
4952

50-
- `module.fileDependencies`: An array of source file paths included into a module. This includes the source JavaScript file itself (ex: `index.js`), and all dependency asset files (stylesheets, images, etc) that it has required. Reviewing dependencies is useful for seeing what source files belong to a module.
51-
- `compilation.chunks`: A set of chunks (build outputs) in the compilation. Each chunk manages the composition of a final rendered assets.
53+
- `module.fileDependencies`:模块中引入的源文件路径构成的数组。这包括源 JavaScript 文件本身(例如:index.js)以及它所需的所有依赖资源文件(样式表、图像等)。审查依赖,可以用于查看一个模块有哪些从属的源文件。
54+
- `compilation.chunks`:编译后的(构建输出的)chunk 集合。每个 chunk 所管理控制的最终渲染资源的组合。
5255

53-
W> **Deprecation warning**: Array functions will still work.
56+
W> **弃用警告**:数组函数依然可用。
5457

55-
- `chunk.getModules()`: An array of modules that are included into a chunk. By extension, you may look through each module's dependencies to see what raw source files fed into a chunk.
56-
- `chunk.files`: A Set of output filenames generated by the chunk. You may access these asset sources from the `compilation.assets` table.
58+
- `chunk.getModules()`chunk 中引入的模块构成的数组。通过扩展可以审查每个模块的依赖,来查看哪些原始源文件被注入到 chunk 中。
59+
- `chunk.files`chunk 生成的输出文件名构成的集合。你可以从 `compilation.assets` 表中访问这些资源来源。
5760

58-
### Monitoring the watch graph $#monitoring-the-watch-graph$
61+
### 监听观察图的修改 $#monitoring-the-watch-graph$
5962

60-
While running webpack middleware, each compilation includes a `fileDependencies` `Set` (what files are being watched) and a `fileTimestamps` `Map` that maps watched file paths to a timestamp. These are extremely useful for detecting what files have changed within the compilation:
63+
运行 webpack 中间件时,每个编译包括一个 `fileDependencies` `Set`(正在观察哪些文件)和一个 `fileTimestamps` `Map`,它将被观察的文件路径映射到时间戳。这可以用于检测编译中哪些文件已经修改:
6164

6265
```javascript
6366
class MyPlugin {
@@ -85,15 +88,15 @@ class MyPlugin {
8588
module.exports = MyPlugin;
8689
```
8790

88-
You may also feed new file paths into the watch graph to receive compilation triggers when those files change. Add valid file paths into the `compilation.fileDependencies` `Set` to add them to the watched files.
91+
还可以将新文件路径添加到观察图中,以在这些文件修改时,接收消息和重新触发编译。只要将有效的文件路径推送到 `compilation.fileDependencies` `Set` 中,就可以将其添加到观察图中。
8992

90-
T> The `fileDependencies` `Set` is rebuilt in each compilation, so your plugin must add its own watched dependencies into each compilation to keep them under watch.
93+
T> `fileDependencies` `Set` 在每次编译时都会重新构建,因此你的插件必须将自己要观察的依赖都推送到每次编译中,以使它们都处于观察中。
9194

92-
W> Since webpack 5, `compilation.fileDependencies`, `compilation.contextDependencies` and `compilation.missingDependencies` are now a `Set` instead of a `Sortable Set` and thus no longer sorted.
95+
W> webpack v5 开始, `compilation.fileDependencies``compilation.contextDependencies` `compilation.missingDependencies` `Set` 类型,而不是 `Sortable Set`,因此不再是有序的了。
9396

94-
## Changed chunks $#changed-chunks$
97+
## 监听 chunk 的修改 $#changed-chunks$
9598

96-
Similar to the watch graph, you can monitor changed chunks (or modules, for that matter) within a compilation by tracking their hashes.
99+
类似于观察图,监听 chunk(或者模块,就当前情况而言)的修改也很简单,通过在编译时跟踪它们的哈希来实现。
97100

98101
```javascript
99102
class MyPlugin {

0 commit comments

Comments
 (0)