Skip to content

Commit 277aa78

Browse files
authored
Merge pull request #1455 from docschina/sync-0462e9b4
docs(en): merge webpack.js.org/master into webpack.js.org/cn @ 0462e9b
2 parents 2cf3456 + 94532a5 commit 277aa78

File tree

9 files changed

+333
-219
lines changed

9 files changed

+333
-219
lines changed

package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,26 @@
7373
]
7474
},
7575
"devDependencies": {
76-
"@babel/core": "^7.16.12",
77-
"@babel/eslint-parser": "^7.16.5",
76+
"@babel/core": "^7.17.0",
77+
"@babel/eslint-parser": "^7.17.0",
7878
"@babel/plugin-proposal-class-properties": "^7.16.7",
7979
"@babel/preset-env": "^7.16.11",
8080
"@babel/preset-react": "^7.16.7",
8181
"@mdx-js/loader": "^2.0.0-next.9",
8282
"@octokit/auth-action": "^1.3.3",
8383
"@octokit/rest": "^18.12.0",
8484
"@pmmmwh/react-refresh-webpack-plugin": "next",
85-
"@svgr/webpack": "^6.2.0",
85+
"@svgr/webpack": "^6.2.1",
8686
"autoprefixer": "^10.4.2",
8787
"babel-loader": "^8.2.3",
88-
"copy-webpack-plugin": "^10.2.1",
89-
"css-loader": "^6.5.1",
88+
"copy-webpack-plugin": "^10.2.4",
89+
"css-loader": "^6.6.0",
9090
"css-minimizer-webpack-plugin": "^3.4.1",
91-
"cypress": "^9.3.1",
92-
"directory-tree": "^3.0.1",
91+
"cypress": "^9.4.1",
92+
"directory-tree": "^3.1.0",
9393
"directory-tree-webpack-plugin": "^1.0.3",
9494
"duplexer": "^0.1.1",
95-
"eslint": "^8.7.0",
95+
"eslint": "^8.8.0",
9696
"eslint-config-prettier": "^8.3.0",
9797
"eslint-plugin-cypress": "^2.12.1",
9898
"eslint-plugin-mdx": "^1.16.0",
@@ -106,7 +106,7 @@
106106
"husky": "^7.0.4",
107107
"hyperlink": "^5.0.4",
108108
"jest": "^27.4.7",
109-
"lint-staged": "^12.3.2",
109+
"lint-staged": "^12.3.3",
110110
"lodash": "^4.17.21",
111111
"markdownlint": "^0.25.1",
112112
"markdownlint-cli": "^0.30.0",
@@ -116,7 +116,7 @@
116116
"modularscale-sass": "^3.0.3",
117117
"node-fetch": "^3.2.0",
118118
"npm-run-all": "^4.1.1",
119-
"postcss": "^8.4.5",
119+
"postcss": "^8.4.6",
120120
"postcss-loader": "^6.2.1",
121121
"prettier": "^2.5.1",
122122
"react-refresh": "^0.11.0",
@@ -131,27 +131,27 @@
131131
"remark-refractor": "montogeek/remark-refractor",
132132
"remark-slug": "^7.0.1",
133133
"rimraf": "^3.0.2",
134-
"sass": "^1.49.0",
134+
"sass": "^1.49.7",
135135
"sass-loader": "^12.4.0",
136136
"sirv-cli": "^2.0.2",
137137
"sitemap-static": "^0.4.2",
138138
"start-server-and-test": "^1.14.0",
139139
"static-site-generator-webpack-plugin": "^3.4.1",
140140
"style-loader": "^3.3.1",
141-
"tailwindcss": "^3.0.17",
141+
"tailwindcss": "^3.0.18",
142142
"tap-spot": "^1.1.1",
143143
"textlint": "^11.8.2",
144144
"textlint-rule-heading": "^1.0.10",
145145
"unist-util-visit": "^4.1.0",
146-
"webpack": "^5.67.0",
146+
"webpack": "^5.68.0",
147147
"webpack-bundle-analyzer": "^4.5.0",
148148
"webpack-cli": "^4.9.2",
149-
"webpack-dev-server": "^4.7.3",
149+
"webpack-dev-server": "^4.7.4",
150150
"webpack-merge": "^5.8.0",
151151
"workbox-webpack-plugin": "^6.4.2"
152152
},
153153
"dependencies": {
154-
"@docsearch/react": "^3.0.0-alpha.42",
154+
"@docsearch/react": "^3.0.0-alpha.50",
155155
"path-browserify": "^1.0.1",
156156
"prop-types": "^15.8.1",
157157
"react": "^17.0.2",

src/content/api/module-variables.mdx

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ contributors:
1313
- anikethsaha
1414
- chenxsan
1515
- jamesgeorge007
16+
- snitin315
1617
related:
1718
- title: CommonJS
1819
url: https://en.wikipedia.org/wiki/CommonJS
@@ -84,7 +85,7 @@ exports.aFunction = function doSomething() {
8485

8586
如果在一个被 Parser 解析的表达式内部使用,则配置选项会被当作 `true` 处理。
8687

87-
## import.meta.url $#import-meta-url$
88+
## import.meta.url
8889

8990
返回模块以 `file:` 开头绝对路径的 URL。
9091

@@ -94,7 +95,7 @@ exports.aFunction = function doSomething() {
9495
console.log(import.meta.url); // 输出结果类似于 `file:///path/to/your/project/src/index.js`
9596
```
9697
97-
## import.meta.webpack $#import-meta-webpack$
98+
## import.meta.webpack
9899
99100
返回 webpack 的版本
100101
@@ -104,7 +105,7 @@ console.log(import.meta.url); // 输出结果类似于 `file:///path/to/your/pro
104105
console.log(import.meta.webpack); // output `5` for webpack 5
105106
```
106107
107-
## import.meta.webpackHot $#importmetawebpackhot$
108+
## import.meta.webpackHot
108109
109110
webpack 特定。[`module.hot`](#modulehot-webpack-specific) 的一个别名,[strict ESM](/guides/ecma-script-modules/#flagging-modules-as-esm) 中可以使用 `import.meta.webpackHot` 但是不能使用 `module.hot`
110111
@@ -132,15 +133,15 @@ require('file.js?test');
132133
__resourceQuery === '?test';
133134
```
134135
135-
## \_\_webpack_public_path\_\_ (webpack-specific) $#__webpack_public_path__-webpack-specific$
136+
## \_\_webpack_public_path\_\_ (webpack-specific)
136137
137138
等同于 `output.publicPath` 配置选项。
138139
139-
## \_\_webpack_require\_\_ (webpack-specific) $#__webpack_require__-webpack-specific$
140+
## \_\_webpack_require\_\_ (webpack-specific)
140141
141142
原始 require 函数。这个表达式不会被解析器解析为依赖。
142143
143-
## `__webpack_chunk_load__` (webpack 特有变量) $#__webpack_chunk_load__-webpack-specific$
144+
## `__webpack_chunk_load__` (webpack-specific)
144145
145146
内部 chunk 载入函数,有一个输入参数:
146147
@@ -168,15 +169,27 @@ import('./module-a').then((moduleA) => {
168169
});
169170
```
170171
171-
## \_\_webpack_modules\_\_ (webpack-specific) $#__webpack_modules__-webpack-specific$
172+
## \_\_webpack_module\_\_ (webpack-specific)
173+
174+
<Badge text="5.68.0+" />
175+
176+
它提供对当前 `module` 的访问。`module` 在 ESM 严格模式下不可用。
177+
178+
## \_\_webpack_module\_\_.id (webpack-specific)
179+
180+
<Badge text="5.68.0+" />
181+
182+
它提供对当前 `module`(`module.id`) ID 的访问。`module` 在 ESM 严格模式下不可用。
183+
184+
## \_\_webpack_modules\_\_ (webpack-specific)
172185
173186
访问所有模块的内部对象。
174187
175-
## \_\_webpack_hash\_\_ (webpack-specific) $#__webpack_hash__-webpack-specific$
188+
## \_\_webpack_hash\_\_ (webpack-specific)
176189
177190
这个变量提供对编译过程中(compilation)的 hash 信息的访问。
178191
179-
## \_\_webpack_get_script_filename\_\_ (webpack-specific) $#__webpack_get_script_filename__-webpack-specific$
192+
## \_\_webpack_get_script_filename\_\_ (webpack-specific)
180193
181194
`function (chunkId)`
182195

@@ -193,11 +206,11 @@ __webpack_get_script_filename__ = (chunkId) => {
193206
};
194207
```
195208
196-
## \_\_non_webpack_require\_\_ (webpack-specific) $#__non_webpack_require__-webpack-specific$
209+
## \_\_non_webpack_require\_\_ (webpack-specific)
197210
198211
生成一个不会被 webpack 解析的 `require` 函数。配合全局可以获取到的 require 函数,可以完成一些酷炫操作。
199212
200-
## \_\_webpack_exports_info\_\_ (webpack-specific) $#__webpack_exports_info__-webpack-specific$
213+
## \_\_webpack_exports_info\_\_ (webpack-specific)
201214
202215
在模块中, `__webpack_exports_info__` 可以被获取到,以便导出模块用以自我检查:
203216
@@ -221,7 +234,7 @@ __webpack_get_script_filename__ = (chunkId) => {
221234
222235
- 可以从嵌套的 exports 中得到相关信息: 例如 `__webpack_exports_info__.<exportName>.<exportName>.<exportName>.used`
223236
224-
## \_\_webpack_is_included\_\_ (webpack-specific) $#webpack-is-included$
237+
## \_\_webpack_is_included\_\_ (webpack-specific)
225238
226239
<Badge text="5.16.0+" />
227240
@@ -233,7 +246,7 @@ if (__webpack_is_included__('./module-a.js')) {
233246
}
234247
```
235248
236-
## \_\_webpack_base_uri\_\_ (webpack-specific) $#webpack-base-uri$
249+
## \_\_webpack_base_uri\_\_ (webpack-specific)
237250
238251
运行时修改 base 的 URI。
239252
@@ -244,7 +257,7 @@ if (__webpack_is_included__('./module-a.js')) {
244257
__webpack_base_uri__ = 'https://example.com';
245258
```
246259
247-
## \_\_webpack_runtime_id\_\_ $#webpackruntimeid$
260+
## \_\_webpack_runtime_id\_\_
248261
249262
访问当前入口的 [runtime](/blog/2020-10-10-webpack-5-release/#entry-point-runtime) id。
250263
@@ -256,6 +269,6 @@ if (__webpack_is_included__('./module-a.js')) {
256269
console.log(__webpack_runtime_id__ === 'main');
257270
```
258271
259-
## DEBUG (webpack-specific) $#debug--webpack-specific$
272+
## DEBUG (webpack-specific)
260273
261274
等同于 `debug` 配置选项。

src/content/concepts/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ T> 查看 [插件接口(plugin interface)](/api/plugins),学习如何使用它
139139
**webpack.config.js**
140140

141141
```javascript
142-
const HtmlWebpackPlugin = require('html-webpack-plugin'); // 通过 npm 安装
142+
const HtmlWebpackPlugin = require('html-webpack-plugin');
143143
const webpack = require('webpack'); // 用于访问内置插件
144144

145145
module.exports = {

src/content/concepts/loaders.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ module.exports = {
5353
- [配置方式](#configuration)(推荐):在 **webpack.config.js** 文件中指定 loader。
5454
- [内联方式](#inline):在每个 `import` 语句中显式指定 loader。
5555

56-
### 配置方式 $#configuration$
56+
注意在 webpack v4 版本可以通过 CLI 使用 loader,但是在 webpack v5 中被弃用。
57+
58+
### Configuration $#configuration$
5759

5860
[`module.rules`](/configuration/module/#modulerules) 允许你在 webpack 配置中指定多个 loader。
5961
这种方式是展示 loader 的一种简明方式,并且有助于使代码变得简洁和易于维护。同时让你对各个 loader 有个全局概览:

src/content/concepts/plugins.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ compiler hook 的 tap 方法的第一个参数,应该是驼峰式命名的插
5555
**webpack.config.js**
5656

5757
```javascript
58-
const HtmlWebpackPlugin = require('html-webpack-plugin'); // 通过 npm 安装
58+
const HtmlWebpackPlugin = require('html-webpack-plugin');
5959
const webpack = require('webpack'); // 访问内置的插件
6060
const path = require('path');
6161

src/content/configuration/dev-server.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ module.exports = {
11201120

11211121
## devServer.open $#devserveropen$
11221122

1123-
`boolean` `string` `[string]` `object` `[object]`
1123+
`boolean` `string` `object` `[string, object]`
11241124

11251125
告诉 dev-server 在服务器已经启动后打开浏览器。设置其为 `true` 以打开你的默认浏览器。
11261126

@@ -1615,7 +1615,7 @@ module.exports = {
16151615

16161616
## devServer.static $#devserverstatic$
16171617

1618-
`boolean` `string` `[string]` `object` `[object]`
1618+
`boolean` `string` `object` `[string, object]`
16191619

16201620
该配置项允许配置从目录提供静态文件的选项(默认是 'public' 文件夹)。将其设置为 `false` 以禁用:
16211621

@@ -1885,7 +1885,7 @@ module.exports = {
18851885

18861886
## devServer.watchFiles $#devserverwatchfiles$
18871887

1888-
`string` `[string]` `object` `[object]`
1888+
`string` `object` `[string, object]`
18891889

18901890
该配置项允许你配置 globs/directories/files 来监听文件变化。例如:
18911891

src/content/configuration/externals.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ translators:
2626

2727
## externals $#externals$
2828

29-
`string` `[string]` `object` `function` `RegExp`
29+
`string` `object` `function` `RegExp` `[string, object, function, RegExp]`
3030

3131
**防止**将某些 `import` 的包(package)**打包**到 bundle 中,而是在运行时(runtime)再去从外部获取这些*扩展依赖(external dependencies)*
3232

src/content/configuration/output.mdx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ module.exports = {
681681

682682
`string = 'hex'`
683683

684-
在生成 hash 时使用的编码方式。支持 Node.js [`hash.digest`](https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding) 的所有编码。对文件名使用 `'base64'`,可能会出现问题,因为 base64 字母表中具有 `/` 这个字符(character)。同样的,`'latin1'` 规定可以含有任何字符(character)。
684+
在生成 hash 时使用的编码方式。支持 Node.js [`hash.digest`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings) 的所有编码。对文件名使用 `'base64'`,可能会出现问题,因为 base64 字母表中具有 `/` 这个字符(character)。同样的,`'latin1'` 规定可以含有任何字符(character)。
685685

686686
## output.hashDigestLength $#outputhashdigestlength$
687687

@@ -970,7 +970,9 @@ MyLibrary = _entry_return_;
970970

971971
请注意,如果 `MyLibrary` 没有在你的库之前定义,那么它将会被设置在全局作用域。
972972

973-
##### type: 'assign-properties' <Badge text='5.16.0+' /> $#typeassignproperties$
973+
##### type: 'assign-properties' $#typeassignproperties$
974+
975+
<Badge text="5.16.0+" />
974976

975977
```js
976978
module.exports = {
@@ -1151,7 +1153,7 @@ T> 在考虑 CommonJS 与 CommonJS2 之间的区别?虽然它们很相似,
11511153

11521154
##### type: 'commonjs-static' $#type-commonjsstatic$
11531155

1154-
<Badge text='5.66.0+' />
1156+
<Badge text="5.66.0+" />
11551157

11561158
```js
11571159
module.exports = {
@@ -1620,7 +1622,9 @@ MyLibrary = _entry_return_;
16201622

16211623
注意,如果 `MyLibrary` 在作用域中未在前面代码进行定义,则你的 library 将被设置在全局作用域内。
16221624

1623-
#### libraryTarget: 'assign-properties' <Badge text='5.16.0+' /> $#libraryTarget-assign-properties$
1625+
#### libraryTarget: 'assign-properties' $#libraryTarget-assign-properties$
1626+
1627+
<Badge text="5.16.0+" />
16241628

16251629
W> 最好使用 [output.library.type: 'assign-properties'`](#type-assign-properties)。
16261630

0 commit comments

Comments
 (0)