webpack 5.68.0 → 5.70.0
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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/lib/BannerPlugin.js +10 -4
- package/lib/ChunkGraph.js +1 -2
- package/lib/CleanPlugin.js +64 -18
- package/lib/Compilation.js +43 -17
- package/lib/ContextModule.js +90 -26
- package/lib/ContextModuleFactory.js +65 -21
- package/lib/EntryOptionPlugin.js +1 -0
- package/lib/ExportsInfo.js +4 -4
- package/lib/Generator.js +1 -0
- package/lib/ModuleHashingError.js +29 -0
- package/lib/NodeStuffPlugin.js +10 -0
- package/lib/NormalModule.js +21 -16
- package/lib/NormalModuleFactory.js +40 -35
- package/lib/ProgressPlugin.js +4 -5
- package/lib/RuntimeTemplate.js +1 -0
- package/lib/TemplatedPathPlugin.js +48 -23
- package/lib/WebpackOptionsApply.js +2 -0
- package/lib/asset/AssetGenerator.js +122 -33
- package/lib/buildChunkGraph.js +1 -1
- package/lib/cache/ResolverCachePlugin.js +89 -28
- package/lib/config/browserslistTargetHandler.js +3 -5
- package/lib/config/defaults.js +7 -2
- package/lib/config/normalization.js +1 -0
- package/lib/css/CssLoadingRuntimeModule.js +63 -70
- package/lib/css/CssModulesPlugin.js +2 -1
- package/lib/debug/ProfilingPlugin.js +3 -4
- package/lib/dependencies/ContextDependencyHelpers.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +8 -2
- package/lib/dependencies/ExportsInfoDependency.js +6 -0
- package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
- package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
- package/lib/dependencies/ImportContextDependency.js +0 -2
- package/lib/dependencies/ImportMetaContextDependency.js +35 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
- package/lib/dependencies/LoaderPlugin.js +2 -0
- package/lib/dependencies/RequireContextDependency.js +0 -16
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +24 -8
- package/lib/index.js +5 -0
- package/lib/javascript/JavascriptModulesPlugin.js +27 -2
- package/lib/javascript/StartupHelpers.js +3 -2
- package/lib/library/AssignLibraryPlugin.js +8 -2
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -7
- package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -7
- package/lib/optimize/ConcatenatedModule.js +10 -4
- package/lib/schemes/HttpUriPlugin.js +68 -6
- package/lib/serialization/FileMiddleware.js +44 -9
- package/lib/util/compileBooleanMatcher.js +1 -1
- package/lib/util/deterministicGrouping.js +1 -1
- package/lib/util/identifier.js +65 -44
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/nonNumericOnlyHash.js +22 -0
- package/lib/util/semver.js +17 -10
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +15 -5
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -20
- package/module.d.ts +15 -0
- package/package.json +13 -13
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
- package/types.d.ts +203 -91
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
const makeSerializable = require("../util/makeSerializable");
|
9
9
|
const HarmonyImportDependency = require("./HarmonyImportDependency");
|
10
|
+
const NullDependency = require("./NullDependency");
|
10
11
|
|
11
12
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
12
13
|
/** @typedef {import("../Dependency")} Dependency */
|
@@ -28,8 +29,9 @@ makeSerializable(
|
|
28
29
|
"webpack/lib/dependencies/HarmonyAcceptImportDependency"
|
29
30
|
);
|
30
31
|
|
31
|
-
HarmonyAcceptImportDependency.Template =
|
32
|
-
HarmonyImportDependency.Template
|
33
|
-
|
32
|
+
HarmonyAcceptImportDependency.Template =
|
33
|
+
/** @type {typeof HarmonyImportDependency.Template} */ (
|
34
|
+
NullDependency.Template
|
35
|
+
);
|
34
36
|
|
35
37
|
module.exports = HarmonyAcceptImportDependency;
|
@@ -145,7 +145,10 @@ class HarmonyExportInitFragment extends InitFragment {
|
|
145
145
|
? `/* unused harmony export ${first(this.unusedExports)} */\n`
|
146
146
|
: "";
|
147
147
|
const definitions = [];
|
148
|
-
|
148
|
+
const orderedExportMap = Array.from(this.exportMap).sort(([a], [b]) =>
|
149
|
+
a < b ? -1 : 1
|
150
|
+
);
|
151
|
+
for (const [key, value] of orderedExportMap) {
|
149
152
|
definitions.push(
|
150
153
|
`\n/* harmony export */ ${JSON.stringify(
|
151
154
|
key
|
@@ -28,7 +28,6 @@ class ImportContextDependency extends ContextDependency {
|
|
28
28
|
serialize(context) {
|
29
29
|
const { write } = context;
|
30
30
|
|
31
|
-
write(this.range);
|
32
31
|
write(this.valueRange);
|
33
32
|
|
34
33
|
super.serialize(context);
|
@@ -37,7 +36,6 @@ class ImportContextDependency extends ContextDependency {
|
|
37
36
|
deserialize(context) {
|
38
37
|
const { read } = context;
|
39
38
|
|
40
|
-
this.range = read();
|
41
39
|
this.valueRange = read();
|
42
40
|
|
43
41
|
super.deserialize(context);
|
@@ -0,0 +1,35 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Ivan Kopeykin @vankop
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const makeSerializable = require("../util/makeSerializable");
|
9
|
+
const ContextDependency = require("./ContextDependency");
|
10
|
+
const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateAsRequireId");
|
11
|
+
|
12
|
+
class ImportMetaContextDependency extends ContextDependency {
|
13
|
+
constructor(options, range) {
|
14
|
+
super(options);
|
15
|
+
|
16
|
+
this.range = range;
|
17
|
+
}
|
18
|
+
|
19
|
+
get category() {
|
20
|
+
return "esm";
|
21
|
+
}
|
22
|
+
|
23
|
+
get type() {
|
24
|
+
return `import.meta.webpackContext ${this.options.mode}`;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
makeSerializable(
|
29
|
+
ImportMetaContextDependency,
|
30
|
+
"webpack/lib/dependencies/ImportMetaContextDependency"
|
31
|
+
);
|
32
|
+
|
33
|
+
ImportMetaContextDependency.Template = ModuleDependencyTemplateAsRequireId;
|
34
|
+
|
35
|
+
module.exports = ImportMetaContextDependency;
|
@@ -0,0 +1,252 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Ivan Kopeykin @vankop
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const WebpackError = require("../WebpackError");
|
9
|
+
const {
|
10
|
+
evaluateToIdentifier
|
11
|
+
} = require("../javascript/JavascriptParserHelpers");
|
12
|
+
const ImportMetaContextDependency = require("./ImportMetaContextDependency");
|
13
|
+
|
14
|
+
/** @typedef {import("estree").Expression} ExpressionNode */
|
15
|
+
/** @typedef {import("estree").ObjectExpression} ObjectExpressionNode */
|
16
|
+
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
17
|
+
/** @typedef {import("../ContextModule").ContextModuleOptions} ContextModuleOptions */
|
18
|
+
/** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
|
19
|
+
/** @typedef {Pick<ContextModuleOptions, 'mode'|'recursive'|'regExp'|'include'|'exclude'|'chunkName'>&{groupOptions: RawChunkGroupOptions, exports?: ContextModuleOptions["referencedExports"]}} ImportMetaContextOptions */
|
20
|
+
|
21
|
+
function createPropertyParseError(prop, expect) {
|
22
|
+
return createError(
|
23
|
+
`Parsing import.meta.webpackContext options failed. Unknown value for property ${JSON.stringify(
|
24
|
+
prop.key.name
|
25
|
+
)}, expected type ${expect}.`,
|
26
|
+
prop.value.loc
|
27
|
+
);
|
28
|
+
}
|
29
|
+
|
30
|
+
function createError(msg, loc) {
|
31
|
+
const error = new WebpackError(msg);
|
32
|
+
error.name = "ImportMetaContextError";
|
33
|
+
error.loc = loc;
|
34
|
+
return error;
|
35
|
+
}
|
36
|
+
|
37
|
+
module.exports = class ImportMetaContextDependencyParserPlugin {
|
38
|
+
apply(parser) {
|
39
|
+
parser.hooks.evaluateIdentifier
|
40
|
+
.for("import.meta.webpackContext")
|
41
|
+
.tap("HotModuleReplacementPlugin", expr => {
|
42
|
+
return evaluateToIdentifier(
|
43
|
+
"import.meta.webpackContext",
|
44
|
+
"import.meta",
|
45
|
+
() => ["webpackContext"],
|
46
|
+
true
|
47
|
+
)(expr);
|
48
|
+
});
|
49
|
+
parser.hooks.call
|
50
|
+
.for("import.meta.webpackContext")
|
51
|
+
.tap("ImportMetaContextDependencyParserPlugin", expr => {
|
52
|
+
if (expr.arguments.length < 1 || expr.arguments.length > 2) return;
|
53
|
+
const [directoryNode, optionsNode] = expr.arguments;
|
54
|
+
if (optionsNode && optionsNode.type !== "ObjectExpression") return;
|
55
|
+
const requestExpr = parser.evaluateExpression(directoryNode);
|
56
|
+
if (!requestExpr.isString()) return;
|
57
|
+
const request = requestExpr.string;
|
58
|
+
const errors = [];
|
59
|
+
let regExp = /^\.\/.*$/;
|
60
|
+
let recursive = true;
|
61
|
+
/** @type {ContextModuleOptions["mode"]} */
|
62
|
+
let mode = "sync";
|
63
|
+
/** @type {ContextModuleOptions["include"]} */
|
64
|
+
let include;
|
65
|
+
/** @type {ContextModuleOptions["exclude"]} */
|
66
|
+
let exclude;
|
67
|
+
/** @type {RawChunkGroupOptions} */
|
68
|
+
const groupOptions = {};
|
69
|
+
/** @type {ContextModuleOptions["chunkName"]} */
|
70
|
+
let chunkName;
|
71
|
+
/** @type {ContextModuleOptions["referencedExports"]} */
|
72
|
+
let exports;
|
73
|
+
if (optionsNode) {
|
74
|
+
for (const prop of optionsNode.properties) {
|
75
|
+
if (prop.type !== "Property" || prop.key.type !== "Identifier") {
|
76
|
+
errors.push(
|
77
|
+
createError(
|
78
|
+
"Parsing import.meta.webpackContext options failed.",
|
79
|
+
optionsNode.loc
|
80
|
+
)
|
81
|
+
);
|
82
|
+
break;
|
83
|
+
}
|
84
|
+
switch (prop.key.name) {
|
85
|
+
case "regExp": {
|
86
|
+
const regExpExpr = parser.evaluateExpression(
|
87
|
+
/** @type {ExpressionNode} */ (prop.value)
|
88
|
+
);
|
89
|
+
if (!regExpExpr.isRegExp()) {
|
90
|
+
errors.push(createPropertyParseError(prop, "RegExp"));
|
91
|
+
} else {
|
92
|
+
regExp = regExpExpr.regExp;
|
93
|
+
}
|
94
|
+
break;
|
95
|
+
}
|
96
|
+
case "include": {
|
97
|
+
const regExpExpr = parser.evaluateExpression(
|
98
|
+
/** @type {ExpressionNode} */ (prop.value)
|
99
|
+
);
|
100
|
+
if (!regExpExpr.isRegExp()) {
|
101
|
+
errors.push(createPropertyParseError(prop, "RegExp"));
|
102
|
+
} else {
|
103
|
+
include = regExpExpr.regExp;
|
104
|
+
}
|
105
|
+
break;
|
106
|
+
}
|
107
|
+
case "exclude": {
|
108
|
+
const regExpExpr = parser.evaluateExpression(
|
109
|
+
/** @type {ExpressionNode} */ (prop.value)
|
110
|
+
);
|
111
|
+
if (!regExpExpr.isRegExp()) {
|
112
|
+
errors.push(createPropertyParseError(prop, "RegExp"));
|
113
|
+
} else {
|
114
|
+
exclude = regExpExpr.regExp;
|
115
|
+
}
|
116
|
+
break;
|
117
|
+
}
|
118
|
+
case "mode": {
|
119
|
+
const modeExpr = parser.evaluateExpression(
|
120
|
+
/** @type {ExpressionNode} */ (prop.value)
|
121
|
+
);
|
122
|
+
if (!modeExpr.isString()) {
|
123
|
+
errors.push(createPropertyParseError(prop, "string"));
|
124
|
+
} else {
|
125
|
+
mode = /** @type {ContextModuleOptions["mode"]} */ (
|
126
|
+
modeExpr.string
|
127
|
+
);
|
128
|
+
}
|
129
|
+
break;
|
130
|
+
}
|
131
|
+
case "chunkName": {
|
132
|
+
const expr = parser.evaluateExpression(
|
133
|
+
/** @type {ExpressionNode} */ (prop.value)
|
134
|
+
);
|
135
|
+
if (!expr.isString()) {
|
136
|
+
errors.push(createPropertyParseError(prop, "string"));
|
137
|
+
} else {
|
138
|
+
chunkName = expr.string;
|
139
|
+
}
|
140
|
+
break;
|
141
|
+
}
|
142
|
+
case "exports": {
|
143
|
+
const expr = parser.evaluateExpression(
|
144
|
+
/** @type {ExpressionNode} */ (prop.value)
|
145
|
+
);
|
146
|
+
if (expr.isString()) {
|
147
|
+
exports = [[expr.string]];
|
148
|
+
} else if (expr.isArray()) {
|
149
|
+
const items = expr.items;
|
150
|
+
if (
|
151
|
+
items.every(i => {
|
152
|
+
if (!i.isArray()) return false;
|
153
|
+
const innerItems = i.items;
|
154
|
+
return innerItems.every(i => i.isString());
|
155
|
+
})
|
156
|
+
) {
|
157
|
+
exports = [];
|
158
|
+
for (const i1 of items) {
|
159
|
+
const export_ = [];
|
160
|
+
for (const i2 of i1.items) {
|
161
|
+
export_.push(i2.string);
|
162
|
+
}
|
163
|
+
exports.push(export_);
|
164
|
+
}
|
165
|
+
} else {
|
166
|
+
errors.push(
|
167
|
+
createPropertyParseError(prop, "string|string[][]")
|
168
|
+
);
|
169
|
+
}
|
170
|
+
} else {
|
171
|
+
errors.push(
|
172
|
+
createPropertyParseError(prop, "string|string[][]")
|
173
|
+
);
|
174
|
+
}
|
175
|
+
break;
|
176
|
+
}
|
177
|
+
case "prefetch": {
|
178
|
+
const expr = parser.evaluateExpression(
|
179
|
+
/** @type {ExpressionNode} */ (prop.value)
|
180
|
+
);
|
181
|
+
if (expr.isBoolean()) {
|
182
|
+
groupOptions.prefetchOrder = 0;
|
183
|
+
} else if (expr.isNumber()) {
|
184
|
+
groupOptions.prefetchOrder = expr.number;
|
185
|
+
} else {
|
186
|
+
errors.push(createPropertyParseError(prop, "boolean|number"));
|
187
|
+
}
|
188
|
+
break;
|
189
|
+
}
|
190
|
+
case "preload": {
|
191
|
+
const expr = parser.evaluateExpression(
|
192
|
+
/** @type {ExpressionNode} */ (prop.value)
|
193
|
+
);
|
194
|
+
if (expr.isBoolean()) {
|
195
|
+
groupOptions.preloadOrder = 0;
|
196
|
+
} else if (expr.isNumber()) {
|
197
|
+
groupOptions.preloadOrder = expr.number;
|
198
|
+
} else {
|
199
|
+
errors.push(createPropertyParseError(prop, "boolean|number"));
|
200
|
+
}
|
201
|
+
break;
|
202
|
+
}
|
203
|
+
case "recursive": {
|
204
|
+
const recursiveExpr = parser.evaluateExpression(
|
205
|
+
/** @type {ExpressionNode} */ (prop.value)
|
206
|
+
);
|
207
|
+
if (!recursiveExpr.isBoolean()) {
|
208
|
+
errors.push(createPropertyParseError(prop, "boolean"));
|
209
|
+
} else {
|
210
|
+
recursive = recursiveExpr.bool;
|
211
|
+
}
|
212
|
+
break;
|
213
|
+
}
|
214
|
+
default:
|
215
|
+
errors.push(
|
216
|
+
createError(
|
217
|
+
`Parsing import.meta.webpackContext options failed. Unknown property ${JSON.stringify(
|
218
|
+
prop.key.name
|
219
|
+
)}.`,
|
220
|
+
optionsNode.loc
|
221
|
+
)
|
222
|
+
);
|
223
|
+
}
|
224
|
+
}
|
225
|
+
}
|
226
|
+
if (errors.length) {
|
227
|
+
for (const error of errors) parser.state.current.addError(error);
|
228
|
+
return;
|
229
|
+
}
|
230
|
+
|
231
|
+
const dep = new ImportMetaContextDependency(
|
232
|
+
{
|
233
|
+
request,
|
234
|
+
include,
|
235
|
+
exclude,
|
236
|
+
recursive,
|
237
|
+
regExp,
|
238
|
+
groupOptions,
|
239
|
+
chunkName,
|
240
|
+
referencedExports: exports,
|
241
|
+
mode,
|
242
|
+
category: "esm"
|
243
|
+
},
|
244
|
+
expr.range
|
245
|
+
);
|
246
|
+
dep.loc = expr.loc;
|
247
|
+
dep.optional = !!parser.scope.inTry;
|
248
|
+
parser.state.current.addDependency(dep);
|
249
|
+
return true;
|
250
|
+
});
|
251
|
+
}
|
252
|
+
};
|
@@ -0,0 +1,59 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Ivan Kopeykin @vankop
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const ContextElementDependency = require("./ContextElementDependency");
|
9
|
+
const ImportMetaContextDependency = require("./ImportMetaContextDependency");
|
10
|
+
const ImportMetaContextDependencyParserPlugin = require("./ImportMetaContextDependencyParserPlugin");
|
11
|
+
|
12
|
+
/** @typedef {import("../../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
13
|
+
/** @typedef {import("../Compiler")} Compiler */
|
14
|
+
|
15
|
+
class ImportMetaContextPlugin {
|
16
|
+
/**
|
17
|
+
* Apply the plugin
|
18
|
+
* @param {Compiler} compiler the compiler instance
|
19
|
+
* @returns {void}
|
20
|
+
*/
|
21
|
+
apply(compiler) {
|
22
|
+
compiler.hooks.compilation.tap(
|
23
|
+
"RequireContextPlugin",
|
24
|
+
(compilation, { contextModuleFactory, normalModuleFactory }) => {
|
25
|
+
compilation.dependencyFactories.set(
|
26
|
+
ImportMetaContextDependency,
|
27
|
+
contextModuleFactory
|
28
|
+
);
|
29
|
+
compilation.dependencyTemplates.set(
|
30
|
+
ImportMetaContextDependency,
|
31
|
+
new ImportMetaContextDependency.Template()
|
32
|
+
);
|
33
|
+
compilation.dependencyFactories.set(
|
34
|
+
ContextElementDependency,
|
35
|
+
normalModuleFactory
|
36
|
+
);
|
37
|
+
|
38
|
+
const handler = (parser, parserOptions) => {
|
39
|
+
if (
|
40
|
+
parserOptions.importMetaContext !== undefined &&
|
41
|
+
!parserOptions.importMetaContext
|
42
|
+
)
|
43
|
+
return;
|
44
|
+
|
45
|
+
new ImportMetaContextDependencyParserPlugin().apply(parser);
|
46
|
+
};
|
47
|
+
|
48
|
+
normalModuleFactory.hooks.parser
|
49
|
+
.for("javascript/auto")
|
50
|
+
.tap("ImportMetaContextPlugin", handler);
|
51
|
+
normalModuleFactory.hooks.parser
|
52
|
+
.for("javascript/esm")
|
53
|
+
.tap("ImportMetaContextPlugin", handler);
|
54
|
+
}
|
55
|
+
);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
module.exports = ImportMetaContextPlugin;
|
@@ -32,6 +32,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
|
|
32
32
|
* @typedef {Object} ImportModuleOptions
|
33
33
|
* @property {string=} layer the target layer
|
34
34
|
* @property {string=} publicPath the target public path
|
35
|
+
* @property {string=} baseUri target base uri
|
35
36
|
*/
|
36
37
|
|
37
38
|
class LoaderPlugin {
|
@@ -199,6 +200,7 @@ class LoaderPlugin {
|
|
199
200
|
referencedModule,
|
200
201
|
{
|
201
202
|
entryOptions: {
|
203
|
+
baseUri: options.baseUri,
|
202
204
|
publicPath: options.publicPath
|
203
205
|
}
|
204
206
|
},
|
@@ -19,22 +19,6 @@ class RequireContextDependency extends ContextDependency {
|
|
19
19
|
get type() {
|
20
20
|
return "require.context";
|
21
21
|
}
|
22
|
-
|
23
|
-
serialize(context) {
|
24
|
-
const { write } = context;
|
25
|
-
|
26
|
-
write(this.range);
|
27
|
-
|
28
|
-
super.serialize(context);
|
29
|
-
}
|
30
|
-
|
31
|
-
deserialize(context) {
|
32
|
-
const { read } = context;
|
33
|
-
|
34
|
-
this.range = read();
|
35
|
-
|
36
|
-
super.deserialize(context);
|
37
|
-
}
|
38
22
|
}
|
39
23
|
|
40
24
|
makeSerializable(
|
@@ -55,15 +55,35 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
55
55
|
this._runtimeRequirements = runtimeRequirements;
|
56
56
|
}
|
57
57
|
|
58
|
+
/**
|
59
|
+
* @private
|
60
|
+
* @param {Chunk} chunk chunk
|
61
|
+
* @param {string} rootOutputDir root output directory
|
62
|
+
* @returns {string} generated code
|
63
|
+
*/
|
64
|
+
_generateBaseUri(chunk, rootOutputDir) {
|
65
|
+
const options = chunk.getEntryOptions();
|
66
|
+
if (options && options.baseUri) {
|
67
|
+
return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
|
68
|
+
}
|
69
|
+
const {
|
70
|
+
compilation: {
|
71
|
+
outputOptions: { importMetaName }
|
72
|
+
}
|
73
|
+
} = this;
|
74
|
+
return `${RuntimeGlobals.baseURI} = new URL(${JSON.stringify(
|
75
|
+
rootOutputDir
|
76
|
+
)}, ${importMetaName}.url);`;
|
77
|
+
}
|
78
|
+
|
58
79
|
/**
|
59
80
|
* @returns {string} runtime code
|
60
81
|
*/
|
61
82
|
generate() {
|
62
|
-
const { compilation, chunk } = this;
|
83
|
+
const { compilation, chunk, chunkGraph } = this;
|
63
84
|
const {
|
64
85
|
runtimeTemplate,
|
65
|
-
|
66
|
-
outputOptions: { importFunctionName, importMetaName }
|
86
|
+
outputOptions: { importFunctionName }
|
67
87
|
} = compilation;
|
68
88
|
const fn = RuntimeGlobals.ensureChunkHandlers;
|
69
89
|
const withBaseURI = this._runtimeRequirements.has(RuntimeGlobals.baseURI);
|
@@ -102,11 +122,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
102
122
|
|
103
123
|
return Template.asString([
|
104
124
|
withBaseURI
|
105
|
-
?
|
106
|
-
`${RuntimeGlobals.baseURI} = new URL(${JSON.stringify(
|
107
|
-
rootOutputDir
|
108
|
-
)}, ${importMetaName}.url);`
|
109
|
-
])
|
125
|
+
? this._generateBaseUri(chunk, rootOutputDir)
|
110
126
|
: "// no baseURI",
|
111
127
|
"",
|
112
128
|
"// object to store loaded and loading chunks",
|
package/lib/index.js
CHANGED
@@ -11,6 +11,7 @@ const memoize = require("./util/memoize");
|
|
11
11
|
/** @typedef {import("../declarations/WebpackOptions").Entry} Entry */
|
12
12
|
/** @typedef {import("../declarations/WebpackOptions").EntryNormalized} EntryNormalized */
|
13
13
|
/** @typedef {import("../declarations/WebpackOptions").EntryObject} EntryObject */
|
14
|
+
/** @typedef {import("../declarations/WebpackOptions").FileCacheOptions} FileCacheOptions */
|
14
15
|
/** @typedef {import("../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
|
15
16
|
/** @typedef {import("../declarations/WebpackOptions").ModuleOptions} ModuleOptions */
|
16
17
|
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
@@ -26,11 +27,15 @@ const memoize = require("./util/memoize");
|
|
26
27
|
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
|
27
28
|
/** @typedef {import("./Compilation").Asset} Asset */
|
28
29
|
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
30
|
+
/** @typedef {import("./Compilation").EntryOptions} EntryOptions */
|
31
|
+
/** @typedef {import("./Compiler").AssetEmittedInfo} AssetEmittedInfo */
|
29
32
|
/** @typedef {import("./MultiStats")} MultiStats */
|
30
33
|
/** @typedef {import("./Parser").ParserState} ParserState */
|
31
34
|
/** @typedef {import("./ResolverFactory").ResolvePluginInstance} ResolvePluginInstance */
|
32
35
|
/** @typedef {import("./ResolverFactory").Resolver} Resolver */
|
33
36
|
/** @typedef {import("./Watching")} Watching */
|
37
|
+
/** @typedef {import("./cli").Argument} Argument */
|
38
|
+
/** @typedef {import("./cli").Problem} Problem */
|
34
39
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsAsset} StatsAsset */
|
35
40
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsChunk} StatsChunk */
|
36
41
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsChunkGroup} StatsChunkGroup */
|
@@ -24,6 +24,7 @@ const { last, someInIterable } = require("../util/IterableHelpers");
|
|
24
24
|
const StringXor = require("../util/StringXor");
|
25
25
|
const { compareModulesByIdentifier } = require("../util/comparators");
|
26
26
|
const createHash = require("../util/createHash");
|
27
|
+
const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
|
27
28
|
const { intersectRuntime } = require("../util/runtime");
|
28
29
|
const JavascriptGenerator = require("./JavascriptGenerator");
|
29
30
|
const JavascriptParser = require("./JavascriptParser");
|
@@ -102,6 +103,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
102
103
|
/**
|
103
104
|
* @typedef {Object} RenderBootstrapContext
|
104
105
|
* @property {Chunk} chunk the chunk
|
106
|
+
* @property {CodeGenerationResults} codeGenerationResults results of code generation
|
105
107
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
106
108
|
* @property {ModuleGraph} moduleGraph the module graph
|
107
109
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
@@ -331,6 +333,7 @@ class JavascriptModulesPlugin {
|
|
331
333
|
{
|
332
334
|
hash: "0000",
|
333
335
|
chunk,
|
336
|
+
codeGenerationResults: context.codeGenerationResults,
|
334
337
|
chunkGraph: context.chunkGraph,
|
335
338
|
moduleGraph: context.moduleGraph,
|
336
339
|
runtimeTemplate: context.runtimeTemplate
|
@@ -343,6 +346,7 @@ class JavascriptModulesPlugin {
|
|
343
346
|
compilation.hooks.contentHash.tap("JavascriptModulesPlugin", chunk => {
|
344
347
|
const {
|
345
348
|
chunkGraph,
|
349
|
+
codeGenerationResults,
|
346
350
|
moduleGraph,
|
347
351
|
runtimeTemplate,
|
348
352
|
outputOptions: {
|
@@ -360,6 +364,7 @@ class JavascriptModulesPlugin {
|
|
360
364
|
{
|
361
365
|
hash: "0000",
|
362
366
|
chunk,
|
367
|
+
codeGenerationResults,
|
363
368
|
chunkGraph: compilation.chunkGraph,
|
364
369
|
moduleGraph: compilation.moduleGraph,
|
365
370
|
runtimeTemplate: compilation.runtimeTemplate
|
@@ -372,6 +377,7 @@ class JavascriptModulesPlugin {
|
|
372
377
|
}
|
373
378
|
hooks.chunkHash.call(chunk, hash, {
|
374
379
|
chunkGraph,
|
380
|
+
codeGenerationResults,
|
375
381
|
moduleGraph,
|
376
382
|
runtimeTemplate
|
377
383
|
});
|
@@ -398,7 +404,10 @@ class JavascriptModulesPlugin {
|
|
398
404
|
xor.updateHash(hash);
|
399
405
|
}
|
400
406
|
const digest = /** @type {string} */ (hash.digest(hashDigest));
|
401
|
-
chunk.contentHash.javascript =
|
407
|
+
chunk.contentHash.javascript = nonNumericOnlyHash(
|
408
|
+
digest,
|
409
|
+
hashDigestLength
|
410
|
+
);
|
402
411
|
});
|
403
412
|
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
404
413
|
"JavascriptModulesPlugin",
|
@@ -974,7 +983,13 @@ class JavascriptModulesPlugin {
|
|
974
983
|
* @returns {{ header: string[], beforeStartup: string[], startup: string[], afterStartup: string[], allowInlineStartup: boolean }} the generated source of the bootstrap code
|
975
984
|
*/
|
976
985
|
renderBootstrap(renderContext, hooks) {
|
977
|
-
const {
|
986
|
+
const {
|
987
|
+
chunkGraph,
|
988
|
+
codeGenerationResults,
|
989
|
+
moduleGraph,
|
990
|
+
chunk,
|
991
|
+
runtimeTemplate
|
992
|
+
} = renderContext;
|
978
993
|
|
979
994
|
const runtimeRequirements = chunkGraph.getTreeRuntimeRequirements(chunk);
|
980
995
|
|
@@ -1098,8 +1113,18 @@ class JavascriptModulesPlugin {
|
|
1098
1113
|
);
|
1099
1114
|
result.allowInlineStartup = false;
|
1100
1115
|
}
|
1116
|
+
|
1117
|
+
let data;
|
1118
|
+
if (codeGenerationResults.has(entryModule, chunk.runtime)) {
|
1119
|
+
const result = codeGenerationResults.get(
|
1120
|
+
entryModule,
|
1121
|
+
chunk.runtime
|
1122
|
+
);
|
1123
|
+
data = result.data;
|
1124
|
+
}
|
1101
1125
|
if (
|
1102
1126
|
result.allowInlineStartup &&
|
1127
|
+
(!data || !data.get("topLevelDeclarations")) &&
|
1103
1128
|
(!entryModule.buildInfo ||
|
1104
1129
|
!entryModule.buildInfo.topLevelDeclarations)
|
1105
1130
|
) {
|
@@ -14,6 +14,7 @@ const { getAllChunks } = require("./ChunkHelpers");
|
|
14
14
|
/** @typedef {import("../Chunk")} Chunk */
|
15
15
|
/** @typedef {import("../Compilation")} Compilation */
|
16
16
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
17
|
+
/** @typedef {import("../ChunkGraph").EntryModuleWithChunkGroup} EntryModuleWithChunkGroup */
|
17
18
|
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
18
19
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
19
20
|
/** @typedef {(string|number)[]} EntryItem */
|
@@ -23,7 +24,7 @@ const EXPORT_PREFIX = "var __webpack_exports__ = ";
|
|
23
24
|
/**
|
24
25
|
* @param {ChunkGraph} chunkGraph chunkGraph
|
25
26
|
* @param {RuntimeTemplate} runtimeTemplate runtimeTemplate
|
26
|
-
* @param {
|
27
|
+
* @param {EntryModuleWithChunkGroup[]} entries entries
|
27
28
|
* @param {Chunk} chunk chunk
|
28
29
|
* @param {boolean} passive true: passive startup with on chunks loaded
|
29
30
|
* @returns {string} runtime code
|
@@ -101,7 +102,7 @@ exports.generateEntryStartup = (
|
|
101
102
|
/**
|
102
103
|
* @param {Hash} hash the hash to update
|
103
104
|
* @param {ChunkGraph} chunkGraph chunkGraph
|
104
|
-
* @param {
|
105
|
+
* @param {EntryModuleWithChunkGroup[]} entries entries
|
105
106
|
* @param {Chunk} chunk chunk
|
106
107
|
* @returns {void}
|
107
108
|
*/
|
@@ -222,9 +222,15 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
222
222
|
* @param {LibraryContext<T>} libraryContext context
|
223
223
|
* @returns {string | undefined} bailout reason
|
224
224
|
*/
|
225
|
-
embedInRuntimeBailout(
|
225
|
+
embedInRuntimeBailout(
|
226
|
+
module,
|
227
|
+
{ chunk, codeGenerationResults },
|
228
|
+
{ options, compilation }
|
229
|
+
) {
|
230
|
+
const { data } = codeGenerationResults.get(module, chunk.runtime);
|
226
231
|
const topLevelDeclarations =
|
227
|
-
|
232
|
+
(data && data.get("topLevelDeclarations")) ||
|
233
|
+
(module.buildInfo && module.buildInfo.topLevelDeclarations);
|
228
234
|
if (!topLevelDeclarations)
|
229
235
|
return "it doesn't tell about top level declarations.";
|
230
236
|
const fullNameResolved = this._getResolvedFullName(
|