Skip to content

Commit c34c95e

Browse files
Merge pull request webpack#88 from dear-lizhihua/cn
cn
2 parents 43bb1b9 + 323afd8 commit c34c95e

File tree

8 files changed

+295
-45
lines changed

8 files changed

+295
-45
lines changed

content/concepts/output.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ module.exports = config;
124124
125125
### `output.hotUpdateFunction`
126126

127-
webpack 用于异步加载(async loading)热更新块(hot update chunk)的 JSONP 函数。
127+
webpack 用于异步加载(async load)热更新(hot update) chunk 的 JSONP 函数。
128128

129129
> 默认值:`"webpackHotUpdate"`
130130

content/configuration/output.md

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ contributors:
77
- tomasAlabes
88
---
99

10-
位于对象最顶级 `output` 键,包括了一组选项,指示 webpack 如何去输出、以及在哪里输出你的「bundles、assets 和和其他你所打包或使用 webpack 载入的任何内容」。
10+
位于对象最顶级 `output` 键,包括了一组选项,指示 webpack 如何去输出、以及在哪里输出你的「bundle、asset 和其他你所打包或使用 webpack 载入的任何内容」。
1111

1212

1313
## `output.chunkFilename`
@@ -51,7 +51,7 @@ contributors:
5151

5252
(弃用:无用,不可用,如果你有其他意见请写 issue 给我们)
5353

54-
对所有或某些模块启用「行到行映射(line to line mapping)」。这将生成基本的资源映射(source map),即生成资源(generated source)的每一行,映射到原始资源(original source)的同一行。这是一个性能优化点,并且应该只需要输入行(input line)和生成行(generated line)相匹配时才使用。
54+
对所有或某些模块启用「行到行映射(line to line mapping)」。这将生成基本的源映射(source map),即生成资源(generated source)的每一行,映射到原始资源(original source)的同一行。这是一个性能优化点,并且应该只需要输入行(input line)和生成行(generated line)相匹配时才使用。
5555

5656
传入 boolean 值,对所有模块启用或禁用此功能(默认 `false`)。对象可有 `test`, `include`, `exclude` 三种属性。例如,对某个特定目录中所有 javascript 文件启用此功能:
5757

@@ -64,136 +64,139 @@ devtoolLineToLine: { test: /\.js$/, include: 'src/utilities' }
6464

6565
`string | function(info)`
6666

67-
This option is only used when [`devtool`](/configuration/devtool) uses an options which requires module names.
67+
此选项仅在 「[`devtool`](/configuration/devtool) 使用了需要模块名称的选项」时使用。
6868

69-
Customize the names used in each source map's `sources` array. This can be done by passing a template string or function. For example, when using `devtool: 'eval'`, this is the default:
69+
自定义每个 source map`sources` 数组中使用的名称。可以通过传递模板字符串(template string)或者函数来完成。例如,当使用 `devtool: 'eval'`,默认值是:
7070

7171
``` js
7272
devtoolModuleFilenameTemplate: "webpack:///[resource-path]?[loaders]"
7373
```
7474

75-
The following substitutions are available in template strings:
75+
模板字符串(template string)中做以下替换:
7676

7777
``` js
78-
[absolute-resource-path] // The absolute filename
7978
[all-loaders] // Automatic and explicit loaders and params up to the name of the first loader
80-
[hash] // The hash of the module identifier
81-
[id] // The module identifier
8279
[loaders] // Explicit loaders and params up to the name of the first loader
8380
[resource] // The path used to resolve the file and any query params used on the first loader
8481
[resource-path] // Same as above without the query params
82+
[absolute-resource-path] // 绝对路径文件名
83+
[all-loaders] // 自动和显式的 loader,以及第一个 loader 名称的参数
84+
[hash] // 模块标识符的 hash
85+
[id] // 模块标识符
86+
[loaders] // 显式的 loader,以及第一个 loader 名称的参数
87+
[resource] // 用于解析文件的路径和用于第一个 loader 的任意查询参数
8588
```
8689

87-
When using a function, the same options are available camel-cased via the `info` parameter:
90+
当使用一个函数,同样的选项要通过 `info` 参数并使用驼峰式(camel-cased):
8891

