webpack 5.86.0 → 5.87.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/README.md +5 -2
- package/lib/CaseSensitiveModulesWarning.js +3 -1
- package/lib/ChunkGroup.js +1 -0
- package/lib/Compiler.js +3 -1
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +11 -1
- package/lib/ConstPlugin.js +57 -29
- package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
- 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/ModuleStoreError.js +2 -1
- package/lib/ModuleTypeConstants.js +7 -0
- package/lib/MultiWatching.js +4 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimePlugin.js +2 -1
- package/lib/RuntimeTemplate.js +20 -2
- package/lib/WebpackError.js +6 -5
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/WebpackOptionsDefaulter.js +10 -3
- package/lib/config/defaults.js +31 -2
- package/lib/css/CssModulesPlugin.js +5 -2
- package/lib/css/CssParser.js +12 -0
- package/lib/dependencies/ConstDependency.js +2 -2
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
- package/lib/dependencies/ImportParserPlugin.js +25 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -0
- package/lib/javascript/BasicEvaluatedExpression.js +23 -15
- package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
- package/lib/javascript/JavascriptParser.js +118 -58
- package/lib/javascript/JavascriptParserHelpers.js +37 -15
- package/lib/performance/SizeLimitsPlugin.js +7 -4
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +3 -1
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +5 -2
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +3 -1
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +3 -1
- 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 +4 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +3 -1
- package/lib/runtime/BaseUriRuntimeModule.js +2 -2
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +4 -1
- package/lib/runtime/CompatRuntimeModule.js +6 -1
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +4 -1
- package/lib/runtime/CreateScriptRuntimeModule.js +3 -1
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +3 -1
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +4 -1
- package/lib/runtime/EnsureChunkRuntimeModule.js +14 -3
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -9
- package/lib/runtime/GetFullHashRuntimeModule.js +3 -2
- package/lib/runtime/GetMainFilenameRuntimeModule.js +4 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +3 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +4 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +63 -47
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +4 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +3 -1
- package/lib/runtime/PublicPathRuntimeModule.js +3 -1
- package/lib/runtime/RelativeUrlRuntimeModule.js +4 -1
- package/lib/runtime/RuntimeIdRuntimeModule.js +5 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -2
- package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -1
- package/lib/serialization/ObjectMiddleware.js +6 -3
- package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +13 -4
- 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 +11 -4
- 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/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 +14 -1
- package/lib/util/smartGrouping.js +1 -1
- package/lib/validateSchema.js +6 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
- package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +13 -6
- 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 +13 -3
- package/lib/webpack.js +11 -2
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -15
- package/module.d.ts +1 -0
- package/package.json +4 -4
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +39 -5
- package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
- package/schemas/plugins/css/CssParserOptions.json +1 -1
- package/types.d.ts +433 -184
@@ -11,6 +11,8 @@ const ChunkPrefetchStartupRuntimeModule = require("./ChunkPrefetchStartupRuntime
|
|
11
11
|
const ChunkPrefetchTriggerRuntimeModule = require("./ChunkPrefetchTriggerRuntimeModule");
|
12
12
|
const ChunkPreloadTriggerRuntimeModule = require("./ChunkPreloadTriggerRuntimeModule");
|
13
13
|
|
14
|
+
/** @typedef {import("../Chunk")} Chunk */
|
15
|
+
/** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
|
14
16
|
/** @typedef {import("../Compiler")} Compiler */
|
15
17
|
|
16
18
|
class ChunkPrefetchPreloadPlugin {
|
@@ -43,7 +45,7 @@ class ChunkPrefetchPreloadPlugin {
|
|
43
45
|
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
44
46
|
"ChunkPrefetchPreloadPlugin",
|
45
47
|
(chunk, set, { chunkGraph }) => {
|
46
|
-
const chunkMap = chunk.getChildIdsByOrdersMap(chunkGraph
|
48
|
+
const chunkMap = chunk.getChildIdsByOrdersMap(chunkGraph);
|
47
49
|
|
48
50
|
if (chunkMap.prefetch) {
|
49
51
|
set.add(RuntimeGlobals.prefetchChunk);
|
@@ -9,6 +9,7 @@ const RuntimeModule = require("../RuntimeModule");
|
|
9
9
|
const Template = require("../Template");
|
10
10
|
|
11
11
|
/** @typedef {import("../Chunk")} Chunk */
|
12
|
+
/** @typedef {import("../Compilation")} Compilation */
|
12
13
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
13
14
|
|
14
15
|
class ChunkPrefetchStartupRuntimeModule extends RuntimeModule {
|
@@ -24,8 +25,10 @@ class ChunkPrefetchStartupRuntimeModule extends RuntimeModule {
|
|
24
25
|
* @returns {string} runtime code
|
25
26
|
*/
|
26
27
|
generate() {
|
27
|
-
const { startupChunks
|
28
|
-
const
|
28
|
+
const { startupChunks } = this;
|
29
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
30
|
+
const chunk = /** @type {Chunk} */ (this.chunk);
|
31
|
+
const { runtimeTemplate } = compilation;
|
29
32
|
return Template.asString(
|
30
33
|
startupChunks.map(
|
31
34
|
({ onChunks, chunks }) =>
|
@@ -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("../Compilation")} Compilation */
|
11
12
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
12
13
|
|
13
14
|
class ChunkPrefetchTriggerRuntimeModule extends RuntimeModule {
|
@@ -24,7 +25,8 @@ class ChunkPrefetchTriggerRuntimeModule extends RuntimeModule {
|
|
24
25
|
*/
|
25
26
|
generate() {
|
26
27
|
const { chunkMap } = this;
|
27
|
-
const
|
28
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
29
|
+
const { runtimeTemplate } = compilation;
|
28
30
|
const body = [
|
29
31
|
"var chunks = chunkToChildrenMap[chunkId];",
|
30
32
|
`Array.isArray(chunks) && chunks.map(${RuntimeGlobals.prefetchChunk});`
|
@@ -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("../Compilation")} Compilation */
|
11
12
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
12
13
|
|
13
14
|
class ChunkPreloadTriggerRuntimeModule extends RuntimeModule {
|
@@ -24,7 +25,8 @@ class ChunkPreloadTriggerRuntimeModule extends RuntimeModule {
|
|
24
25
|
*/
|
25
26
|
generate() {
|
26
27
|
const { chunkMap } = this;
|
27
|
-
const
|
28
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
29
|
+
const { runtimeTemplate } = compilation;
|
28
30
|
const body = [
|
29
31
|
"var chunks = chunkToChildrenMap[chunkId];",
|
30
32
|
`Array.isArray(chunks) && chunks.map(${RuntimeGlobals.preloadChunk});`
|
@@ -8,6 +8,10 @@
|
|
8
8
|
/** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
|
9
9
|
|
10
10
|
class BasicEffectRulePlugin {
|
11
|
+
/**
|
12
|
+
* @param {string} ruleProperty the rule property
|
13
|
+
* @param {string=} effectType the effect type
|
14
|
+
*/
|
11
15
|
constructor(ruleProperty, effectType) {
|
12
16
|
this.ruleProperty = ruleProperty;
|
13
17
|
this.effectType = effectType || ruleProperty;
|
@@ -9,6 +9,11 @@
|
|
9
9
|
/** @typedef {import("./RuleSetCompiler").RuleCondition} RuleCondition */
|
10
10
|
|
11
11
|
class BasicMatcherRulePlugin {
|
12
|
+
/**
|
13
|
+
* @param {string} ruleProperty the rule property
|
14
|
+
* @param {string=} dataProperty the data property
|
15
|
+
* @param {boolean=} invert if true, inverts the condition
|
16
|
+
*/
|
12
17
|
constructor(ruleProperty, dataProperty, invert) {
|
13
18
|
this.ruleProperty = ruleProperty;
|
14
19
|
this.dataProperty = dataProperty || ruleProperty;
|
@@ -150,9 +150,9 @@ class RuleSetCompiler {
|
|
150
150
|
* @returns {CompiledRule[]} rules
|
151
151
|
*/
|
152
152
|
compileRules(path, rules, refs) {
|
153
|
-
return rules
|
154
|
-
|
155
|
-
|
153
|
+
return rules
|
154
|
+
.filter(Boolean)
|
155
|
+
.map((rule, i) => this.compileRule(`${path}[${i}]`, rule, refs));
|
156
156
|
}
|
157
157
|
|
158
158
|
/**
|
@@ -106,9 +106,11 @@ class UseEffectRulePlugin {
|
|
106
106
|
*/
|
107
107
|
const useToEffectsWithoutIdent = (path, items) => {
|
108
108
|
if (Array.isArray(items)) {
|
109
|
-
return items
|
110
|
-
|
111
|
-
|
109
|
+
return items
|
110
|
+
.filter(Boolean)
|
111
|
+
.map((item, idx) =>
|
112
|
+
useToEffectRaw(`${path}[${idx}]`, "[[missing ident]]", item)
|
113
|
+
);
|
112
114
|
}
|
113
115
|
return [useToEffectRaw(path, "[[missing ident]]", items)];
|
114
116
|
};
|
@@ -120,7 +122,7 @@ class UseEffectRulePlugin {
|
|
120
122
|
*/
|
121
123
|
const useToEffects = (path, items) => {
|
122
124
|
if (Array.isArray(items)) {
|
123
|
-
return items.map((item, idx) => {
|
125
|
+
return items.filter(Boolean).map((item, idx) => {
|
124
126
|
const subPath = `${path}[${idx}]`;
|
125
127
|
return useToEffect(subPath, subPath, item);
|
126
128
|
});
|
@@ -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 AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
12
14
|
constructor() {
|
13
15
|
super("async module");
|
@@ -17,7 +19,8 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
17
19
|
* @returns {string} 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.asyncModule;
|
22
25
|
return Template.asString([
|
23
26
|
'var webpackQueues = typeof Symbol === "function" ? Symbol("webpack queues") : "__webpack_queues__";',
|
@@ -10,6 +10,8 @@ const Template = require("../Template");
|
|
10
10
|
const JavascriptModulesPlugin = require("../javascript/JavascriptModulesPlugin");
|
11
11
|
const { getUndoPath } = require("../util/identifier");
|
12
12
|
|
13
|
+
/** @typedef {import("../Compilation")} Compilation */
|
14
|
+
|
13
15
|
class AutoPublicPathRuntimeModule extends RuntimeModule {
|
14
16
|
constructor() {
|
15
17
|
super("publicPath", RuntimeModule.STAGE_BASIC);
|
@@ -19,7 +21,7 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
|
|
19
21
|
* @returns {string} runtime code
|
20
22
|
*/
|
21
23
|
generate() {
|
22
|
-
const
|
24
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
23
25
|
const { scriptType, importMetaName, path } = compilation.outputOptions;
|
24
26
|
const chunkName = compilation.getPath(
|
25
27
|
JavascriptModulesPlugin.getChunkFilenameTemplate(
|
@@ -9,6 +9,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
9
9
|
const RuntimeModule = require("../RuntimeModule");
|
10
10
|
|
11
11
|
/** @typedef {import("../../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescriptionNormalized */
|
12
|
+
/** @typedef {import("../Chunk")} Chunk */
|
12
13
|
|
13
14
|
class BaseUriRuntimeModule extends RuntimeModule {
|
14
15
|
constructor() {
|
@@ -19,8 +20,7 @@ class BaseUriRuntimeModule extends RuntimeModule {
|
|
19
20
|
* @returns {string} runtime code
|
20
21
|
*/
|
21
22
|
generate() {
|
22
|
-
const
|
23
|
-
|
23
|
+
const chunk = /** @type {Chunk} */ (this.chunk);
|
24
24
|
const options =
|
25
25
|
/** @type {EntryDescriptionNormalized} */
|
26
26
|
(chunk.getEntryOptions());
|
@@ -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 CompatGetDefaultExportRuntimeModule extends HelperRuntimeModule {
|
12
14
|
constructor() {
|
13
15
|
super("compat get default export");
|
@@ -17,7 +19,8 @@ class CompatGetDefaultExportRuntimeModule extends HelperRuntimeModule {
|
|
17
19
|
* @returns {string} 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.compatGetDefaultExport;
|
22
25
|
return Template.asString([
|
23
26
|
"// getDefaultExport function for compatibility with non-harmony modules",
|
@@ -7,6 +7,9 @@
|
|
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
|
+
/** @typedef {import("../Compilation")} Compilation */
|
10
13
|
/** @typedef {import("../MainTemplate")} MainTemplate */
|
11
14
|
|
12
15
|
class CompatRuntimeModule extends RuntimeModule {
|
@@ -19,7 +22,9 @@ class CompatRuntimeModule extends RuntimeModule {
|
|
19
22
|
* @returns {string} runtime code
|
20
23
|
*/
|
21
24
|
generate() {
|
22
|
-
const
|
25
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
26
|
+
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
|
27
|
+
const chunk = /** @type {Chunk} */ (this.chunk);
|
23
28
|
const {
|
24
29
|
runtimeTemplate,
|
25
30
|
mainTemplate,
|
@@ -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 CreateFakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
12
14
|
constructor() {
|
13
15
|
super("create fake namespace object");
|
@@ -17,7 +19,8 @@ class CreateFakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
17
19
|
* @returns {string} 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.createFakeNamespaceObject;
|
22
25
|
return Template.asString([
|
23
26
|
`var getProto = Object.getPrototypeOf ? ${runtimeTemplate.returningFunction(
|
@@ -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 CreateScriptRuntimeModule extends HelperRuntimeModule {
|
12
14
|
constructor() {
|
13
15
|
super("trusted types script");
|
@@ -17,7 +19,7 @@ class CreateScriptRuntimeModule extends HelperRuntimeModule {
|
|
17
19
|
* @returns {string} runtime code
|
18
20
|
*/
|
19
21
|
generate() {
|
20
|
-
const
|
22
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
21
23
|
const { runtimeTemplate, outputOptions } = compilation;
|
22
24
|
const { trustedTypes } = outputOptions;
|
23
25
|
const fn = RuntimeGlobals.createScript;
|
@@ -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 CreateScriptUrlRuntimeModule extends HelperRuntimeModule {
|
12
14
|
constructor() {
|
13
15
|
super("trusted types script url");
|
@@ -17,7 +19,7 @@ class CreateScriptUrlRuntimeModule extends HelperRuntimeModule {
|
|
17
19
|
* @returns {string} runtime code
|
18
20
|
*/
|
19
21
|
generate() {
|
20
|
-
const
|
22
|
+
const compilation = /** @type {Compilation} */ (this.compilation);
|
21
23
|
const { runtimeTemplate, outputOptions } = compilation;
|
22
24
|
const { trustedTypes } = outputOptions;
|
23
25
|
const fn = RuntimeGlobals.createScriptUrl;
|
@@ -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 DefinePropertyGettersRuntimeModule extends HelperRuntimeModule {
|
12
14
|
constructor() {
|
13
15
|
super("define property getters");
|
@@ -17,7 +19,8 @@ class DefinePropertyGettersRuntimeModule extends HelperRuntimeModule {
|
|
17
19
|
* @returns {string} 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
|
@@ -21,20 +23,29 @@ class EnsureChunkRuntimeModule extends RuntimeModule {
|
|
21
23
|
* @returns {string} 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 */
|
@@ -37,15 +38,10 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
|
|
37
38
|
* @returns {string} 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>>} */
|
@@ -19,9 +19,10 @@ class GetFullHashRuntimeModule extends RuntimeModule {
|
|
19
19
|
* @returns {string} 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 {
|
@@ -26,7 +27,9 @@ class GetMainFilenameRuntimeModule extends RuntimeModule {
|
|
26
27
|
* @returns {string} 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
|
@@ -21,7 +23,7 @@ class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
|
|
21
23
|
* @returns {string} 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,6 +9,8 @@ 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");
|
@@ -18,7 +20,8 @@ class HasOwnPropertyRuntimeModule extends RuntimeModule {
|
|
18
20
|
* @returns {string} 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
56
|
* @returns {string} 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,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 MakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
12
14
|
constructor() {
|
13
15
|
super("make namespace object");
|
@@ -17,7 +19,8 @@ class MakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|
17
19
|
* @returns {string} 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,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 OnChunksLoadedRuntimeModule extends RuntimeModule {
|
12
14
|
constructor() {
|
13
15
|
super("chunk loaded");
|
@@ -17,7 +19,7 @@ class OnChunksLoadedRuntimeModule extends RuntimeModule {
|
|
17
19
|
* @returns {string} 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 = [];",
|