webpack 5.85.0 → 5.88.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +5 -2
- package/lib/APIPlugin.js +150 -99
- package/lib/AsyncDependenciesBlock.js +3 -3
- package/lib/BannerPlugin.js +2 -1
- package/lib/CaseSensitiveModulesWarning.js +3 -1
- package/lib/Chunk.js +35 -17
- package/lib/ChunkGraph.js +4 -4
- package/lib/ChunkGroup.js +20 -9
- package/lib/CompatibilityPlugin.js +50 -30
- package/lib/Compilation.js +2 -1
- package/lib/Compiler.js +10 -9
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +11 -1
- package/lib/ConstPlugin.js +73 -32
- package/lib/ContextModule.js +8 -3
- package/lib/ContextModuleFactory.js +1 -0
- package/lib/ContextReplacementPlugin.js +13 -0
- package/lib/DelegatedModule.js +15 -3
- package/lib/DelegatedModuleFactoryPlugin.js +6 -0
- package/lib/DependenciesBlock.js +1 -1
- package/lib/Dependency.js +11 -5
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DllEntryPlugin.js +11 -1
- package/lib/DllModule.js +6 -0
- package/lib/DllReferencePlugin.js +13 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ErrorHelpers.js +1 -0
- package/lib/EvalSourceMapDevToolPlugin.js +6 -1
- package/lib/ExportsInfo.js +22 -4
- package/lib/ExportsInfoApiPlugin.js +14 -5
- package/lib/ExternalModule.js +20 -8
- package/lib/FileSystemInfo.js +52 -24
- package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
- package/lib/FlagDependencyUsagePlugin.js +3 -1
- package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
- package/lib/Generator.js +7 -0
- package/lib/HotModuleReplacementPlugin.js +8 -0
- package/lib/InitFragment.js +28 -5
- package/lib/JavascriptMetaInfoPlugin.js +11 -6
- package/lib/LibManifestPlugin.js +20 -4
- package/lib/Module.js +14 -3
- package/lib/ModuleDependencyError.js +4 -2
- package/lib/ModuleDependencyWarning.js +4 -2
- package/lib/ModuleGraph.js +31 -24
- package/lib/ModuleGraphConnection.js +19 -6
- package/lib/ModuleInfoHeaderPlugin.js +9 -2
- package/lib/ModuleNotFoundError.js +5 -2
- package/lib/ModuleProfile.js +1 -0
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/ModuleStoreError.js +2 -1
- package/lib/ModuleTypeConstants.js +7 -0
- package/lib/MultiWatching.js +4 -0
- package/lib/NodeStuffPlugin.js +32 -6
- package/lib/ProgressPlugin.js +71 -15
- package/lib/ProvidePlugin.js +13 -4
- package/lib/RawModule.js +3 -1
- package/lib/RequireJsStuffPlugin.js +7 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimeModule.js +3 -3
- package/lib/RuntimePlugin.js +6 -3
- package/lib/RuntimeTemplate.js +22 -4
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
- package/lib/SourceMapDevToolPlugin.js +7 -2
- package/lib/UseStrictPlugin.js +10 -3
- package/lib/Watching.js +62 -25
- package/lib/WebpackError.js +6 -5
- package/lib/WebpackIsIncludedPlugin.js +6 -4
- package/lib/WebpackOptionsApply.js +4 -2
- package/lib/WebpackOptionsDefaulter.js +10 -3
- package/lib/asset/AssetGenerator.js +2 -1
- package/lib/asset/AssetParser.js +11 -6
- package/lib/asset/AssetSourceParser.js +8 -3
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
- package/lib/buildChunkGraph.js +37 -21
- package/lib/cache/IdleFileCachePlugin.js +2 -1
- package/lib/cache/PackFileCacheStrategy.js +53 -22
- package/lib/config/browserslistTargetHandler.js +7 -7
- package/lib/config/defaults.js +43 -26
- package/lib/container/RemoteRuntimeModule.js +1 -1
- package/lib/css/CssExportsGenerator.js +9 -0
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssLoadingRuntimeModule.js +43 -19
- package/lib/css/CssModulesPlugin.js +42 -14
- package/lib/css/CssParser.js +22 -0
- package/lib/dependencies/AMDDefineDependency.js +34 -4
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
- package/lib/dependencies/AMDRuntimeModules.js +2 -2
- package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
- package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
- package/lib/dependencies/CommonJsPlugin.js +13 -8
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
- package/lib/dependencies/ConstDependency.js +2 -2
- package/lib/dependencies/ContextDependency.js +7 -2
- package/lib/dependencies/CssImportDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
- package/lib/dependencies/CssUrlDependency.js +3 -3
- package/lib/dependencies/DllEntryDependency.js +5 -0
- package/lib/dependencies/DynamicExports.js +10 -6
- package/lib/dependencies/ExportsInfoDependency.js +14 -4
- package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExports.js +9 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +40 -27
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +31 -21
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
- package/lib/dependencies/ImportDependency.js +5 -3
- package/lib/dependencies/ImportEagerDependency.js +5 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
- package/lib/dependencies/ImportMetaPlugin.js +31 -15
- package/lib/dependencies/ImportParserPlugin.js +62 -25
- package/lib/dependencies/ImportWeakDependency.js +5 -3
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/ModuleDependency.js +1 -1
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
- package/lib/dependencies/ProvidedDependency.js +4 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
- package/lib/dependencies/RequireHeaderDependency.js +4 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
- package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
- package/lib/dependencies/SystemPlugin.js +17 -5
- package/lib/dependencies/SystemRuntimeModule.js +1 -1
- package/lib/dependencies/URLDependency.js +2 -2
- package/lib/dependencies/URLPlugin.js +9 -4
- package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +59 -22
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -0
- package/lib/javascript/BasicEvaluatedExpression.js +28 -19
- package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
- package/lib/javascript/JavascriptModulesPlugin.js +25 -5
- package/lib/javascript/JavascriptParser.js +157 -85
- package/lib/javascript/JavascriptParserHelpers.js +37 -15
- package/lib/json/JsonData.js +2 -2
- package/lib/json/JsonParser.js +25 -12
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +13 -1
- package/lib/library/EnableLibraryPlugin.js +4 -0
- package/lib/library/SystemLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +20 -2
- package/lib/logging/runtime.js +1 -1
- package/lib/logging/truncateArgs.js +4 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
- package/lib/optimize/AggressiveMergingPlugin.js +8 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
- package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
- package/lib/optimize/InnerGraph.js +5 -5
- package/lib/optimize/InnerGraphPlugin.js +2 -1
- package/lib/optimize/LimitChunkCountPlugin.js +29 -4
- package/lib/optimize/MangleExportsPlugin.js +1 -1
- package/lib/optimize/MinMaxSizeWarning.js +5 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
- package/lib/optimize/RealContentHashPlugin.js +80 -30
- package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
- package/lib/optimize/RuntimeChunkPlugin.js +9 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
- package/lib/optimize/SplitChunksPlugin.js +71 -31
- package/lib/performance/SizeLimitsPlugin.js +7 -4
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
- package/lib/rules/BasicEffectRulePlugin.js +4 -0
- package/lib/rules/BasicMatcherRulePlugin.js +5 -0
- package/lib/rules/RuleSetCompiler.js +3 -3
- package/lib/rules/UseEffectRulePlugin.js +6 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +8 -5
- package/lib/runtime/AutoPublicPathRuntimeModule.js +4 -2
- package/lib/runtime/BaseUriRuntimeModule.js +3 -3
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
- package/lib/runtime/CompatRuntimeModule.js +7 -2
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
- package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
- package/lib/runtime/EnsureChunkRuntimeModule.js +15 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -10
- package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
- package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -2
- package/lib/runtime/GlobalRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
- package/lib/runtime/LoadScriptRuntimeModule.js +64 -48
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
- package/lib/runtime/NonceRuntimeModule.js +1 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
- package/lib/runtime/PublicPathRuntimeModule.js +4 -2
- package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
- package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -3
- package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -2
- package/lib/runtime/SystemContextRuntimeModule.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +143 -1
- package/lib/serialization/ErrorObjectSerializer.js +3 -0
- package/lib/serialization/ObjectMiddleware.js +9 -3
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +14 -5
- package/lib/sharing/ProvideSharedDependency.js +11 -0
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +22 -21
- package/lib/sharing/ShareRuntimeModule.js +12 -5
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/sharing/utils.js +32 -5
- package/lib/util/AsyncQueue.js +4 -2
- package/lib/util/ParallelismFactorCalculator.js +10 -0
- package/lib/util/Semaphore.js +1 -1
- package/lib/util/StackedCacheMap.js +1 -1
- package/lib/util/URLAbsoluteSpecifier.js +1 -1
- package/lib/util/createHash.js +30 -9
- package/lib/util/deprecation.js +10 -3
- package/lib/util/deterministicGrouping.js +50 -11
- package/lib/util/findGraphRoots.js +4 -2
- package/lib/util/memoize.js +3 -3
- package/lib/util/processAsyncTree.js +7 -1
- package/lib/util/registerExternalSerializer.js +1 -1
- package/lib/util/runtime.js +84 -21
- package/lib/util/semver.js +1 -0
- package/lib/util/smartGrouping.js +1 -1
- package/lib/validateSchema.js +6 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +6 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +14 -7
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
- package/lib/wasm-sync/WebAssemblyParser.js +6 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +14 -4
- package/lib/webpack.js +11 -2
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -16
- package/module.d.ts +1 -0
- package/package.json +5 -4
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +52 -6
- package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
- package/schemas/plugins/css/CssParserOptions.json +1 -1
- package/types.d.ts +606 -292
@@ -8,16 +8,19 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
8
8
|
const Template = require("../Template");
|
9
9
|
const HelperRuntimeModule = require("./HelperRuntimeModule");
|
10
10
|
|
11
|
+
/** @typedef {import("../Compilation")} Compilation */
|
12
|
+
|
11
13
|
class DefinePropertyGettersRuntimeModule extends HelperRuntimeModule {
|
12
14
|
constructor() {
|
13
15
|
super("define property getters");
|
14
16
|
}
|
15
17
|
|
16
18
|
/**
|
17
|
-
* @returns {string} runtime code
|
19
|
+
* @returns {string | null} runtime code
|
18
20
|
*/
|
19
21
|
generate() {
|
20
|
-
const
|
22
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
23
|
+
const { runtimeTemplate } = compilation;
|
21
24
|
const fn = RuntimeGlobals.definePropertyGetters;
|
22
25
|
return Template.asString([
|
23
26
|
"// define getter functions for harmony exports",
|
@@ -8,6 +8,8 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
8
8
|
const RuntimeModule = require("../RuntimeModule");
|
9
9
|
const Template = require("../Template");
|
10
10
|
|
11
|
+
/** @typedef {import("../Compilation")} Compilation */
|
12
|
+
|
11
13
|
class EnsureChunkRuntimeModule extends RuntimeModule {
|
12
14
|
/**
|
13
15
|
* @param {ReadonlySet<string>} runtimeRequirements runtime requirements
|
@@ -18,23 +20,32 @@ class EnsureChunkRuntimeModule extends RuntimeModule {
|
|
18
20
|
}
|
19
21
|
|
20
22
|
/**
|
21
|
-
* @returns {string} runtime code
|
23
|
+
* @returns {string | null} runtime code
|
22
24
|
*/
|
23
25
|
generate() {
|
24
|
-
const
|
26
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
27
|
+
const { runtimeTemplate } = compilation;
|
25
28
|
// Check if there are non initial chunks which need to be imported using require-ensure
|
26
29
|
if (this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)) {
|
30
|
+
const withFetchPriority = this.runtimeRequirements.has(
|
31
|
+
RuntimeGlobals.hasFetchPriority
|
32
|
+
);
|
27
33
|
const handlers = RuntimeGlobals.ensureChunkHandlers;
|
28
34
|
return Template.asString([
|
29
35
|
`${handlers} = {};`,
|
30
36
|
"// This file contains only the entry chunk.",
|
31
37
|
"// The chunk loading function for additional chunks",
|
32
38
|
`${RuntimeGlobals.ensureChunk} = ${runtimeTemplate.basicFunction(
|
33
|
-
|
39
|
+
`chunkId${withFetchPriority ? ", fetchPriority" : ""}`,
|
34
40
|
[
|
35
41
|
`return Promise.all(Object.keys(${handlers}).reduce(${runtimeTemplate.basicFunction(
|
36
42
|
"promises, key",
|
37
|
-
[
|
43
|
+
[
|
44
|
+
`${handlers}[key](chunkId, promises${
|
45
|
+
withFetchPriority ? ", fetchPriority" : ""
|
46
|
+
});`,
|
47
|
+
"return promises;"
|
48
|
+
]
|
38
49
|
)}, []));`
|
39
50
|
]
|
40
51
|
)};`
|
@@ -10,6 +10,7 @@ const Template = require("../Template");
|
|
10
10
|
const { first } = require("../util/SetHelpers");
|
11
11
|
|
12
12
|
/** @typedef {import("../Chunk")} Chunk */
|
13
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
13
14
|
/** @typedef {import("../Compilation")} Compilation */
|
14
15
|
/** @typedef {import("../Compilation").AssetInfo} AssetInfo */
|
15
16
|
/** @typedef {import("../Compilation").PathData} PathData */
|
@@ -34,18 +35,13 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
|
34
35
|
}
|
35
36
|
|
36
37
|
/**
|
37
|
-
* @returns {string} runtime code
|
38
|
+
* @returns {string | null} runtime code
|
38
39
|
*/
|
39
40
|
generate() {
|
40
|
-
const {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
contentType,
|
45
|
-
getFilenameForChunk,
|
46
|
-
allChunks,
|
47
|
-
compilation
|
48
|
-
} = this;
|
41
|
+
const { global, contentType, getFilenameForChunk, allChunks } = this;
|
42
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
43
|
+
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
44
|
+
const chunk = /** @type {Chunk} */ (this.chunk);
|
49
45
|
const { runtimeTemplate } = compilation;
|
50
46
|
|
51
47
|
/** @type {Map<string | FilenameFunction, Set<Chunk>>} */
|
@@ -16,12 +16,13 @@ class GetFullHashRuntimeModule extends RuntimeModule {
|
|
16
16
|
}
|
17
17
|
|
18
18
|
/**
|
19
|
-
* @returns {string} runtime code
|
19
|
+
* @returns {string | null} runtime code
|
20
20
|
*/
|
21
21
|
generate() {
|
22
|
-
const
|
22
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
23
|
+
const { runtimeTemplate } = compilation;
|
23
24
|
return `${RuntimeGlobals.getFullHash} = ${runtimeTemplate.returningFunction(
|
24
|
-
JSON.stringify(
|
25
|
+
JSON.stringify(compilation.hash || "XXXX")
|
25
26
|
)}`;
|
26
27
|
}
|
27
28
|
}
|
@@ -8,6 +8,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
8
8
|
const RuntimeModule = require("../RuntimeModule");
|
9
9
|
const Template = require("../Template");
|
10
10
|
|
11
|
+
/** @typedef {import("../Chunk")} Chunk */
|
11
12
|
/** @typedef {import("../Compilation")} Compilation */
|
12
13
|
|
13
14
|
class GetMainFilenameRuntimeModule extends RuntimeModule {
|
@@ -23,10 +24,12 @@ class GetMainFilenameRuntimeModule extends RuntimeModule {
|
|
23
24
|
}
|
24
25
|
|
25
26
|
/**
|
26
|
-
* @returns {string} runtime code
|
27
|
+
* @returns {string | null} runtime code
|
27
28
|
*/
|
28
29
|
generate() {
|
29
|
-
const { global, filename
|
30
|
+
const { global, filename } = this;
|
31
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
32
|
+
const chunk = /** @type {Chunk} */ (this.chunk);
|
30
33
|
const { runtimeTemplate } = compilation;
|
31
34
|
const url = compilation.getPath(JSON.stringify(filename), {
|
32
35
|
hash: `" + ${RuntimeGlobals.getFullHash}() + "`,
|
@@ -8,6 +8,8 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
8
8
|
const Template = require("../Template");
|
9
9
|
const HelperRuntimeModule = require("./HelperRuntimeModule");
|
10
10
|
|
11
|
+
/** @typedef {import("../Compilation")} Compilation */
|
12
|
+
|
11
13
|
class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
|
12
14
|
/**
|
13
15
|
* @param {ReadonlySet<string>} runtimeRequirements runtime requirements
|
@@ -18,10 +20,10 @@ class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
|
|
18
20
|
}
|
19
21
|
|
20
22
|
/**
|
21
|
-
* @returns {string} runtime code
|
23
|
+
* @returns {string | null} runtime code
|
22
24
|
*/
|
23
25
|
generate() {
|
24
|
-
const
|
26
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
25
27
|
const { runtimeTemplate, outputOptions } = compilation;
|
26
28
|
const { trustedTypes } = outputOptions;
|
27
29
|
const fn = RuntimeGlobals.getTrustedTypesPolicy;
|
@@ -9,16 +9,19 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
9
9
|
const RuntimeModule = require("../RuntimeModule");
|
10
10
|
const Template = require("../Template");
|
11
11
|
|
12
|
+
/** @typedef {import("../Compilation")} Compilation */
|
13
|
+
|
12
14
|
class HasOwnPropertyRuntimeModule extends RuntimeModule {
|
13
15
|
constructor() {
|
14
16
|
super("hasOwnProperty shorthand");
|
15
17
|
}
|
16
18
|
|
17
19
|
/**
|
18
|
-
* @returns {string} runtime code
|
20
|
+
* @returns {string | null} runtime code
|
19
21
|
*/
|
20
22
|
generate() {
|
21
|
-
const
|
23
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
24
|
+
const { runtimeTemplate } = compilation;
|
22
25
|
|
23
26
|
return Template.asString([
|
24
27
|
`${RuntimeGlobals.hasOwnProperty} = ${runtimeTemplate.returningFunction(
|
@@ -44,17 +44,19 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
|
|
44
44
|
|
45
45
|
/**
|
46
46
|
* @param {boolean=} withCreateScriptUrl use create script url for trusted types
|
47
|
+
* @param {boolean=} withFetchPriority use `fetchPriority` attribute
|
47
48
|
*/
|
48
|
-
constructor(withCreateScriptUrl) {
|
49
|
+
constructor(withCreateScriptUrl, withFetchPriority) {
|
49
50
|
super("load script");
|
50
51
|
this._withCreateScriptUrl = withCreateScriptUrl;
|
52
|
+
this._withFetchPriority = withFetchPriority;
|
51
53
|
}
|
52
54
|
|
53
55
|
/**
|
54
|
-
* @returns {string} runtime code
|
56
|
+
* @returns {string | null} runtime code
|
55
57
|
*/
|
56
58
|
generate() {
|
57
|
-
const
|
59
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
58
60
|
const { runtimeTemplate, outputOptions } = compilation;
|
59
61
|
const {
|
60
62
|
scriptType,
|
@@ -81,6 +83,15 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
|
|
81
83
|
uniqueName
|
82
84
|
? 'script.setAttribute("data-webpack", dataWebpackPrefix + key);'
|
83
85
|
: "",
|
86
|
+
this._withFetchPriority
|
87
|
+
? Template.asString([
|
88
|
+
"if(fetchPriority) {",
|
89
|
+
Template.indent(
|
90
|
+
'script.setAttribute("fetchpriority", fetchPriority);'
|
91
|
+
),
|
92
|
+
"}"
|
93
|
+
])
|
94
|
+
: "",
|
84
95
|
`script.src = ${
|
85
96
|
this._withCreateScriptUrl
|
86
97
|
? `${RuntimeGlobals.createScriptUrl}(url)`
|
@@ -105,53 +116,58 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
|
|
105
116
|
? `var dataWebpackPrefix = ${JSON.stringify(uniqueName + ":")};`
|
106
117
|
: "// data-webpack is not used as build has no uniqueName",
|
107
118
|
"// loadScript function to load a script via script tag",
|
108
|
-
`${fn} = ${runtimeTemplate.basicFunction(
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
"
|
119
|
+
`${fn} = ${runtimeTemplate.basicFunction(
|
120
|
+
`url, done, key, chunkId${
|
121
|
+
this._withFetchPriority ? ", fetchPriority" : ""
|
122
|
+
}`,
|
123
|
+
[
|
124
|
+
"if(inProgress[url]) { inProgress[url].push(done); return; }",
|
125
|
+
"var script, needAttach;",
|
126
|
+
"if(key !== undefined) {",
|
127
|
+
Template.indent([
|
128
|
+
'var scripts = document.getElementsByTagName("script");',
|
129
|
+
"for(var i = 0; i < scripts.length; i++) {",
|
130
|
+
Template.indent([
|
131
|
+
"var s = scripts[i];",
|
132
|
+
`if(s.getAttribute("src") == url${
|
133
|
+
uniqueName
|
134
|
+
? ' || s.getAttribute("data-webpack") == dataWebpackPrefix + key'
|
135
|
+
: ""
|
136
|
+
}) { script = s; break; }`
|
137
|
+
]),
|
138
|
+
"}"
|
139
|
+
]),
|
140
|
+
"}",
|
141
|
+
"if(!script) {",
|
115
142
|
Template.indent([
|
116
|
-
"
|
117
|
-
|
118
|
-
uniqueName
|
119
|
-
? ' || s.getAttribute("data-webpack") == dataWebpackPrefix + key'
|
120
|
-
: ""
|
121
|
-
}) { script = s; break; }`
|
143
|
+
"needAttach = true;",
|
144
|
+
createScript.call(code, /** @type {Chunk} */ (this.chunk))
|
122
145
|
]),
|
123
|
-
"}"
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
])
|
149
|
-
),
|
150
|
-
`var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), ${loadTimeout});`,
|
151
|
-
"script.onerror = onScriptComplete.bind(null, script.onerror);",
|
152
|
-
"script.onload = onScriptComplete.bind(null, script.onload);",
|
153
|
-
"needAttach && document.head.appendChild(script);"
|
154
|
-
])};`
|
146
|
+
"}",
|
147
|
+
"inProgress[url] = [done];",
|
148
|
+
"var onScriptComplete = " +
|
149
|
+
runtimeTemplate.basicFunction(
|
150
|
+
"prev, event",
|
151
|
+
Template.asString([
|
152
|
+
"// avoid mem leaks in IE.",
|
153
|
+
"script.onerror = script.onload = null;",
|
154
|
+
"clearTimeout(timeout);",
|
155
|
+
"var doneFns = inProgress[url];",
|
156
|
+
"delete inProgress[url];",
|
157
|
+
"script.parentNode && script.parentNode.removeChild(script);",
|
158
|
+
`doneFns && doneFns.forEach(${runtimeTemplate.returningFunction(
|
159
|
+
"fn(event)",
|
160
|
+
"fn"
|
161
|
+
)});`,
|
162
|
+
"if(prev) return prev(event);"
|
163
|
+
])
|
164
|
+
),
|
165
|
+
`var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), ${loadTimeout});`,
|
166
|
+
"script.onerror = onScriptComplete.bind(null, script.onerror);",
|
167
|
+
"script.onload = onScriptComplete.bind(null, script.onload);",
|
168
|
+
"needAttach && document.head.appendChild(script);"
|
169
|
+
]
|
170
|
+
)};`
|
155
171
|
]);
|
156
172
|
}
|
157
173
|
}
|
@@ -8,16 +8,19 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
8
8
|
const Template = require("../Template");
|
9
9
|
const HelperRuntimeModule = require("./HelperRuntimeModule");
|
10
10
|
|
11
|
+
/** @typedef {import("../Compilation")} Compilation */
|
12
|
+
|
11
13
|
class MakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
12
14
|
constructor() {
|
13
15
|
super("make namespace object");
|
14
16
|
}
|
15
17
|
|
16
18
|
/**
|
17
|
-
* @returns {string} runtime code
|
19
|
+
* @returns {string | null} runtime code
|
18
20
|
*/
|
19
21
|
generate() {
|
20
|
-
const
|
22
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
23
|
+
const { runtimeTemplate } = compilation;
|
21
24
|
const fn = RuntimeGlobals.makeNamespaceObject;
|
22
25
|
return Template.asString([
|
23
26
|
"// define __esModule on exports",
|
@@ -8,16 +8,18 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
8
8
|
const RuntimeModule = require("../RuntimeModule");
|
9
9
|
const Template = require("../Template");
|
10
10
|
|
11
|
+
/** @typedef {import("../Compilation")} Compilation */
|
12
|
+
|
11
13
|
class OnChunksLoadedRuntimeModule extends RuntimeModule {
|
12
14
|
constructor() {
|
13
15
|
super("chunk loaded");
|
14
16
|
}
|
15
17
|
|
16
18
|
/**
|
17
|
-
* @returns {string} runtime code
|
19
|
+
* @returns {string | null} runtime code
|
18
20
|
*/
|
19
21
|
generate() {
|
20
|
-
const
|
22
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
21
23
|
const { runtimeTemplate } = compilation;
|
22
24
|
return Template.asString([
|
23
25
|
"var deferred = [];",
|
@@ -8,6 +8,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
8
8
|
const RuntimeModule = require("../RuntimeModule");
|
9
9
|
|
10
10
|
/** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputOptions */
|
11
|
+
/** @typedef {import("../Compilation")} Compilation */
|
11
12
|
|
12
13
|
class PublicPathRuntimeModule extends RuntimeModule {
|
13
14
|
/**
|
@@ -19,10 +20,11 @@ class PublicPathRuntimeModule extends RuntimeModule {
|
|
19
20
|
}
|
20
21
|
|
21
22
|
/**
|
22
|
-
* @returns {string} runtime code
|
23
|
+
* @returns {string | null} runtime code
|
23
24
|
*/
|
24
25
|
generate() {
|
25
|
-
const {
|
26
|
+
const { publicPath } = this;
|
27
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
26
28
|
|
27
29
|
return `${RuntimeGlobals.publicPath} = ${JSON.stringify(
|
28
30
|
compilation.getPath(publicPath || "", {
|
@@ -8,16 +8,19 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
8
8
|
const Template = require("../Template");
|
9
9
|
const HelperRuntimeModule = require("./HelperRuntimeModule");
|
10
10
|
|
11
|
+
/** @typedef {import("../Compilation")} Compilation */
|
12
|
+
|
11
13
|
class RelativeUrlRuntimeModule extends HelperRuntimeModule {
|
12
14
|
constructor() {
|
13
15
|
super("relative url");
|
14
16
|
}
|
15
17
|
|
16
18
|
/**
|
17
|
-
* @returns {string} runtime code
|
19
|
+
* @returns {string | null} runtime code
|
18
20
|
*/
|
19
21
|
generate() {
|
20
|
-
const
|
22
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
23
|
+
const { runtimeTemplate } = compilation;
|
21
24
|
return Template.asString([
|
22
25
|
`${RuntimeGlobals.relativeUrl} = function RelativeURL(url) {`,
|
23
26
|
Template.indent([
|
@@ -7,16 +7,20 @@
|
|
7
7
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
8
8
|
const RuntimeModule = require("../RuntimeModule");
|
9
9
|
|
10
|
+
/** @typedef {import("../Chunk")} Chunk */
|
11
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
12
|
+
|
10
13
|
class RuntimeIdRuntimeModule extends RuntimeModule {
|
11
14
|
constructor() {
|
12
15
|
super("runtimeId");
|
13
16
|
}
|
14
17
|
|
15
18
|
/**
|
16
|
-
* @returns {string} runtime code
|
19
|
+
* @returns {string | null} runtime code
|
17
20
|
*/
|
18
21
|
generate() {
|
19
|
-
const
|
22
|
+
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
23
|
+
const chunk = /** @type {Chunk} */ (this.chunk);
|
20
24
|
const runtime = chunk.runtime;
|
21
25
|
if (typeof runtime !== "string")
|
22
26
|
throw new Error("RuntimeIdRuntimeModule must be in a single runtime");
|
@@ -9,6 +9,10 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
9
9
|
const RuntimeModule = require("../RuntimeModule");
|
10
10
|
const Template = require("../Template");
|
11
11
|
|
12
|
+
/** @typedef {import("../Chunk")} Chunk */
|
13
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
14
|
+
/** @typedef {import("../Compilation")} Compilation */
|
15
|
+
|
12
16
|
class StartupChunkDependenciesRuntimeModule extends RuntimeModule {
|
13
17
|
/**
|
14
18
|
* @param {boolean} asyncChunkLoading use async chunk loading
|
@@ -19,16 +23,18 @@ class StartupChunkDependenciesRuntimeModule extends RuntimeModule {
|
|
19
23
|
}
|
20
24
|
|
21
25
|
/**
|
22
|
-
* @returns {string} runtime code
|
26
|
+
* @returns {string | null} runtime code
|
23
27
|
*/
|
24
28
|
generate() {
|
25
|
-
const
|
26
|
-
const
|
29
|
+
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
30
|
+
const chunk = /** @type {Chunk} */ (this.chunk);
|
27
31
|
const chunkIds = Array.from(
|
28
32
|
chunkGraph.getChunkEntryDependentChunksIterable(chunk)
|
29
33
|
).map(chunk => {
|
30
34
|
return chunk.id;
|
31
35
|
});
|
36
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
37
|
+
const { runtimeTemplate } = compilation;
|
32
38
|
return Template.asString([
|
33
39
|
`var next = ${RuntimeGlobals.startup};`,
|
34
40
|
`${RuntimeGlobals.startup} = ${runtimeTemplate.basicFunction(
|
@@ -7,6 +7,7 @@
|
|
7
7
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
8
8
|
const RuntimeModule = require("../RuntimeModule");
|
9
9
|
|
10
|
+
/** @typedef {import("../Compilation")} Compilation */
|
10
11
|
/** @typedef {import("../MainTemplate")} MainTemplate */
|
11
12
|
|
12
13
|
class StartupEntrypointRuntimeModule extends RuntimeModule {
|
@@ -19,10 +20,10 @@ class StartupEntrypointRuntimeModule extends RuntimeModule {
|
|
19
20
|
}
|
20
21
|
|
21
22
|
/**
|
22
|
-
* @returns {string} runtime code
|
23
|
+
* @returns {string | null} runtime code
|
23
24
|
*/
|
24
25
|
generate() {
|
25
|
-
const
|
26
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
26
27
|
const { runtimeTemplate } = compilation;
|
27
28
|
return `${
|
28
29
|
RuntimeGlobals.startupEntrypoint
|