webpack 4.8.2 → 4.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -52
- package/bin/webpack.js +128 -43
- package/lib/AmdMainTemplatePlugin.js +10 -0
- package/lib/AsyncDependencyToInitialChunkError.js +12 -2
- package/lib/BannerPlugin.js +115 -101
- package/lib/CaseSensitiveModulesWarning.js +20 -2
- package/lib/Chunk.js +1 -0
- package/lib/ChunkGroup.js +465 -465
- package/lib/ChunkRenderError.js +8 -0
- package/lib/ChunkTemplate.js +71 -71
- package/lib/Compilation.js +1 -1
- package/lib/Compiler.js +2 -1
- package/lib/ContextModule.js +8 -8
- package/lib/DllPlugin.js +3 -1
- package/lib/DllReferencePlugin.js +2 -1
- package/lib/Entrypoint.js +54 -54
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +115 -115
- package/lib/ExportPropertyMainTemplatePlugin.js +13 -0
- package/lib/Generator.js +52 -52
- package/lib/HotModuleReplacement.runtime.js +633 -633
- package/lib/JsonParser.js +2 -1
- package/lib/LibManifestPlugin.js +9 -0
- package/lib/LibraryTemplatePlugin.js +66 -33
- package/lib/MainTemplate.js +468 -468
- package/lib/Module.js +3 -3
- package/lib/ModuleDependencyError.js +12 -2
- package/lib/NormalModuleFactory.js +5 -3
- package/lib/Parser.js +27 -23
- package/lib/ProgressPlugin.js +1 -1
- package/lib/RecordIdsPlugin.js +3 -1
- package/lib/RuntimeTemplate.js +1 -1
- package/lib/SetVarMainTemplatePlugin.js +12 -0
- package/lib/SourceMapDevToolPlugin.js +11 -13
- package/lib/Template.js +289 -290
- package/lib/UmdMainTemplatePlugin.js +67 -32
- package/lib/WebpackError.js +8 -2
- package/lib/compareLocations.js +20 -0
- package/lib/debug/ProfilingPlugin.js +416 -416
- package/lib/dependencies/ContextDependencyHelpers.js +142 -142
- package/lib/dependencies/WebpackMissingModule.js +2 -2
- package/lib/optimize/RemoveEmptyChunksPlugin.js +42 -40
- package/lib/optimize/RuntimeChunkPlugin.js +9 -5
- package/lib/optimize/SplitChunksPlugin.js +195 -124
- package/lib/util/Queue.js +46 -46
- package/lib/util/SetHelpers.js +48 -48
- package/lib/util/SortableSet.js +106 -106
- package/lib/util/StackedSetMap.js +128 -128
- package/lib/util/cachedMerge.js +13 -0
- package/lib/util/identifier.js +5 -0
- package/lib/util/objectToMap.js +16 -16
- package/lib/wasm/WebAssemblyGenerator.js +280 -280
- package/lib/wasm/WebAssemblyParser.js +79 -79
- package/lib/web/JsonpMainTemplatePlugin.js +2 -2
- package/package.json +21 -17
- package/schemas/WebpackOptions.json +12 -1
- package/schemas/plugins/BannerPlugin.json +96 -85
- package/schemas/plugins/DllPlugin.json +4 -0
package/lib/JsonParser.js
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
const parseJson = require("json-parse-better-errors");
|
7
8
|
const JsonExportsDependency = require("./dependencies/JsonExportsDependency");
|
8
9
|
|
9
10
|
class JsonParser {
|
@@ -12,7 +13,7 @@ class JsonParser {
|
|
12
13
|
}
|
13
14
|
|
14
15
|
parse(source, state) {
|
15
|
-
const data =
|
16
|
+
const data = parseJson(source[0] === "\ufeff" ? source.slice(1) : source);
|
16
17
|
state.module.buildInfo.jsonData = data;
|
17
18
|
state.module.buildMeta.exportsType = "named";
|
18
19
|
if (typeof data === "object" && data)
|
package/lib/LibManifestPlugin.js
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
|
7
7
|
const path = require("path");
|
8
8
|
const asyncLib = require("neo-async");
|
9
|
+
const SingleEntryDependency = require("./dependencies/SingleEntryDependency");
|
9
10
|
|
10
11
|
class LibManifestPlugin {
|
11
12
|
constructor(options) {
|
@@ -37,6 +38,14 @@ class LibManifestPlugin {
|
|
37
38
|
name,
|
38
39
|
type: this.options.type,
|
39
40
|
content: Array.from(chunk.modulesIterable, module => {
|
41
|
+
if (
|
42
|
+
this.options.entryOnly &&
|
43
|
+
!module.reasons.some(
|
44
|
+
r => r.dependency instanceof SingleEntryDependency
|
45
|
+
)
|
46
|
+
) {
|
47
|
+
return;
|
48
|
+
}
|
40
49
|
if (module.libIdent) {
|
41
50
|
const ident = module.libIdent({
|
42
51
|
context: this.options.context || compiler.options.context
|
@@ -6,30 +6,45 @@
|
|
6
6
|
|
7
7
|
const SetVarMainTemplatePlugin = require("./SetVarMainTemplatePlugin");
|
8
8
|
|
9
|
+
/** @typedef {import("./Compiler")} Compiler */
|
10
|
+
|
11
|
+
/**
|
12
|
+
* @param {string[]} accessor the accessor to convert to path
|
13
|
+
* @returns {string} the path
|
14
|
+
*/
|
9
15
|
const accessorToObjectAccess = accessor => {
|
10
|
-
return accessor
|
11
|
-
.map(a => {
|
12
|
-
return `[${JSON.stringify(a)}]`;
|
13
|
-
})
|
14
|
-
.join("");
|
16
|
+
return accessor.map(a => `[${JSON.stringify(a)}]`).join("");
|
15
17
|
};
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
/**
|
20
|
+
* @param {string=} base the path prefix
|
21
|
+
* @param {string|string[]} accessor the accessor
|
22
|
+
* @param {string=} joinWith the element separator
|
23
|
+
* @returns {string} the path
|
24
|
+
*/
|
25
|
+
const accessorAccess = (base, accessor, joinWith = "; ") => {
|
26
|
+
const accessors = Array.isArray(accessor) ? accessor : [accessor];
|
27
|
+
return accessors
|
28
|
+
.map((_, idx) => {
|
29
|
+
const a = base
|
30
|
+
? base + accessorToObjectAccess(accessors.slice(0, idx + 1))
|
31
|
+
: accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1));
|
32
|
+
if (idx === accessors.length - 1) return a;
|
25
33
|
if (idx === 0 && typeof base === "undefined")
|
26
34
|
return `${a} = typeof ${a} === "object" ? ${a} : {}`;
|
27
35
|
return `${a} = ${a} || {}`;
|
28
36
|
})
|
29
|
-
.join(joinWith
|
37
|
+
.join(joinWith);
|
30
38
|
};
|
31
39
|
|
32
40
|
class LibraryTemplatePlugin {
|
41
|
+
/**
|
42
|
+
* @param {string} name name of library
|
43
|
+
* @param {string} target type of library
|
44
|
+
* @param {boolean} umdNamedDefine setting this to true will name the UMD module
|
45
|
+
* @param {string|TODO} auxiliaryComment comment in the UMD wrapper
|
46
|
+
* @param {string|string[]} exportProperty which export should be exposed as library
|
47
|
+
*/
|
33
48
|
constructor(name, target, umdNamedDefine, auxiliaryComment, exportProperty) {
|
34
49
|
this.name = name;
|
35
50
|
this.target = target;
|
@@ -38,10 +53,14 @@ class LibraryTemplatePlugin {
|
|
38
53
|
this.exportProperty = exportProperty;
|
39
54
|
}
|
40
55
|
|
56
|
+
/**
|
57
|
+
* @param {Compiler} compiler the compiler instance
|
58
|
+
* @returns {void}
|
59
|
+
*/
|
41
60
|
apply(compiler) {
|
42
61
|
compiler.hooks.thisCompilation.tap("LibraryTemplatePlugin", compilation => {
|
43
62
|
if (this.exportProperty) {
|
44
|
-
|
63
|
+
const ExportPropertyMainTemplatePlugin = require("./ExportPropertyMainTemplatePlugin");
|
45
64
|
new ExportPropertyMainTemplatePlugin(this.exportProperty).apply(
|
46
65
|
compilation
|
47
66
|
);
|
@@ -49,66 +68,80 @@ class LibraryTemplatePlugin {
|
|
49
68
|
switch (this.target) {
|
50
69
|
case "var":
|
51
70
|
new SetVarMainTemplatePlugin(
|
52
|
-
`var ${accessorAccess(
|
71
|
+
`var ${accessorAccess(undefined, this.name)}`,
|
72
|
+
false
|
53
73
|
).apply(compilation);
|
54
74
|
break;
|
55
75
|
case "assign":
|
56
76
|
new SetVarMainTemplatePlugin(
|
57
|
-
accessorAccess(undefined, this.name)
|
77
|
+
accessorAccess(undefined, this.name),
|
78
|
+
false
|
58
79
|
).apply(compilation);
|
59
80
|
break;
|
60
81
|
case "this":
|
61
82
|
case "self":
|
62
83
|
case "window":
|
63
|
-
if (this.name)
|
84
|
+
if (this.name) {
|
64
85
|
new SetVarMainTemplatePlugin(
|
65
|
-
accessorAccess(this.target, this.name)
|
86
|
+
accessorAccess(this.target, this.name),
|
87
|
+
false
|
66
88
|
).apply(compilation);
|
67
|
-
else
|
89
|
+
} else {
|
68
90
|
new SetVarMainTemplatePlugin(this.target, true).apply(compilation);
|
91
|
+
}
|
69
92
|
break;
|
70
93
|
case "global":
|
71
|
-
if (this.name)
|
94
|
+
if (this.name) {
|
72
95
|
new SetVarMainTemplatePlugin(
|
73
96
|
accessorAccess(
|
74
97
|
compilation.runtimeTemplate.outputOptions.globalObject,
|
75
98
|
this.name
|
76
|
-
)
|
99
|
+
),
|
100
|
+
false
|
77
101
|
).apply(compilation);
|
78
|
-
else
|
102
|
+
} else {
|
79
103
|
new SetVarMainTemplatePlugin(
|
80
104
|
compilation.runtimeTemplate.outputOptions.globalObject,
|
81
105
|
true
|
82
106
|
).apply(compilation);
|
107
|
+
}
|
83
108
|
break;
|
84
109
|
case "commonjs":
|
85
|
-
if (this.name)
|
110
|
+
if (this.name) {
|
86
111
|
new SetVarMainTemplatePlugin(
|
87
|
-
accessorAccess("exports", this.name)
|
112
|
+
accessorAccess("exports", this.name),
|
113
|
+
false
|
88
114
|
).apply(compilation);
|
89
|
-
else
|
115
|
+
} else {
|
116
|
+
new SetVarMainTemplatePlugin("exports", true).apply(compilation);
|
117
|
+
}
|
90
118
|
break;
|
91
119
|
case "commonjs2":
|
92
120
|
case "commonjs-module":
|
93
|
-
new SetVarMainTemplatePlugin("module.exports").apply(
|
121
|
+
new SetVarMainTemplatePlugin("module.exports", false).apply(
|
122
|
+
compilation
|
123
|
+
);
|
94
124
|
break;
|
95
|
-
case "amd":
|
96
|
-
|
125
|
+
case "amd": {
|
126
|
+
const AmdMainTemplatePlugin = require("./AmdMainTemplatePlugin");
|
97
127
|
new AmdMainTemplatePlugin(this.name).apply(compilation);
|
98
128
|
break;
|
129
|
+
}
|
99
130
|
case "umd":
|
100
|
-
case "umd2":
|
101
|
-
|
131
|
+
case "umd2": {
|
132
|
+
const UmdMainTemplatePlugin = require("./UmdMainTemplatePlugin");
|
102
133
|
new UmdMainTemplatePlugin(this.name, {
|
103
134
|
optionalAmdExternalAsGlobal: this.target === "umd2",
|
104
135
|
namedDefine: this.umdNamedDefine,
|
105
136
|
auxiliaryComment: this.auxiliaryComment
|
106
137
|
}).apply(compilation);
|
107
138
|
break;
|
108
|
-
|
109
|
-
|
139
|
+
}
|
140
|
+
case "jsonp": {
|
141
|
+
const JsonpExportMainTemplatePlugin = require("./web/JsonpExportMainTemplatePlugin");
|
110
142
|
new JsonpExportMainTemplatePlugin(this.name).apply(compilation);
|
111
143
|
break;
|
144
|
+
}
|
112
145
|
default:
|
113
146
|
throw new Error(`${this.target} is not a valid Library target`);
|
114
147
|
}
|