webpack 5.22.0 → 5.23.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/RuntimeGlobals.js +5 -0
- package/lib/RuntimePlugin.js +8 -0
- package/lib/WebpackOptionsApply.js +5 -5
- package/lib/config/defaults.js +26 -10
- package/lib/config/target.js +1 -1
- package/lib/dependencies/URLDependency.js +35 -13
- package/lib/dependencies/URLPlugin.js +3 -1
- package/lib/dependencies/WorkerPlugin.js +7 -1
- package/lib/index.js +1 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +15 -4
- package/lib/node/NodeTargetPlugin.js +1 -1
- package/lib/runtime/RelativeUrlRuntimeModule.js +41 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -0
- package/package.json +2 -2
- package/schemas/WebpackOptions.json +8 -1
- package/types.d.ts +4 -2
package/lib/RuntimeGlobals.js
CHANGED
@@ -304,6 +304,11 @@ exports.systemContext = "__webpack_require__.y";
|
|
304
304
|
*/
|
305
305
|
exports.baseURI = "__webpack_require__.b";
|
306
306
|
|
307
|
+
/**
|
308
|
+
* a RelativeURL class when relative URLs are used
|
309
|
+
*/
|
310
|
+
exports.relativeUrl = "__webpack_require__.U";
|
311
|
+
|
307
312
|
/**
|
308
313
|
* Creates an async module. The body function must be a async function.
|
309
314
|
* "module.exports" will be decorated with an AsyncModulePromise.
|
package/lib/RuntimePlugin.js
CHANGED
@@ -22,6 +22,7 @@ const HasOwnPropertyRuntimeModule = require("./runtime/HasOwnPropertyRuntimeModu
|
|
22
22
|
const LoadScriptRuntimeModule = require("./runtime/LoadScriptRuntimeModule");
|
23
23
|
const MakeNamespaceObjectRuntimeModule = require("./runtime/MakeNamespaceObjectRuntimeModule");
|
24
24
|
const PublicPathRuntimeModule = require("./runtime/PublicPathRuntimeModule");
|
25
|
+
const RelativeUrlRuntimeModule = require("./runtime/RelativeUrlRuntimeModule");
|
25
26
|
const RuntimeIdRuntimeModule = require("./runtime/RuntimeIdRuntimeModule");
|
26
27
|
const SystemContextRuntimeModule = require("./runtime/SystemContextRuntimeModule");
|
27
28
|
const ShareRuntimeModule = require("./sharing/ShareRuntimeModule");
|
@@ -48,6 +49,7 @@ const GLOBALS_ON_REQUIRE = [
|
|
48
49
|
RuntimeGlobals.interceptModuleExecution,
|
49
50
|
RuntimeGlobals.publicPath,
|
50
51
|
RuntimeGlobals.baseURI,
|
52
|
+
RuntimeGlobals.relativeUrl,
|
51
53
|
RuntimeGlobals.scriptNonce,
|
52
54
|
RuntimeGlobals.uncaughtErrorHandler,
|
53
55
|
RuntimeGlobals.asyncModule,
|
@@ -313,6 +315,12 @@ class RuntimePlugin {
|
|
313
315
|
compilation.addRuntimeModule(chunk, new LoadScriptRuntimeModule());
|
314
316
|
return true;
|
315
317
|
});
|
318
|
+
compilation.hooks.runtimeRequirementInTree
|
319
|
+
.for(RuntimeGlobals.relativeUrl)
|
320
|
+
.tap("RuntimePlugin", (chunk, set) => {
|
321
|
+
compilation.addRuntimeModule(chunk, new RelativeUrlRuntimeModule());
|
322
|
+
return true;
|
323
|
+
});
|
316
324
|
// TODO webpack 6: remove CompatRuntimeModule
|
317
325
|
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
318
326
|
"RuntimePlugin",
|
@@ -43,6 +43,7 @@ const RequireEnsurePlugin = require("./dependencies/RequireEnsurePlugin");
|
|
43
43
|
const RequireIncludePlugin = require("./dependencies/RequireIncludePlugin");
|
44
44
|
const SystemPlugin = require("./dependencies/SystemPlugin");
|
45
45
|
const URLPlugin = require("./dependencies/URLPlugin");
|
46
|
+
const WorkerPlugin = require("./dependencies/WorkerPlugin");
|
46
47
|
|
47
48
|
const InferAsyncModulesPlugin = require("./async-modules/InferAsyncModulesPlugin");
|
48
49
|
|
@@ -312,11 +313,10 @@ class WebpackOptionsApply extends OptionsApply {
|
|
312
313
|
new SystemPlugin().apply(compiler);
|
313
314
|
new ImportMetaPlugin().apply(compiler);
|
314
315
|
new URLPlugin().apply(compiler);
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
}
|
316
|
+
new WorkerPlugin(
|
317
|
+
options.output.workerChunkLoading,
|
318
|
+
options.output.workerWasmLoading
|
319
|
+
).apply(compiler);
|
320
320
|
|
321
321
|
new DefaultStatsFactoryPlugin().apply(compiler);
|
322
322
|
new DefaultStatsPresetPlugin().apply(compiler);
|
package/lib/config/defaults.js
CHANGED
@@ -622,11 +622,19 @@ const applyOutputDefaults = (
|
|
622
622
|
});
|
623
623
|
F(output, "chunkLoading", () => {
|
624
624
|
if (tp) {
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
625
|
+
switch (output.chunkFormat) {
|
626
|
+
case "array-push":
|
627
|
+
if (tp.document) return "jsonp";
|
628
|
+
if (tp.importScripts) return "import-scripts";
|
629
|
+
break;
|
630
|
+
case "commonjs":
|
631
|
+
if (tp.require) return "require";
|
632
|
+
if (tp.nodeBuiltins) return "async-node";
|
633
|
+
break;
|
634
|
+
case "module":
|
635
|
+
if (tp.dynamicImport) return "import";
|
636
|
+
break;
|
637
|
+
}
|
630
638
|
if (
|
631
639
|
tp.require === null ||
|
632
640
|
tp.nodeBuiltins === null ||
|
@@ -640,10 +648,18 @@ const applyOutputDefaults = (
|
|
640
648
|
});
|
641
649
|
F(output, "workerChunkLoading", () => {
|
642
650
|
if (tp) {
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
651
|
+
switch (output.chunkFormat) {
|
652
|
+
case "array-push":
|
653
|
+
if (tp.importScriptsInWorker) return "import-scripts";
|
654
|
+
break;
|
655
|
+
case "commonjs":
|
656
|
+
if (tp.require) return "require";
|
657
|
+
if (tp.nodeBuiltins) return "async-node";
|
658
|
+
break;
|
659
|
+
case "module":
|
660
|
+
if (tp.dynamicImportInWorker) return "import";
|
661
|
+
break;
|
662
|
+
}
|
647
663
|
if (
|
648
664
|
tp.require === null ||
|
649
665
|
tp.nodeBuiltins === null ||
|
@@ -656,8 +672,8 @@ const applyOutputDefaults = (
|
|
656
672
|
});
|
657
673
|
F(output, "wasmLoading", () => {
|
658
674
|
if (tp) {
|
659
|
-
if (tp.nodeBuiltins) return "async-node";
|
660
675
|
if (tp.fetchWasm) return "fetch";
|
676
|
+
if (tp.nodeBuiltins) return "async-node";
|
661
677
|
if (tp.nodeBuiltins === null || tp.fetchWasm === null) {
|
662
678
|
return "universal";
|
663
679
|
}
|
package/lib/config/target.js
CHANGED
@@ -197,7 +197,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|
197
197
|
document: context === "renderer",
|
198
198
|
fetchWasm: context === "renderer",
|
199
199
|
importScripts: false,
|
200
|
-
importScriptsInWorker:
|
200
|
+
importScriptsInWorker: true,
|
201
201
|
|
202
202
|
globalThis: v(5),
|
203
203
|
const: v(1, 1),
|
@@ -28,11 +28,13 @@ class URLDependency extends ModuleDependency {
|
|
28
28
|
* @param {string} request request
|
29
29
|
* @param {[number, number]} range range of the arguments of new URL( |> ... <| )
|
30
30
|
* @param {[number, number]} outerRange range of the full |> new URL(...) <|
|
31
|
+
* @param {boolean=} relative use relative urls instead of absolute with base uri
|
31
32
|
*/
|
32
|
-
constructor(request, range, outerRange) {
|
33
|
+
constructor(request, range, outerRange, relative) {
|
33
34
|
super(request);
|
34
35
|
this.range = range;
|
35
36
|
this.outerRange = outerRange;
|
37
|
+
this.relative = relative || false;
|
36
38
|
/** @type {Set<string> | boolean} */
|
37
39
|
this.usedByExports = undefined;
|
38
40
|
}
|
@@ -60,6 +62,7 @@ class URLDependency extends ModuleDependency {
|
|
60
62
|
serialize(context) {
|
61
63
|
const { write } = context;
|
62
64
|
write(this.outerRange);
|
65
|
+
write(this.relative);
|
63
66
|
write(this.usedByExports);
|
64
67
|
super.serialize(context);
|
65
68
|
}
|
@@ -67,6 +70,7 @@ class URLDependency extends ModuleDependency {
|
|
67
70
|
deserialize(context) {
|
68
71
|
const { read } = context;
|
69
72
|
this.outerRange = read();
|
73
|
+
this.relative = read();
|
70
74
|
this.usedByExports = read();
|
71
75
|
super.deserialize(context);
|
72
76
|
}
|
@@ -101,20 +105,38 @@ URLDependency.Template = class URLDependencyTemplate extends (
|
|
101
105
|
return;
|
102
106
|
}
|
103
107
|
|
104
|
-
runtimeRequirements.add(RuntimeGlobals.baseURI);
|
105
108
|
runtimeRequirements.add(RuntimeGlobals.require);
|
106
109
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
110
|
+
if (dep.relative) {
|
111
|
+
runtimeRequirements.add(RuntimeGlobals.relativeUrl);
|
112
|
+
source.replace(
|
113
|
+
dep.outerRange[0],
|
114
|
+
dep.outerRange[1] - 1,
|
115
|
+
`/* asset import */ new ${
|
116
|
+
RuntimeGlobals.relativeUrl
|
117
|
+
}(${runtimeTemplate.moduleRaw({
|
118
|
+
chunkGraph,
|
119
|
+
module: moduleGraph.getModule(dep),
|
120
|
+
request: dep.request,
|
121
|
+
runtimeRequirements,
|
122
|
+
weak: false
|
123
|
+
})})`
|
124
|
+
);
|
125
|
+
} else {
|
126
|
+
runtimeRequirements.add(RuntimeGlobals.baseURI);
|
127
|
+
|
128
|
+
source.replace(
|
129
|
+
dep.range[0],
|
130
|
+
dep.range[1] - 1,
|
131
|
+
`/* asset import */ ${runtimeTemplate.moduleRaw({
|
132
|
+
chunkGraph,
|
133
|
+
module: moduleGraph.getModule(dep),
|
134
|
+
request: dep.request,
|
135
|
+
runtimeRequirements,
|
136
|
+
weak: false
|
137
|
+
})}, ${RuntimeGlobals.baseURI}`
|
138
|
+
);
|
139
|
+
}
|
118
140
|
}
|
119
141
|
};
|
120
142
|
|
@@ -33,6 +33,7 @@ class URLPlugin {
|
|
33
33
|
*/
|
34
34
|
const parserCallback = (parser, parserOptions) => {
|
35
35
|
if (parserOptions.url === false) return;
|
36
|
+
const relative = parserOptions.url === "relative";
|
36
37
|
|
37
38
|
/**
|
38
39
|
* @param {NewExpressionNode} expr expression
|
@@ -77,7 +78,8 @@ class URLPlugin {
|
|
77
78
|
const dep = new URLDependency(
|
78
79
|
request,
|
79
80
|
[arg1.range[0], arg2.range[1]],
|
80
|
-
expr.range
|
81
|
+
expr.range,
|
82
|
+
relative
|
81
83
|
);
|
82
84
|
dep.loc = expr.loc;
|
83
85
|
parser.state.module.addDependency(dep);
|
@@ -13,6 +13,7 @@ const formatLocation = require("../formatLocation");
|
|
13
13
|
const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin");
|
14
14
|
const { equals } = require("../util/ArrayHelpers");
|
15
15
|
const { contextify } = require("../util/identifier");
|
16
|
+
const EnableWasmLoadingPlugin = require("../wasm/EnableWasmLoadingPlugin");
|
16
17
|
const {
|
17
18
|
harmonySpecifierTag
|
18
19
|
} = require("./HarmonyImportDependencyParserPlugin");
|
@@ -37,8 +38,9 @@ const DEFAULT_SYNTAX = [
|
|
37
38
|
];
|
38
39
|
|
39
40
|
class WorkerPlugin {
|
40
|
-
constructor(chunkLoading) {
|
41
|
+
constructor(chunkLoading, wasmLoading) {
|
41
42
|
this._chunkLoading = chunkLoading;
|
43
|
+
this._wasmLoading = wasmLoading;
|
42
44
|
}
|
43
45
|
/**
|
44
46
|
* Apply the plugin
|
@@ -49,6 +51,9 @@ class WorkerPlugin {
|
|
49
51
|
if (this._chunkLoading) {
|
50
52
|
new EnableChunkLoadingPlugin(this._chunkLoading).apply(compiler);
|
51
53
|
}
|
54
|
+
if (this._wasmLoading) {
|
55
|
+
new EnableWasmLoadingPlugin(this._wasmLoading).apply(compiler);
|
56
|
+
}
|
52
57
|
const cachedContextify = contextify.bindContextCache(
|
53
58
|
compiler.context,
|
54
59
|
compiler.root
|
@@ -227,6 +232,7 @@ class WorkerPlugin {
|
|
227
232
|
name: entryOptions.name,
|
228
233
|
entryOptions: {
|
229
234
|
chunkLoading: this._chunkLoading,
|
235
|
+
wasmLoading: this._wasmLoading,
|
230
236
|
...entryOptions
|
231
237
|
}
|
232
238
|
});
|
package/lib/index.js
CHANGED
@@ -25,6 +25,7 @@ const memoize = require("./util/memoize");
|
|
25
25
|
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
|
26
26
|
/** @typedef {import("./Compilation").Asset} Asset */
|
27
27
|
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
28
|
+
/** @typedef {import("./MultiStats")} MultiStats */
|
28
29
|
/** @typedef {import("./Parser").ParserState} ParserState */
|
29
30
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsCompilation} StatsCompilation */
|
30
31
|
|
@@ -115,18 +115,29 @@ class CommonJsChunkFormatPlugin {
|
|
115
115
|
entrySource.add(
|
116
116
|
`${RuntimeGlobals.externalInstallChunk}(exports);\n`
|
117
117
|
);
|
118
|
+
const startupSource = new ConcatSource();
|
118
119
|
for (let i = 0; i < entries.length; i++) {
|
119
120
|
const [module, entrypoint] = entries[i];
|
120
|
-
|
121
|
-
`${
|
122
|
-
|
123
|
-
}(${JSON.stringify(
|
121
|
+
startupSource.add(
|
122
|
+
`${
|
123
|
+
i === entries.length - 1 ? "var __webpack_exports__ = " : ""
|
124
|
+
}${RuntimeGlobals.startupEntrypoint}(${JSON.stringify(
|
124
125
|
entrypoint.chunks
|
125
126
|
.filter(c => c !== chunk && c !== runtimeChunk)
|
126
127
|
.map(c => c.id)
|
127
128
|
)}, ${JSON.stringify(chunkGraph.getModuleId(module))});\n`
|
128
129
|
);
|
129
130
|
}
|
131
|
+
entrySource.add(
|
132
|
+
hooks.renderStartup.call(
|
133
|
+
startupSource,
|
134
|
+
entries[entries.length - 1][0],
|
135
|
+
{
|
136
|
+
...renderContext,
|
137
|
+
inlined: false
|
138
|
+
}
|
139
|
+
)
|
140
|
+
);
|
130
141
|
entrySource.add("})()");
|
131
142
|
return entrySource;
|
132
143
|
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
*/
|
4
|
+
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
8
|
+
const Template = require("../Template");
|
9
|
+
const HelperRuntimeModule = require("./HelperRuntimeModule");
|
10
|
+
|
11
|
+
class RelativeUrlRuntimeModule extends HelperRuntimeModule {
|
12
|
+
constructor() {
|
13
|
+
super("relative url");
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @returns {string} runtime code
|
18
|
+
*/
|
19
|
+
generate() {
|
20
|
+
const { runtimeTemplate } = this.compilation;
|
21
|
+
return Template.asString([
|
22
|
+
`${RuntimeGlobals.relativeUrl} = function RelativeURL(url) {`,
|
23
|
+
Template.indent([
|
24
|
+
'var realUrl = new URL(url, "x:/");',
|
25
|
+
"var values = {};",
|
26
|
+
"for (var key in realUrl) values[key] = realUrl[key];",
|
27
|
+
"values.href = url;",
|
28
|
+
'values.pathname = url.replace(/[?#].*/, "");',
|
29
|
+
'values.origin = values.protocol = "";',
|
30
|
+
`values.toString = values.toJSON = ${runtimeTemplate.returningFunction(
|
31
|
+
"url"
|
32
|
+
)};`,
|
33
|
+
"for (var key in values) Object.defineProperty(this, key, Object.assign({ enumerable: true, configurable: true, value: values[key] }));"
|
34
|
+
]),
|
35
|
+
"};",
|
36
|
+
`${RuntimeGlobals.relativeUrl}.prototype = URL.prototype;`
|
37
|
+
]);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
module.exports = RelativeUrlRuntimeModule;
|
@@ -56,6 +56,7 @@ class StartupChunkDependenciesPlugin {
|
|
56
56
|
.for(RuntimeGlobals.startupEntrypoint)
|
57
57
|
.tap("StartupChunkDependenciesPlugin", (chunk, set) => {
|
58
58
|
if (!isEnabledForChunk(chunk)) return;
|
59
|
+
set.add(RuntimeGlobals.require);
|
59
60
|
set.add(RuntimeGlobals.ensureChunk);
|
60
61
|
set.add(RuntimeGlobals.ensureChunkIncludeEntries);
|
61
62
|
compilation.addRuntimeModule(
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "webpack",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.23.0",
|
4
4
|
"author": "Tobias Koppers @sokra",
|
5
5
|
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
|
6
6
|
"license": "MIT",
|
@@ -55,7 +55,7 @@
|
|
55
55
|
"eslint": "^7.14.0",
|
56
56
|
"eslint-config-prettier": "^7.0.0",
|
57
57
|
"eslint-plugin-jest": "^24.1.3",
|
58
|
-
"eslint-plugin-jsdoc": "^
|
58
|
+
"eslint-plugin-jsdoc": "^32.0.2",
|
59
59
|
"eslint-plugin-node": "^11.0.0",
|
60
60
|
"eslint-plugin-prettier": "^3.1.4",
|
61
61
|
"file-loader": "^6.0.0",
|
@@ -1269,7 +1269,14 @@
|
|
1269
1269
|
},
|
1270
1270
|
"url": {
|
1271
1271
|
"description": "Enable/disable parsing of new URL() syntax.",
|
1272
|
-
"
|
1272
|
+
"anyOf": [
|
1273
|
+
{
|
1274
|
+
"enum": ["relative"]
|
1275
|
+
},
|
1276
|
+
{
|
1277
|
+
"type": "boolean"
|
1278
|
+
}
|
1279
|
+
]
|
1273
1280
|
},
|
1274
1281
|
"worker": {
|
1275
1282
|
"description": "Disable or configure parsing of WebWorker syntax like new Worker() or navigator.serviceWorker.register().",
|
package/types.d.ts
CHANGED
@@ -4899,7 +4899,7 @@ declare interface JavascriptParserOptions {
|
|
4899
4899
|
/**
|
4900
4900
|
* Enable/disable parsing of new URL() syntax.
|
4901
4901
|
*/
|
4902
|
-
url?: boolean;
|
4902
|
+
url?: boolean | "relative";
|
4903
4903
|
|
4904
4904
|
/**
|
4905
4905
|
* Disable or configure parsing of WebWorker syntax like new Worker() or navigator.serviceWorker.register().
|
@@ -10476,7 +10476,7 @@ declare interface UpdateHashContextGenerator {
|
|
10476
10476
|
chunkGraph: ChunkGraph;
|
10477
10477
|
runtime: RuntimeSpec;
|
10478
10478
|
}
|
10479
|
-
type UsageStateType = 0 |
|
10479
|
+
type UsageStateType = 0 | 1 | 2 | 3 | 4;
|
10480
10480
|
declare interface UserResolveOptions {
|
10481
10481
|
/**
|
10482
10482
|
* A list of module alias configurations or an object which maps key to value
|
@@ -11201,6 +11201,7 @@ declare namespace exports {
|
|
11201
11201
|
export let hasOwnProperty: string;
|
11202
11202
|
export let systemContext: string;
|
11203
11203
|
export let baseURI: string;
|
11204
|
+
export let relativeUrl: string;
|
11204
11205
|
export let asyncModule: string;
|
11205
11206
|
}
|
11206
11207
|
export const UsageState: Readonly<{
|
@@ -11482,6 +11483,7 @@ declare namespace exports {
|
|
11482
11483
|
WebpackPluginInstance,
|
11483
11484
|
Asset,
|
11484
11485
|
AssetInfo,
|
11486
|
+
MultiStats,
|
11485
11487
|
ParserState,
|
11486
11488
|
StatsCompilation
|
11487
11489
|
};
|