8992
``` js
9093
devtoolModuleFilenameTemplate: info => {
9194
return `webpack:///${info.resourcePath}?${info.loaders}`
9295
}
9396
```
9497

95-
If multiple modules would result in the same name, [`output.devtoolFallbackModuleFilenameTemplate`](#output-devtoolfallbackmodulefilenametemplate) is used instead for these modules.
98+
如果多个模块产生相同的名称,使用 [`output.devtoolFallbackModuleFilenameTemplate`](#output-devtoolfallbackmodulefilenametemplate) 来代替这些模块。
9699

97100

98101
## `output.filename`
99102

100103
`string`
101104

102-
This option determines the name of each output bundle. The bundle is written to the directory specified by the [`output.path`](#output-path) option.
105+
此选项决定了每个输出 bundle 的名称。这些 bundle 将写入到 [`output.path`](#output-path) 选项指定的目录下。
103106

104-
For a single [`entry`](/configuration/entry-context#entry) point, this can be a static name.
107+
对于单个[`入口`](/configuration/entry-context#entry)起点,filename 会是一个静态名称。
105108

106109
``` js
107110
filename: "bundle.js"
108111
```
109112

110-
However, when creating multiple bundles via more than one entry point, code splitting, or various plugins, you should use one of the following substitutions to give each bundle a unique name...
113+
然而,当通过多个入口起点(entry point)、代码拆分(code splitting)或各种插件(plugin)创建多个 bundle,应该使用以下一种替换方式,来赋予每个 bundle 一个唯一的名称……
111114

112-
Using entry name:
115+
使用入口名称:
113116

114117
``` js
115118
filename: "[name].bundle.js"
116119
```
117120

118-
Using internal chunk id:
121+
使用内部 chunk id
119122

120123
``` js
121124
filename: "[id].bundle.js"
122125
```
123126

124-
Using the unique hash generated for every build:
127+
使用每次构建过程中,唯一的 hash 生成
125128

126129
``` js
127130
filename: "[name].[hash].bundle.js"
128131
```
129132

130-
Using hashes based on each chunks' content:
133+
使用基于每个 chunk 内容的 hash:
131134

132135
``` js
133136
filename: "[chunkhash].bundle.js"
134137
```
135138

136-
Make sure the read the [Caching guide](/guides/caching) for details. There are more steps involved than just setting this option.
139+
请确保已阅读过[指南 - 缓存](/guides/caching)的详细信息。这里涉及更多步骤,不仅仅是设置此选项。
137140

138-
The default value is `"[name].js"`.
141+
默认值是 `"[name].js"`
139142

140-
Note this option is called filename but you are still allowed to something like `"js/[name]/bundle.js"` to create a folder structure.
143+
注意此选项被称为文件名,但是你还是可以创建像 `"js/[name]/bundle.js"` 这样的文件夹结构。
141144

142-
Note this options does not affect output files for on-demand-loaded chunks. For these files the [`output.chunkFilename`](#output-chunkfilename) option is used. It also doesn't affect files created by loaders. For these files see loader options.
145+
注意,此选项不会影响那些「按需加载 chunk」的输出文件。对于这些文件,请使用 [`output.chunkFilename`](#output-chunkfilename) 选项来控制输出。同样也不影响通过 loader 创建的文件,对于这些文件,请查看 loader 选项来输出控制。
143146

144147

145148
## `output.hotUpdateChunkFilename`
146149

147150
`string`
148151

149-
Customize the filenames of hot update chunks. See [`output.filename`](#output-filename) option for details on the possible values.
152+
自定义热更新 chunk 的文件名。可选的值的详细信息,请查看 [`output.filename`](#output-filename) 选项。
150153

151-
The only placeholders allowed here are `[id]` and `[hash]`, the default being:
154+
占位符只能是 `[id]` `[hash]`,默认值是:
152155

153156
``` js
154157
hotUpdateChunkFilename: "[id].[hash].hot-update.js"
155158
```
156159

157-
Here is no need to change it.
160+
这里没有必要修改它。
158161

159162

160163
## `output.hotUpdateFunction`
161164

162165
`function`
163166

164-
Only used when [`target`](/configuration/target) is web, which uses JSONP for loading hot updates.
167+
只在 [`target`](/configuration/target) web 时使用,用于加载热更新(hot update)的 JSONP 函数。
165168

166-
A JSONP function used to asynchronously load hot-update chunks.
169+
JSONP 函数用于异步加载(async load)热更新(hot-update) chunk。
167170

168-
For details see [`output.jsonpFunction`](#output-jsonpfunction).
171+
详细请查看 [`output.jsonpFunction`](#output-jsonpfunction)
169172

170173

171174
## `output.hotUpdateMainFilename`
172175

173176
`string`
174177

175-
Customize the main hot update filename. See [`output.filename`](#output-filename) option for details on the possible values.
178+
自定义热更新的主文件名(main filename)。可选的值的详细信息,请查看 [`output.filename`](#output-filename) 选项
176179

177-
`[hash]` is the only available placeholder, the default being:
180+
占位符只能是 `[hash]`,默认值是:
178181

179182
``` js
180183
hotUpdateMainFilename: "[hash].hot-update.json"
181184
```
182185

183-
Here is no need to change it.
186+
这里没有必要修改它。
184187

185188

186189
## `output.jsonpFunction`
187190

188191
`function`
189192

190-
Only used when [`target`](/configuration/target) is web, which uses JSONP for loading on-demand chunks.
193+
只在 [`target`](/configuration/target) web 时使用,用于按需加载(load on-demand) chunk 的 JSONP 函数。
191194

192-
A JSONP function name used to asynchronously load chunks or join multiple initial chunks (CommonsChunkPlugin, AggressiveSplittingPlugin).
195+
JSONP 函数用于异步加载(async load) chunk,或者拼接多个初始 chunk(CommonsChunkPlugin, AggressiveSplittingPlugin)
193196

194-
This needs to be changed if multiple webpack runtimes (from different compilation) are used on the same webpage.
197+
如果在同一网页中使用了多个(来自不同编译(compilation)的)webpack runtime,则需要修改此选项。
195198

196-
If using the [`output.library`](#output-library) option, the library name is automatically appended.
199+
如果使用了 [`output.library`](#output-library) 选项,library 名称时自动追加的。
197200

198201

199202
## `output.library`

generated/plugins/commons-chunk-plugin.md

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,53 @@
11
---
22
title: commons-chunk-plugin
3+
contributors:
4+
- bebraw
5+
- simon04
36
---
47

5-
?> Review this content
6-
78
```javascript
89
new webpack.optimize.CommonsChunkPlugin(options)
910
```
1011

11-
* `options.name` or `options.names` (`string|string[]`): The chunk name of the commons chunk. An existing chunk can be selected by passing a name of an existing chunk. If an array of strings is passed this is equal to invoking the plugin multiple times for each chunk name. If omitted and `options.async` or `options.children` is set all chunks are used, otherwise `options.filename` is used as chunk name.
12-
* `options.filename` (`string`): The filename template for the commons chunk. Can contain the same placeholder as `output.filename`. If omitted the original filename is not modified (usually `output.filename` or `output.chunkFilename`).
13-
* `options.minChunks` (`number|Infinity|function(module, count) -> boolean`): The minimum number of chunks which need to contain a module before it's moved into the commons chunk. The number must be greater than or equal 2 and lower than or equal to the number of chunks. Passing `Infinity` just creates the commons chunk, but moves no modules into it. By providing a `function` you can add custom logic. (Defaults to the number of chunks)
14-
* `options.chunks` (`string[]`): Select the source chunks by chunk names. The chunk must be a child of the commons chunk. If omitted all entry chunks are selected.
15-
* `options.children` (`boolean`): If `true` all children of the commons chunk are selected
16-
* `options.async` (`boolean|string`): If `true` a new async commons chunk is created as child of `options.name` and sibling of `options.chunks`. It is loaded in parallel with `options.chunks`. It is possible to change the name of the output file by providing the desired string instead of `true`.
17-
* `options.minSize` (`number`): Minimum size of all common module before a commons chunk is created.
12+
## Options
13+
14+
```javascript
15+
{
16+
name: string, // or
17+
names: string[],
18+
// The chunk name of the commons chunk. An existing chunk can be selected by passing a name of an existing chunk.
19+
// If an array of strings is passed this is equal to invoking the plugin multiple times for each chunk name.
20+
// If omitted and `options.async` or `options.children` is set all chunks are used,
21+
// otherwise `options.filename` is used as chunk name.
22+
23+
filename: string,
24+
// The filename template for the commons chunk. Can contain the same placeholder as `output.filename`.
25+
// If omitted the original filename is not modified (usually `output.filename` or `output.chunkFilename`).
26+
27+
minChunks: number|Infinity|function(module, count) -> boolean,
28+
// The minimum number of chunks which need to contain a module before it's moved into the commons chunk.
29+
// The number must be greater than or equal 2 and lower than or equal to the number of chunks.
30+
// Passing `Infinity` just creates the commons chunk, but moves no modules into it.
31+
// By providing a `function` you can add custom logic. (Defaults to the number of chunks)
32+
33+
chunks: string[],
34+
// Select the source chunks by chunk names. The chunk must be a child of the commons chunk.
35+
// If omitted all entry chunks are selected.
36+
37+
children: boolean,
38+
// If `true` all children of the commons chunk are selected
39+
40+
async: boolean|string,
41+
// If `true` a new async commons chunk is created as child of `options.name` and sibling of `options.chunks`.
42+
// It is loaded in parallel with `options.chunks`. It is possible to change the name of the output file
43+
// by providing the desired string instead of `true`.
44+
45+
minSize: number,
46+
// Minimum size of all common module before a commons chunk is created.
47+
}
48+
```
49+
50+
T> The deprecated webpack 1 constructor `new webpack.optimize.CommonsChunkPlugin(options, filenameTemplate, selectedChunks, minChunks)` is no longer supported. Use a corresponding options object instead.
1851
1952
## Examples
2053
@@ -92,7 +125,7 @@ new CommonsChunkPlugin({
92125
93126
### Extra async commons chunk
94127
95-
Similar to 3., but instead of moving common modules into the parent (which increases initial load time) a new async-loaded additional commons chunk is used. This is automatically downloaded in parallel when the additional chunk is downloaded.
128+
Similar to the above one, but instead of moving common modules into the parent (which increases initial load time) a new async-loaded additional commons chunk is used. This is automatically downloaded in parallel when the additional chunk is downloaded.
96129
97130
```javascript
98131
new CommonsChunkPlugin({
@@ -109,3 +142,32 @@ new CommonsChunkPlugin({
109142
// (3 children must share the module before it's separated)
110143
})
111144
```
145+
146+
### Passing the `minChunks` property a function
147+
148+
You also have the ability to pass the `minChunks` property a function. This function is called by the `CommonsChunkPlugin` and calls the function with `module` and `count` arguments.
149+
150+
The `module` property represents each module in the chunks you have provided via the `names` property.
151+
152+
The `count` property represents how many chunks the `module` is used in.
153+
154+
This option is useful when you want to have fine-grained control over how the CommonsChunk algorithm determins where modules should be moved to.
155+
156+
```javascript
157+
new CommonsChunkPlugin({
158+
name: "my-single-lib-chunk",
159+
filename: "my-single-lib-chunk.js",
160+
minChunks: function(module, countOfHowManyTimesThisModuleIsUsedAcrossAllChunks) {
161+
// If module has a path, and inside of the path exists the name "somelib",
162+
// and it is used in 3 separate chunks/entries, then break it out into
163+
// a separate chunk with chunk keyname "my-single-lib-chunk", and filename "my-single-lib-chunk.js"
164+
return module.resource && (/somelib/).test(module.resource) && count === 3;
165+
}
166+
});
167+
```
168+
169+
As seen above, this example allows you to move only one lib to a separate file if and only if all conditions are met inside the function.
170+
171+
***
172+
173+
> 原文:https://webpack.js.org/loaders/

generated/plugins/define-plugin.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: define-plugin
3+
---
4+
5+
``` javascript
6+
new webpack.DefinePlugin(definitions)
7+
```
8+
9+
The `DefinePlugin` allows you to create global constants which can be configured at **compile** time. This can be useful for allowing different behaviour between development builds and release builds. For example, you might use a global constant to determine whether logging takes place; perhaps you perform logging in your development build but not in the release build. That's the sort of scenario the `DefinePlugin` facilitates.
10+
11+
**Example:**
12+
13+
``` javascript
14+
new webpack.DefinePlugin({
15+
PRODUCTION: JSON.stringify(true),
16+
VERSION: JSON.stringify("5fa3b9"),
17+
BROWSER_SUPPORTS_HTML5: true,
18+
TWO: "1+1",
19+
"typeof window": JSON.stringify("object")
20+
})
21+
```
22+
23+
``` javascript
24+
console.log("Running App version " + VERSION);
25+
if(!BROWSER_SUPPORTS_HTML5) require("html5shiv");
26+
```
27+
28+
T> Note that because the plugin does a direct text replacement, the value given to it must include actual quotes inside of the string itself. Typically, this is done either with alternate quotes, such as `'"production"'`, or by using `JSON.stringify('production')`.
29+
30+
Each key passed into `DefinePlugin` is an identifier or multiple identifiers joined with `.`.
31+
32+
* If the value is a string it will be used as a code fragment.
33+
* If the value isn't a string, it will be stringified (including functions).
34+
* If the value is an object all keys are defined the same way.
35+
* If you prefix `typeof` to the key, it's only defined for typeof calls.
36+
37+
The values will be inlined into the code which allows a minification pass to remove the redundant conditional.
38+
39+
**Example:**
40+
41+
``` javascript
42+
if (!PRODUCTION) {
43+
console.log('Debug info')
44+
}
45+
if (PRODUCTION) {
46+
console.log('Production log')
47+
}
48+
`````
49+
After passing through webpack with no minification results in:
50+
51+
``` javascript
52+
if (!true) {
53+
console.log('Debug info')
54+
}
55+
if (true) {
56+
console.log('Production log')
57+
}
58+
```
59+
60+
and then after a minification pass results in:
61+
62+
``` javascript
63+
console.log('Production log')
64+
```
65+
66+
***
67+
68+
> 原文:https://webpack.js.org/loaders/

generated/plugins/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ title: Plugin
33
---
44

55
?> TODO
6+
7+
***
8+
9+
> 原文:https://webpack.js.org/loaders/

0 commit comments

Comments
 (0)