You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
对所有或某些模块启用「行到行映射(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)相匹配时才使用。
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:
If multiple modules would result in the same name, [`output.devtoolFallbackModuleFilenameTemplate`](#output-devtoolfallbackmodulefilenametemplate)is used instead for these modules.
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...
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.
Copy file name to clipboardExpand all lines: generated/plugins/commons-chunk-plugin.md
+72-10Lines changed: 72 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,53 @@
1
1
---
2
2
title: commons-chunk-plugin
3
+
contributors:
4
+
- bebraw
5
+
- simon04
3
6
---
4
7
5
-
?> Review this content
6
-
7
8
```javascript
8
9
newwebpack.optimize.CommonsChunkPlugin(options)
9
10
```
10
11
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`).
// 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 `newwebpack.optimize.CommonsChunkPlugin(options, filenameTemplate, selectedChunks, minChunks)` is no longer supported. Use a corresponding options object instead.
18
51
19
52
## Examples
20
53
@@ -92,7 +125,7 @@ new CommonsChunkPlugin({
92
125
93
126
### Extra async commons chunk
94
127
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.
96
129
97
130
```javascript
98
131
newCommonsChunkPlugin({
@@ -109,3 +142,32 @@ new CommonsChunkPlugin({
109
142
// (3 children must share the module before it's separated)
110
143
})
111
144
```
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.
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
+
newwebpack.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:
0 commit comments