webpack 5.111.0 → 5.111.1
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/lib/APIPlugin.js +3 -4
- package/lib/CompatibilityPlugin.js +3 -4
- package/lib/Compilation.js +16 -35
- package/lib/Compiler.js +4 -5
- package/lib/ConstPlugin.js +16 -132
- package/lib/DependencyTemplate.js +2 -1
- package/lib/DotenvPlugin.js +24 -28
- package/lib/ErrorHelpers.js +113 -0
- package/lib/ExportsInfo.js +20 -16
- package/lib/ExternalModule.js +6 -8
- package/lib/FlagDependencyExportsPlugin.js +8 -13
- package/lib/FlagDependencyUsagePlugin.js +9 -13
- package/lib/Generator.js +24 -2
- package/lib/HotModuleReplacementPlugin.js +2 -0
- package/lib/IgnorePlugin.js +1 -1
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/Module.js +3 -3
- package/lib/ModuleGraph.js +6 -9
- package/lib/MultiCompiler.js +6 -16
- package/lib/NormalModule.js +96 -44
- package/lib/RuntimeTemplate.js +33 -43
- package/lib/SourceMapDevToolPlugin.js +53 -103
- package/lib/TemplatedPathPlugin.js +16 -59
- package/lib/asset/AssetBytesGenerator.js +7 -1
- package/lib/asset/AssetGenerator.js +25 -16
- package/lib/asset/AssetSourceGenerator.js +7 -1
- package/lib/buildChunkGraph.js +11 -15
- package/lib/cache/MemoryCachePlugin.js +4 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
- package/lib/cache/PackFileCacheStrategy.js +3 -18
- package/lib/cache/getLazyHashedEtag.js +3 -5
- package/lib/config/browserslistTargetHandler.js +2 -8
- package/lib/config/defaults.js +52 -78
- package/lib/config/getClaimedAssetTypes.js +10 -11
- package/lib/config/target.js +3 -4
- package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
- package/lib/{ContextModule.js → context/ContextModule.js} +37 -34
- package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
- package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
- package/lib/css/CssGenerator.js +19 -11
- package/lib/css/CssParser.js +18 -20
- package/lib/css/cssMinify.js +32 -29
- package/lib/css/data.js +797 -288
- package/lib/css/syntax.js +2250 -934
- package/lib/debug/ProfilingPlugin.js +3 -4
- package/lib/dependencies/CommonJsExportRequireDependency.js +10 -11
- package/lib/dependencies/CommonJsImportsParserPlugin.js +4 -5
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -9
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/CssIcssExportDependency.js +6 -8
- package/lib/dependencies/CssIcssImportDependency.js +3 -6
- package/lib/dependencies/CssUrlDependency.js +3 -5
- package/lib/dependencies/HarmonyCompatibilityDependency.js +11 -20
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -4
- package/lib/dependencies/HarmonyExportExpressionDependency.js +3 -4
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +3 -4
- package/lib/dependencies/HarmonyExportInitFragment.js +26 -19
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +7 -28
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +103 -16
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +3 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +16 -2
- package/lib/dependencies/HtmlEntryDependency.js +74 -102
- package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
- package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
- package/lib/dependencies/ImportMetaPlugin.js +8 -10
- package/lib/dependencies/ImportParserPlugin.js +1 -1
- package/lib/dependencies/LoaderPlugin.js +26 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/URLContextDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +6 -5
- package/lib/dependencies/WorkerAndWorkletPlugin.js +15 -21
- package/lib/dependencies/WorkerDependency.js +6 -5
- package/lib/dependencies/WorkletDependency.js +6 -9
- package/lib/errors/HookWebpackError.js +3 -2
- package/lib/hmr/LazyCompilationPlugin.js +3 -5
- package/lib/html/HtmlGenerator.js +61 -82
- package/lib/html/HtmlModulesPlugin.js +88 -139
- package/lib/html/HtmlParser.js +97 -141
- package/lib/html/data.js +21 -0
- package/lib/html/htmlMinify.js +10 -11
- package/lib/html/syntax.js +883 -993
- package/lib/index.js +46 -3
- package/lib/javascript/ChunkFormatHelpers.js +4 -3
- package/lib/javascript/JavascriptGenerator.js +8 -1
- package/lib/javascript/JavascriptModulesPlugin.js +21 -48
- package/lib/javascript/JavascriptParser.js +721 -178
- package/lib/javascript/parser.js +6 -0
- package/lib/javascript/syntax.js +420 -92
- package/lib/json/JsonGenerator.js +7 -1
- package/lib/library/ModuleLibraryPlugin.js +64 -136
- package/lib/loaders/LoaderRunner.js +137 -9
- package/lib/node/NodeWatchFileSystem.js +3 -9
- package/lib/optimize/AggressiveMergingPlugin.js +3 -5
- package/lib/optimize/ConcatenatedModule.js +81 -100
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
- package/lib/optimize/InnerGraphPlugin.js +7 -13
- package/lib/optimize/LimitChunkCountPlugin.js +5 -8
- package/lib/optimize/MangleExportsPlugin.js +3 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +3 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +7 -19
- package/lib/optimize/SplitChunksPlugin.js +2 -4
- package/lib/performance/BroadContextsPlugin.js +1 -1
- package/lib/performance/CacheEffectivenessPlugin.js +3 -4
- package/lib/performance/SizeLimitsPlugin.js +2 -4
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +6 -8
- package/lib/prefetch/ResourceHintPlugin.js +17 -21
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +7 -10
- package/lib/runtime/AsyncModuleRuntimeModule.js +3 -5
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
- package/lib/runtime/GlobalRuntimeModule.js +2 -4
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +55 -85
- package/lib/schemes/DataUriPlugin.js +3 -6
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +9 -9
- package/lib/serialization/FileMiddleware.js +16 -16
- package/lib/serialization/ObjectMiddleware.js +30 -33
- package/lib/stats/DefaultStatsFactoryPlugin.js +3 -4
- package/lib/typescript/TypeScriptPlugin.js +2 -3
- package/lib/url/URLParserPlugin.js +6 -8
- package/lib/util/LocConverter.js +4 -7
- package/lib/util/SourceProcessor.js +15 -22
- package/lib/util/chainedImports.js +3 -4
- package/lib/util/concatenate.js +4 -4
- package/lib/util/createHooksRegistry.js +1 -2
- package/lib/util/dataURL.js +2 -3
- package/lib/util/deterministicGrouping.js +8 -13
- package/lib/util/findGraphRoots.js +6 -13
- package/lib/util/globUtils.js +1 -1
- package/lib/util/hash/wasm-hash.js +3 -4
- package/lib/util/internalSerializables.js +1 -1
- package/lib/util/semver.js +5 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
- package/package.json +30 -23
- package/types.d.ts +299 -280
|
@@ -45,7 +45,7 @@ const getCommentCompilationWarning = memoize(() =>
|
|
|
45
45
|
* } from "../../declarations/WebpackOptions"
|
|
46
46
|
*/
|
|
47
47
|
/** @import { RawChunkGroupOptions } from "../ChunkGroup" */
|
|
48
|
-
/** @import { ContextMode } from "../ContextModule" */
|
|
48
|
+
/** @import { ContextMode } from "../context/ContextModule" */
|
|
49
49
|
/** @import { RawReferencedExports } from "../Dependency" */
|
|
50
50
|
/** @import { BuildMeta } from "../Module" */
|
|
51
51
|
/**
|
|
@@ -21,7 +21,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
|
|
|
21
21
|
* } from "../Compilation"
|
|
22
22
|
*/
|
|
23
23
|
/** @import Compiler from "../Compiler" */
|
|
24
|
-
/** @import { BuildInfo } from "../Module" */
|
|
24
|
+
/** @import Module, { BuildInfo } from "../Module" */
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Defines the import module callback callback.
|
|
@@ -39,6 +39,31 @@ const LoaderImportDependency = require("./LoaderImportDependency");
|
|
|
39
39
|
* @property {string=} baseUri target base uri
|
|
40
40
|
*/
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @callback LoadModuleCallback
|
|
44
|
+
* @param {Error | null} err error object
|
|
45
|
+
* @param {(string | Buffer)=} source source of the loaded module
|
|
46
|
+
* @param {(object | null)=} sourceMap source map of the loaded module
|
|
47
|
+
* @param {Module=} module the loaded module
|
|
48
|
+
* @returns {void}
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* `importModule` takes a callback or, given none, answers with a promise, and
|
|
53
|
+
* TypeScript reads an intersection of call signatures as an overload set
|
|
54
|
+
* @typedef {{ (request: string, options: ImportModuleOptions | undefined, callback: ImportModuleCallback): void } & { (request: string, options?: ImportModuleOptions): Promise<ExecuteModuleExports> }} ImportModuleMethod
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* These properties are added by the LoaderPlugin
|
|
59
|
+
* @typedef {object} LoaderPluginLoaderContext
|
|
60
|
+
* @property {(request: string, callback: LoadModuleCallback) => void} loadModule Resolves the given request to a module, applies all configured loaders and calls
|
|
61
|
+
* back with the generated source, the sourceMap and the module instance (usually an
|
|
62
|
+
* instance of NormalModule). Use this function if you need to know the source code
|
|
63
|
+
* of another module to generate the result.
|
|
64
|
+
* @property {ImportModuleMethod} importModule
|
|
65
|
+
*/
|
|
66
|
+
|
|
42
67
|
const PLUGIN_NAME = "LoaderPlugin";
|
|
43
68
|
|
|
44
69
|
class LoaderPlugin {
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
const RequireContextDependency = require("./RequireContextDependency");
|
|
9
9
|
|
|
10
|
-
/** @import { ContextMode } from "../ContextModule" */
|
|
10
|
+
/** @import { ContextMode } from "../context/ContextModule" */
|
|
11
11
|
/** @import JavascriptParser, { Range } from "../javascript/JavascriptParser" */
|
|
12
12
|
|
|
13
13
|
const PLUGIN_NAME = "RequireContextDependencyParserPlugin";
|
|
@@ -9,7 +9,7 @@ const makeSerializable = require("../util/makeSerializable");
|
|
|
9
9
|
const ContextDependency = require("./ContextDependency");
|
|
10
10
|
const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
|
|
11
11
|
|
|
12
|
-
/** @import { ContextOptions } from "../ContextModule" */
|
|
12
|
+
/** @import { ContextOptions } from "../context/ContextModule" */
|
|
13
13
|
/** @import { Range } from "../javascript/JavascriptParser" */
|
|
14
14
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[Range]>} ObjectDeserializerContext */
|
|
15
15
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[Range]>} ObjectSerializerContext */
|
|
@@ -263,11 +263,12 @@ URLDependency.Template = class URLDependencyTemplate extends (
|
|
|
263
263
|
return;
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
-
//
|
|
267
|
-
//
|
|
268
|
-
//
|
|
269
|
-
//
|
|
270
|
-
//
|
|
266
|
+
// WHY: ESM module output emits the analyzable
|
|
267
|
+
// `new URL("./asset", import.meta.url)` form — a literal specifier, no runtime
|
|
268
|
+
// helpers — so other bundlers and webpack itself can statically follow the
|
|
269
|
+
// asset, while `url: "relative"` keeps the runtime form. A prefetch or preload
|
|
270
|
+
// hint does not force it: the `<link>` is emitted separately at chunk startup
|
|
271
|
+
// (`StartupAssetHintRuntimeModule`), independent of the call site.
|
|
271
272
|
if (
|
|
272
273
|
!dep.relative &&
|
|
273
274
|
runtimeTemplate.supportsAnalyzable(
|
|
@@ -86,10 +86,9 @@ const WORKER_DEFAULT_SYNTAX = [
|
|
|
86
86
|
"Worker from worker_threads"
|
|
87
87
|
];
|
|
88
88
|
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
// pre-added via `addModule` from the calling scope (see WorkletDependency).
|
|
89
|
+
// A worklet is always a module script loaded through `addModule`, and unlike a
|
|
90
|
+
// Web Worker cannot load further chunks at runtime, so WorkletDependency wraps
|
|
91
|
+
// the call and pre-adds every chunk from the calling scope.
|
|
93
92
|
const WORKLET_DEFAULT_SYNTAX = [
|
|
94
93
|
"*context.audioWorklet.addModule()",
|
|
95
94
|
"*audioWorklet.addModule()",
|
|
@@ -406,10 +405,9 @@ class WorkerAndWorkletPlugin {
|
|
|
406
405
|
)
|
|
407
406
|
);
|
|
408
407
|
} else {
|
|
409
|
-
// `webpackEntryOptions` is user input from a magic
|
|
410
|
-
//
|
|
411
|
-
//
|
|
412
|
-
// `prototype`.
|
|
408
|
+
// `webpackEntryOptions` is user input from a magic comment, so
|
|
409
|
+
// only safe own keys are copied, against prototype pollution
|
|
410
|
+
// through `__proto__` or `constructor`.
|
|
413
411
|
const userEntryOptions = importOptions.webpackEntryOptions;
|
|
414
412
|
for (const key of Object.keys(userEntryOptions)) {
|
|
415
413
|
if (
|
|
@@ -502,11 +500,9 @@ class WorkerAndWorkletPlugin {
|
|
|
502
500
|
|
|
503
501
|
/** @type {ResourceHint | undefined} */
|
|
504
502
|
let resourceHint;
|
|
505
|
-
// Resource-hint comments belong to the asset expression
|
|
506
|
-
//
|
|
507
|
-
//
|
|
508
|
-
// `import.meta.url` there is no `new URL` and no place for
|
|
509
|
-
// the comments to go, so resource hints are skipped.
|
|
503
|
+
// Resource-hint comments belong to the asset expression, so they are
|
|
504
|
+
// read from the inner `new URL(...)` range alone. A bare
|
|
505
|
+
// `import.meta.url` has none, so its hints are skipped.
|
|
510
506
|
if (arg1.type === "NewExpression") {
|
|
511
507
|
const { options: urlImportOptions } = parser.parseCommentOptions(
|
|
512
508
|
/** @type {Range} */ (arg1.range)
|
|
@@ -652,10 +648,9 @@ class WorkerAndWorkletPlugin {
|
|
|
652
648
|
name: entryOptions.name,
|
|
653
649
|
circular: false,
|
|
654
650
|
entryOptions: {
|
|
655
|
-
// A module worklet links its split chunks
|
|
656
|
-
//
|
|
657
|
-
//
|
|
658
|
-
// chunks use import-scripts and are pre-added from the calling scope.
|
|
651
|
+
// A module worklet links its split chunks through native `import`
|
|
652
|
+
// and keeps module chunk loading. A script worklet loads none at
|
|
653
|
+
// runtime, so its chunks are pre-added from the calling scope.
|
|
659
654
|
chunkLoading: this._module
|
|
660
655
|
? this._chunkLoading
|
|
661
656
|
: "import-scripts",
|
|
@@ -800,10 +795,9 @@ class WorkerAndWorkletPlugin {
|
|
|
800
795
|
);
|
|
801
796
|
}
|
|
802
797
|
|
|
803
|
-
// Worklet parsing is opt-in: unset falls back to
|
|
804
|
-
//
|
|
805
|
-
//
|
|
806
|
-
// merge sentinel of a user-provided list.
|
|
798
|
+
// Worklet parsing is opt-in: unset falls back to `futureDefaults` and
|
|
799
|
+
// `false` disables it. Not defaulted in `config/defaults.js`, which
|
|
800
|
+
// would splice into a user list's `"..."` sentinel.
|
|
807
801
|
const workletOption =
|
|
808
802
|
parserOptions.worklet === undefined
|
|
809
803
|
? this._workletDefault
|
|
@@ -131,11 +131,12 @@ WorkerDependency.Template = class WorkerDependencyTemplate extends (
|
|
|
131
131
|
);
|
|
132
132
|
const chunk = entrypoint.getEntrypointChunk();
|
|
133
133
|
|
|
134
|
-
//
|
|
135
|
-
// import.meta.url)` form
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
//
|
|
134
|
+
// WHY: ESM module output emits the analyzable
|
|
135
|
+
// `new URL("./worker.<name>.js", import.meta.url)` form — a literal specifier,
|
|
136
|
+
// no runtime helpers — so other bundlers and webpack itself can statically
|
|
137
|
+
// follow the worker. A resource hint does not block it: the `<link>` is
|
|
138
|
+
// emitted at chunk startup instead of wrapping the href, which would turn the
|
|
139
|
+
// specifier into a non-analyzable expression.
|
|
139
140
|
const analyzableSpecifier = runtimeTemplate.getAnalyzableWorkerUrl(
|
|
140
141
|
dep.options.publicPath,
|
|
141
142
|
chunk,
|
|
@@ -136,10 +136,9 @@ WorkletDependency.Template = class WorkletDependencyTemplate extends (
|
|
|
136
136
|
const runtimeChunkId =
|
|
137
137
|
runtimeChunk && runtimeChunk.id !== null ? runtimeChunk.id : null;
|
|
138
138
|
|
|
139
|
-
//
|
|
140
|
-
// import.meta.url)
|
|
141
|
-
//
|
|
142
|
-
// splits via native `import`, so only the entry chunk is referenced.
|
|
139
|
+
// ESM output emits the analyzable `new URL("./worklet.<name>.js",
|
|
140
|
+
// import.meta.url)`, which another bundler can follow statically. Only the
|
|
141
|
+
// entry chunk is named, its splits being linked by native `import`.
|
|
143
142
|
const analyzableSpecifier = runtimeTemplate.getAnalyzableWorkerUrl(
|
|
144
143
|
dep.options.publicPath,
|
|
145
144
|
entryChunk,
|
|
@@ -196,11 +195,9 @@ WorkletDependency.Template = class WorkletDependencyTemplate extends (
|
|
|
196
195
|
return;
|
|
197
196
|
}
|
|
198
197
|
|
|
199
|
-
// A worklet
|
|
200
|
-
//
|
|
201
|
-
//
|
|
202
|
-
// chunks pushed before it and runs entry startup with every module present
|
|
203
|
-
// (see ImportScriptsChunkLoadingRuntimeModule).
|
|
198
|
+
// A worklet loads no chunks at runtime, so every reachable one is pre-added
|
|
199
|
+
// from the calling scope. The runtime chunk goes last, installing what came
|
|
200
|
+
// before it and running startup with every module present.
|
|
204
201
|
/** @type {(string | number)[]} */
|
|
205
202
|
const restChunkIds = [];
|
|
206
203
|
for (const chunk of referencedChunks) {
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
+
const { toError } = require("../ErrorHelpers");
|
|
8
9
|
const makeSerializable = require("../util/makeSerializable");
|
|
9
10
|
const WebpackError = require("./WebpackError");
|
|
10
11
|
|
|
@@ -67,13 +68,13 @@ makeSerializable(HookWebpackError, "webpack/lib/errors/HookWebpackError");
|
|
|
67
68
|
|
|
68
69
|
/**
|
|
69
70
|
* Creates webpack error.
|
|
70
|
-
* @param {
|
|
71
|
+
* @param {EXPECTED_ANY} error what a plugin failed with
|
|
71
72
|
* @param {string} hook name of the hook
|
|
72
73
|
* @returns {WebpackError} a webpack error
|
|
73
74
|
*/
|
|
74
75
|
const makeWebpackError = (error, hook) => {
|
|
75
76
|
if (error instanceof WebpackError) return error;
|
|
76
|
-
return new HookWebpackError(error, hook);
|
|
77
|
+
return new HookWebpackError(toError(error), hook);
|
|
77
78
|
};
|
|
78
79
|
|
|
79
80
|
HookWebpackError.makeWebpackError = makeWebpackError;
|
|
@@ -335,11 +335,9 @@ class LazyCompilationProxyModule extends Module {
|
|
|
335
335
|
block.addDependency(dep);
|
|
336
336
|
this.addBlock(block);
|
|
337
337
|
} else if (hasClosureLibrary(compilation.options.output)) {
|
|
338
|
-
// Reserve statically
|
|
339
|
-
//
|
|
340
|
-
//
|
|
341
|
-
// Once the proxy activates and the lazily-built module references those
|
|
342
|
-
// externals, the identifiers resolve normally instead of throwing.
|
|
338
|
+
// Reserve the statically declared externals on the inactive proxy, so the
|
|
339
|
+
// entry chunk's library wrapper already exposes their closure identifiers
|
|
340
|
+
// and they resolve rather than throw once the proxy activates.
|
|
343
341
|
const requests = collectStaticExternalRequests(
|
|
344
342
|
options.externals,
|
|
345
343
|
this.layer
|
|
@@ -226,12 +226,9 @@ const CHUNK_URL_SENTINEL_REGEXP =
|
|
|
226
226
|
const HTML_PAGE_URL_SENTINEL_REGEXP =
|
|
227
227
|
/__WEBPACK_HTML_PAGE_URL__([0-9a-f]+)__END__/g;
|
|
228
228
|
|
|
229
|
-
// Sentinel for a URL-referenced asset
|
|
230
|
-
//
|
|
231
|
-
//
|
|
232
|
-
// HtmlEntry deps run *while* the HTML module is being codegen'd — the asset
|
|
233
|
-
// module's own codegen might not have completed yet. Keyed by the asset
|
|
234
|
-
// module's identifier, hex-encoded so any character in it is safe in a URL.
|
|
229
|
+
// Sentinel for a URL-referenced asset in a resource-hint `<link>`, resolved at
|
|
230
|
+
// `HtmlModulesPlugin` render because HtmlEntry deps run while the HTML module
|
|
231
|
+
// is codegen'd, before the asset's own. Keyed by hex-encoded identifier.
|
|
235
232
|
const ASSET_URL_SENTINEL_REGEXP =
|
|
236
233
|
/__WEBPACK_HTML_ASSET_URL__([0-9a-f]+)__END__/g;
|
|
237
234
|
|
|
@@ -240,11 +237,9 @@ const ASSET_URL_SENTINEL_REGEXP =
|
|
|
240
237
|
/** @type {WeakSet<Compilation>} */
|
|
241
238
|
const integritySentinelCompilations = new WeakSet();
|
|
242
239
|
|
|
243
|
-
// Matches the whole ` integrity="<sentinel>"
|
|
244
|
-
//
|
|
245
|
-
//
|
|
246
|
-
// optional and back-referenced to keep the pair matched; the replacement always
|
|
247
|
-
// re-quotes, since an SRI list carries spaces and `=` padding.
|
|
240
|
+
// Matches the whole ` integrity="<sentinel>"`, so the attribute can be dropped
|
|
241
|
+
// when the per-asset `integrity` returns `false`. Minification runs first and
|
|
242
|
+
// may have unquoted it, hence the optional back-referenced quote.
|
|
248
243
|
const INTEGRITY_SENTINEL_REGEXP =
|
|
249
244
|
/ integrity=(["']?)__WEBPACK_HTML_INTEGRITY__([0-9a-f]+)__([a-z]+)__END__\1/g;
|
|
250
245
|
|
|
@@ -253,10 +248,9 @@ const INTEGRITY_SENTINEL_REGEXP =
|
|
|
253
248
|
const INTEGRITY_SENTINEL_STRIP_REGEXP =
|
|
254
249
|
/ integrity=(\\?["']|)__WEBPACK_HTML_INTEGRITY__[0-9a-f]+__[a-z]+__END__\1/g;
|
|
255
250
|
|
|
256
|
-
// The trailing `(?:__<hash>)?` is the inlined chunk's content hash, embedded
|
|
257
|
-
//
|
|
258
|
-
//
|
|
259
|
-
// resolver ignores it.
|
|
251
|
+
// The trailing `(?:__<hash>)?` is the inlined chunk's content hash, embedded so
|
|
252
|
+
// the host page's bytes and `[contenthash]` change with the inlined content.
|
|
253
|
+
// The resolver ignores it.
|
|
260
254
|
const INLINE_SENTINEL_REGEXP =
|
|
261
255
|
/__WEBPACK_HTML_INLINE__([0-9a-f]+)__([a-z]+)(?:__[0-9a-f]+)?__END__/g;
|
|
262
256
|
|
|
@@ -449,12 +443,9 @@ class HtmlGenerator extends Generator {
|
|
|
449
443
|
const url =
|
|
450
444
|
/** @type {Record<string, string | undefined> | undefined} */
|
|
451
445
|
(data.get("url"));
|
|
452
|
-
// Prefer the `asset-url` channel
|
|
453
|
-
//
|
|
454
|
-
//
|
|
455
|
-
// `__webpack_require__.p + "…"`); for those we reconstruct the URL
|
|
456
|
-
// from the emitted `filename` + `PUBLIC_PATH_AUTO` so the same
|
|
457
|
-
// undo-path substitution runs at asset render.
|
|
446
|
+
// Prefer the `asset-url` channel, which is the real URL string. An asset
|
|
447
|
+
// reached only from JS has none — its URL is a JS expression — so rebuild
|
|
448
|
+
// one from `filename` and let the undo-path substitution run.
|
|
458
449
|
if (url && url["asset-url"]) return url["asset-url"];
|
|
459
450
|
const filename = /** @type {string | undefined} */ (data.get("filename"));
|
|
460
451
|
if (filename) return `${PUBLIC_PATH_AUTO}${filename}`;
|
|
@@ -693,10 +684,9 @@ class HtmlGenerator extends Generator {
|
|
|
693
684
|
bodyDepth++;
|
|
694
685
|
}
|
|
695
686
|
},
|
|
696
|
-
// Collected on exit
|
|
697
|
-
// closes
|
|
698
|
-
//
|
|
699
|
-
// exiting keeps them in source order.
|
|
687
|
+
// Collected on exit, since an element's `end` is final only once it
|
|
688
|
+
// closes. `script`, `style`, `link` and `meta` never nest in each
|
|
689
|
+
// other, so exiting keeps them in source order.
|
|
700
690
|
exit: (path) => {
|
|
701
691
|
const name = path.tagName();
|
|
702
692
|
if (name === "head") {
|
|
@@ -1058,12 +1048,9 @@ class HtmlGenerator extends Generator {
|
|
|
1058
1048
|
this._moduleGraph = moduleGraph;
|
|
1059
1049
|
/** @type {((module: NormalModule) => boolean) | undefined} */
|
|
1060
1050
|
this._isPageOnly = isPageOnly;
|
|
1061
|
-
// Raw
|
|
1062
|
-
//
|
|
1063
|
-
// `
|
|
1064
|
-
// Set — created once per call and passed to every type's `generate()`,
|
|
1065
|
-
// so it uniquely scopes the cache to one module's one code generation
|
|
1066
|
-
// and releases with it. The two passes differ only in `undoPath`.
|
|
1051
|
+
// Raw render shared between the JS and HTML passes of one `codeGeneration()`
|
|
1052
|
+
// call, which differ only in `undoPath`. Keyed by that call's
|
|
1053
|
+
// `runtimeRequirements` Set, so the entry is scoped to it and releases with it.
|
|
1067
1054
|
/** @type {WeakMap<RuntimeRequirements, string>} */
|
|
1068
1055
|
this._rawRenderCache = new WeakMap();
|
|
1069
1056
|
}
|
|
@@ -1075,11 +1062,9 @@ class HtmlGenerator extends Generator {
|
|
|
1075
1062
|
* @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
|
|
1076
1063
|
*/
|
|
1077
1064
|
getConcatenationBailoutReason(module, context) {
|
|
1078
|
-
// The HMR shim references the per-module `module.hot
|
|
1079
|
-
//
|
|
1080
|
-
//
|
|
1081
|
-
// would target the wrong module id. Bail out of concatenation so the
|
|
1082
|
-
// HMR-aware HTML module keeps its own module scope.
|
|
1065
|
+
// The HMR shim references the per-module `module.hot`, and a concatenated
|
|
1066
|
+
// file shares one `module`, so the self-accept wiring would target the wrong
|
|
1067
|
+
// id. Bail out, keeping the module's own scope.
|
|
1083
1068
|
if (module.hot) {
|
|
1084
1069
|
return "HTML module needs its own module scope for HMR";
|
|
1085
1070
|
}
|
|
@@ -1278,10 +1263,9 @@ class HtmlGenerator extends Generator {
|
|
|
1278
1263
|
* @returns {string} the rewritten HTML
|
|
1279
1264
|
*/
|
|
1280
1265
|
_renderHtml(module, generateContext, undoPath) {
|
|
1281
|
-
//
|
|
1282
|
-
//
|
|
1283
|
-
//
|
|
1284
|
-
// passes diverge only in the `[webpack/auto]` substitution below.
|
|
1266
|
+
// No dependency template branches on `type` or writes
|
|
1267
|
+
// `runtimeRequirements`, so the raw render is computed once per
|
|
1268
|
+
// `codeGeneration()`; the passes diverge only in the substitution below.
|
|
1285
1269
|
const cacheKey = generateContext.runtimeRequirements;
|
|
1286
1270
|
let rawContent = this._rawRenderCache.get(cacheKey);
|
|
1287
1271
|
if (rawContent === undefined) {
|
|
@@ -1345,11 +1329,9 @@ class HtmlGenerator extends Generator {
|
|
|
1345
1329
|
|
|
1346
1330
|
/** @type {string} */
|
|
1347
1331
|
let sourceContent;
|
|
1348
|
-
// `module.hot`
|
|
1349
|
-
//
|
|
1350
|
-
//
|
|
1351
|
-
// would target the wrong id) — `getConcatenationBailoutReason` keeps
|
|
1352
|
-
// us out of concatenation in that case.
|
|
1332
|
+
// `module.hot` marks HMR being enabled, and concatenation merges into a
|
|
1333
|
+
// parent's scope where `module.hot.accept` would target the wrong id.
|
|
1334
|
+
// `getConcatenationBailoutReason` keeps such a module out of it.
|
|
1353
1335
|
if (generateContext.concatenationScope && !module.hot) {
|
|
1354
1336
|
generateContext.concatenationScope.registerNamespaceExport(
|
|
1355
1337
|
ConcatenationScope.NAMESPACE_OBJECT_EXPORT
|
|
@@ -1423,15 +1405,11 @@ class HtmlGenerator extends Generator {
|
|
|
1423
1405
|
const acceptBlock = extracting
|
|
1424
1406
|
? [
|
|
1425
1407
|
"module.hot.accept();",
|
|
1426
|
-
//
|
|
1427
|
-
//
|
|
1428
|
-
//
|
|
1429
|
-
//
|
|
1430
|
-
//
|
|
1431
|
-
// `<body>`/`</body>`/`<title>` inside a comment can no
|
|
1432
|
-
// longer fool the tag regexes (the non-greedy `*?` would
|
|
1433
|
-
// otherwise stop at the FIRST `</body>` it sees, even one
|
|
1434
|
-
// inside a comment).
|
|
1408
|
+
// WHY: a `</body>` inside a comment stops the non-greedy `*?` at the
|
|
1409
|
+
// wrong place, so comments are masked before any tag regex runs.
|
|
1410
|
+
// Masking rather than deleting keeps offsets stable, so the body and
|
|
1411
|
+
// title can still be sliced out of the original HTML with their
|
|
1412
|
+
// comments intact.
|
|
1435
1413
|
`${declare} __webpack_mask_comments__ = ${runtimeTemplate.returningFunction(
|
|
1436
1414
|
`h.replace(/<!--[\\s\\S]*?-->/g, ${runtimeTemplate.returningFunction(
|
|
1437
1415
|
'c.replace(/[^\\n]/g, " ")',
|
|
@@ -1475,9 +1453,8 @@ class HtmlGenerator extends Generator {
|
|
|
1475
1453
|
]
|
|
1476
1454
|
)};`,
|
|
1477
1455
|
// A `<script>` parsed out of a string carries the already-started flag,
|
|
1478
|
-
// so appending
|
|
1479
|
-
//
|
|
1480
|
-
// replaces would have done.
|
|
1456
|
+
// so appending it would never run. A fresh one with the same attributes
|
|
1457
|
+
// and body does, as the reload this replaces would have.
|
|
1481
1458
|
`${declare} __webpack_revive_script__ = ${runtimeTemplate.basicFunction(
|
|
1482
1459
|
"node",
|
|
1483
1460
|
[
|
|
@@ -1493,11 +1470,9 @@ class HtmlGenerator extends Generator {
|
|
|
1493
1470
|
"return script;"
|
|
1494
1471
|
]
|
|
1495
1472
|
)};`,
|
|
1496
|
-
// Apply only the difference between the two authored heads
|
|
1497
|
-
//
|
|
1498
|
-
//
|
|
1499
|
-
// tear them down while a delta never touches them. Reports whether it
|
|
1500
|
-
// could — the caller reloads when it could not.
|
|
1473
|
+
// Apply only the difference between the two authored heads: the
|
|
1474
|
+
// runtime's own injected tags are in neither string, so replacing
|
|
1475
|
+
// `document.head` wholesale would tear them down where a delta cannot.
|
|
1501
1476
|
`${declare} __webpack_patch_head__ = ${runtimeTemplate.basicFunction(
|
|
1502
1477
|
"oldHtml, newHtml",
|
|
1503
1478
|
[
|
|
@@ -1533,14 +1508,12 @@ class HtmlGenerator extends Generator {
|
|
|
1533
1508
|
`${declare} removed = surplus(oldChildren, newChildren);`,
|
|
1534
1509
|
`${declare} added = surplus(newChildren, oldChildren);`,
|
|
1535
1510
|
"if (removed.length === 0 && added.length === 0) return true;",
|
|
1536
|
-
//
|
|
1537
|
-
//
|
|
1538
|
-
// `type` that is neither a JavaScript MIME
|
|
1539
|
-
// `importmap`
|
|
1540
|
-
//
|
|
1541
|
-
//
|
|
1542
|
-
// Every JavaScript MIME essence ends in `script`, and a type
|
|
1543
|
-
// nothing here recognizes falls back to the reload.
|
|
1511
|
+
// WHY: a script that has run cannot be un-run, so dropping one is the
|
|
1512
|
+
// single edit still worth a reload — but only a script that ran. A
|
|
1513
|
+
// `type` that is neither a JavaScript MIME essence, all of which end
|
|
1514
|
+
// in `script`, nor `module`, `importmap` or `speculationrules` is a
|
|
1515
|
+
// data block the browser never executed, as safe to remove as a
|
|
1516
|
+
// `<meta>`. An unrecognized type falls back to the reload.
|
|
1544
1517
|
`if (removed.some(${runtimeTemplate.basicFunction("node", [
|
|
1545
1518
|
'if (node.nodeName !== "SCRIPT") return false;',
|
|
1546
1519
|
`${declare} type = (node.getAttribute("type") || "").trim().toLowerCase();`,
|
|
@@ -1564,11 +1537,9 @@ class HtmlGenerator extends Generator {
|
|
|
1564
1537
|
]),
|
|
1565
1538
|
"}",
|
|
1566
1539
|
`for (${mutable} i = 0; i < live.length; i++) document.head.removeChild(live[i]);`,
|
|
1567
|
-
// Pair each retained element with its live node, scanning
|
|
1568
|
-
//
|
|
1569
|
-
//
|
|
1570
|
-
// cannot express falls back to the reload. Injected nodes simply
|
|
1571
|
-
// never match, so they neither anchor nor block anything.
|
|
1540
|
+
// Pair each retained element with its live node, scanning forward
|
|
1541
|
+
// only: a moved element then finds no match and falls back to the
|
|
1542
|
+
// reload, while an injected node never matches either way.
|
|
1572
1543
|
`${declare} liveByNew = [];`,
|
|
1573
1544
|
`${mutable} searchFrom = 0;`,
|
|
1574
1545
|
`for (${mutable} i = 0; i < newChildren.length; i++) {`,
|
|
@@ -1648,13 +1619,22 @@ class HtmlGenerator extends Generator {
|
|
|
1648
1619
|
*/
|
|
1649
1620
|
generateError(error, module, generateContext) {
|
|
1650
1621
|
if (generateContext.type === HTML_TYPE) {
|
|
1651
|
-
// Strip `<`, `>`, `--` runs from
|
|
1652
|
-
const safe =
|
|
1622
|
+
// Strip `<`, `>`, `--` runs from the message so it can't escape the comment.
|
|
1623
|
+
const safe = Generator.buildErrorMessage(
|
|
1624
|
+
error,
|
|
1625
|
+
generateContext.runtimeTemplate.requestShortener
|
|
1626
|
+
)
|
|
1653
1627
|
.replace(/[<>]/g, "")
|
|
1654
1628
|
.replace(/-{2,}/g, (m) => `${"-".repeat(m.length - 1)} `);
|
|
1655
1629
|
return new RawSource(`<!-- webpack error: ${safe} -->`);
|
|
1656
1630
|
}
|
|
1657
|
-
return new RawSource(
|
|
1631
|
+
return new RawSource(
|
|
1632
|
+
Generator.throwBuildErrorCode(
|
|
1633
|
+
error,
|
|
1634
|
+
undefined,
|
|
1635
|
+
generateContext.runtimeTemplate.requestShortener
|
|
1636
|
+
)
|
|
1637
|
+
);
|
|
1658
1638
|
}
|
|
1659
1639
|
|
|
1660
1640
|
/**
|
|
@@ -1664,10 +1644,9 @@ class HtmlGenerator extends Generator {
|
|
|
1664
1644
|
*/
|
|
1665
1645
|
updateHash(hash, updateHashContext) {
|
|
1666
1646
|
hash.update("html");
|
|
1667
|
-
//
|
|
1668
|
-
// `extracting` branch
|
|
1669
|
-
//
|
|
1670
|
-
// One `_shouldExtract` walk covers both checks (expose = extract ∪ inline).
|
|
1647
|
+
// The source-type set turns on html-type exposure and the HMR shim's
|
|
1648
|
+
// `extracting` branch on the emit decision. They differ only for
|
|
1649
|
+
// `"inline"`, which exposes html without emitting, so hash both.
|
|
1671
1650
|
const extract = this._shouldExtract(updateHashContext.module);
|
|
1672
1651
|
if (extract || this.options.extract === "inline") {
|
|
1673
1652
|
hash.update("html-type");
|