webpack 5.99.6 → 5.99.8
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/AutomaticPrefetchPlugin.js +21 -22
- package/lib/BannerPlugin.js +31 -35
- package/lib/CleanPlugin.js +5 -3
- package/lib/Compilation.js +21 -15
- package/lib/Compiler.js +2 -1
- package/lib/ContextExclusionPlugin.js +4 -2
- package/lib/ContextModule.js +1 -1
- package/lib/ContextModuleFactory.js +1 -2
- package/lib/ContextReplacementPlugin.js +7 -4
- package/lib/DefinePlugin.js +2 -2
- package/lib/DelegatedModule.js +18 -8
- package/lib/DelegatedModuleFactoryPlugin.js +9 -7
- package/lib/DelegatedPlugin.js +4 -2
- package/lib/DllEntryPlugin.js +4 -2
- package/lib/DllPlugin.js +5 -3
- package/lib/DllReferencePlugin.js +56 -60
- package/lib/DynamicEntryPlugin.js +4 -2
- package/lib/EntryOptionPlugin.js +3 -1
- package/lib/EntryPlugin.js +4 -2
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/EvalDevToolModulePlugin.js +9 -7
- package/lib/EvalSourceMapDevToolPlugin.js +138 -139
- package/lib/ExportsInfo.js +35 -16
- package/lib/ExternalModule.js +6 -5
- package/lib/ExternalsPlugin.js +3 -1
- package/lib/FileSystemInfo.js +2 -2
- package/lib/FlagDependencyExportsPlugin.js +2 -1
- package/lib/IgnorePlugin.js +6 -4
- package/lib/IgnoreWarningsPlugin.js +4 -2
- package/lib/LibManifestPlugin.js +5 -6
- package/lib/LoaderOptionsPlugin.js +4 -2
- package/lib/LoaderTargetPlugin.js +4 -2
- package/lib/Module.js +19 -12
- package/lib/ModuleFilenameHelpers.js +8 -4
- package/lib/ModuleInfoHeaderPlugin.js +11 -12
- package/lib/MultiCompiler.js +5 -3
- package/lib/NoEmitOnErrorsPlugin.js +5 -3
- package/lib/NormalModule.js +13 -8
- package/lib/NormalModuleReplacementPlugin.js +33 -36
- package/lib/PlatformPlugin.js +3 -1
- package/lib/PrefetchPlugin.js +4 -2
- package/lib/ProgressPlugin.js +23 -26
- package/lib/RecordIdsPlugin.js +72 -102
- package/lib/RuntimePlugin.js +34 -32
- package/lib/SourceMapDevToolPlugin.js +9 -8
- package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
- package/lib/WarnNoModeSetPlugin.js +3 -1
- package/lib/WatchIgnorePlugin.js +3 -1
- package/lib/WebpackError.js +11 -3
- package/lib/WebpackOptionsApply.js +6 -7
- package/lib/asset/AssetGenerator.js +2 -2
- package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
- package/lib/cache/IdleFileCachePlugin.js +11 -12
- package/lib/cache/MemoryWithGcCachePlugin.js +7 -5
- package/lib/cache/ResolverCachePlugin.js +8 -6
- package/lib/cli.js +5 -1
- package/lib/config/defaults.js +10 -6
- package/lib/config/normalization.js +14 -8
- package/lib/container/ContainerReferencePlugin.js +24 -26
- package/lib/container/ModuleFederationPlugin.js +2 -1
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssModulesPlugin.js +8 -6
- package/lib/debug/ProfilingPlugin.js +18 -21
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
- package/lib/dependencies/LoaderPlugin.js +5 -3
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
- package/lib/dependencies/RequireContextPlugin.js +2 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/esm/ModuleChunkLoadingPlugin.js +72 -73
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -2
- package/lib/hmr/LazyCompilationPlugin.js +17 -18
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
- package/lib/ids/DeterministicModuleIdsPlugin.js +47 -48
- package/lib/ids/HashedModuleIdsPlugin.js +4 -2
- package/lib/ids/NamedChunkIdsPlugin.js +4 -2
- package/lib/ids/NamedModuleIdsPlugin.js +4 -2
- package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
- package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
- package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
- package/lib/index.js +11 -0
- package/lib/javascript/JavascriptModulesPlugin.js +2 -2
- package/lib/javascript/JavascriptParser.js +634 -656
- package/lib/json/JsonModulesPlugin.js +4 -4
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +60 -42
- package/lib/node/CommonJsChunkLoadingPlugin.js +69 -73
- package/lib/node/NodeEnvironmentPlugin.js +3 -1
- package/lib/node/nodeConsole.js +3 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
- package/lib/optimize/ConcatenatedModule.js +15 -16
- package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +15 -16
- package/lib/optimize/MinChunkSizePlugin.js +4 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +6 -4
- package/lib/optimize/RealContentHashPlugin.js +4 -2
- package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
- package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
- package/lib/optimize/RuntimeChunkPlugin.js +21 -23
- package/lib/optimize/SideEffectsFlagPlugin.js +9 -6
- package/lib/optimize/SplitChunksPlugin.js +9 -7
- package/lib/performance/SizeLimitsPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
- package/lib/rules/BasicEffectRulePlugin.js +1 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +2 -1
- package/lib/rules/RuleSetCompiler.js +19 -5
- package/lib/rules/UseEffectRulePlugin.js +4 -6
- package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
- package/lib/schemes/DataUriPlugin.js +5 -3
- package/lib/schemes/FileUriPlugin.js +5 -3
- package/lib/schemes/HttpUriPlugin.js +186 -188
- package/lib/serialization/AggregateErrorSerializer.js +42 -0
- package/lib/serialization/ErrorObjectSerializer.js +7 -2
- package/lib/serialization/ObjectMiddleware.js +13 -0
- package/lib/sharing/ProvideSharedPlugin.js +6 -4
- package/lib/stats/DefaultStatsFactoryPlugin.js +89 -33
- package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +306 -341
- package/lib/util/concatenate.js +4 -2
- package/lib/util/createHash.js +3 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
- package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
- package/package.json +35 -30
- package/schemas/WebpackOptions.check.d.ts +1 -1
- package/schemas/WebpackOptions.check.js +2 -2
- package/schemas/WebpackOptions.json +267 -26
- package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/DllPlugin.check.d.ts +1 -1
- package/schemas/plugins/DllPlugin.check.js +1 -1
- package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
- package/schemas/plugins/IgnorePlugin.check.js +1 -1
- package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
- package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
- package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/{JsonModulesPluginGenerator.check.js → json/JsonModulesPluginGenerator.check.js} +1 -1
- package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
- package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
- package/schemas/plugins/{JsonModulesPluginParser.check.js → json/JsonModulesPluginParser.check.js} +1 -1
- package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
- package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
- package/types.d.ts +587 -207
- package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +0 -7
- package/schemas/plugins/JsonModulesPluginGenerator.json +0 -11
- package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
- package/schemas/plugins/JsonModulesPluginParser.json +0 -16
@@ -15,83 +15,82 @@ const ChunkPreloadTriggerRuntimeModule = require("./ChunkPreloadTriggerRuntimeMo
|
|
15
15
|
/** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
|
16
16
|
/** @typedef {import("../Compiler")} Compiler */
|
17
17
|
|
18
|
+
const PLUGIN_NAME = "ChunkPrefetchPreloadPlugin";
|
19
|
+
|
18
20
|
class ChunkPrefetchPreloadPlugin {
|
19
21
|
/**
|
20
22
|
* @param {Compiler} compiler the compiler
|
21
23
|
* @returns {void}
|
22
24
|
*/
|
23
25
|
apply(compiler) {
|
24
|
-
compiler.hooks.compilation.tap(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
27
|
+
compilation.hooks.additionalChunkRuntimeRequirements.tap(
|
28
|
+
PLUGIN_NAME,
|
29
|
+
(chunk, set, { chunkGraph }) => {
|
30
|
+
if (chunkGraph.getNumberOfEntryModules(chunk) === 0) return;
|
31
|
+
const startupChildChunks = chunk.getChildrenOfTypeInOrder(
|
32
|
+
chunkGraph,
|
33
|
+
"prefetchOrder"
|
34
|
+
);
|
35
|
+
if (startupChildChunks) {
|
36
|
+
set.add(RuntimeGlobals.prefetchChunk);
|
37
|
+
set.add(RuntimeGlobals.onChunksLoaded);
|
38
|
+
set.add(RuntimeGlobals.exports);
|
39
|
+
compilation.addRuntimeModule(
|
40
|
+
chunk,
|
41
|
+
new ChunkPrefetchStartupRuntimeModule(startupChildChunks)
|
34
42
|
);
|
35
|
-
if (startupChildChunks) {
|
36
|
-
set.add(RuntimeGlobals.prefetchChunk);
|
37
|
-
set.add(RuntimeGlobals.onChunksLoaded);
|
38
|
-
set.add(RuntimeGlobals.exports);
|
39
|
-
compilation.addRuntimeModule(
|
40
|
-
chunk,
|
41
|
-
new ChunkPrefetchStartupRuntimeModule(startupChildChunks)
|
42
|
-
);
|
43
|
-
}
|
44
43
|
}
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
}
|
45
|
+
);
|
46
|
+
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
47
|
+
PLUGIN_NAME,
|
48
|
+
(chunk, set, { chunkGraph }) => {
|
49
|
+
const chunkMap = chunk.getChildIdsByOrdersMap(chunkGraph);
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
compilation.addRuntimeModule(
|
54
|
-
chunk,
|
55
|
-
new ChunkPrefetchTriggerRuntimeModule(chunkMap.prefetch)
|
56
|
-
);
|
57
|
-
}
|
58
|
-
if (chunkMap.preload) {
|
59
|
-
set.add(RuntimeGlobals.preloadChunk);
|
60
|
-
compilation.addRuntimeModule(
|
61
|
-
chunk,
|
62
|
-
new ChunkPreloadTriggerRuntimeModule(chunkMap.preload)
|
63
|
-
);
|
64
|
-
}
|
65
|
-
}
|
66
|
-
);
|
67
|
-
compilation.hooks.runtimeRequirementInTree
|
68
|
-
.for(RuntimeGlobals.prefetchChunk)
|
69
|
-
.tap("ChunkPrefetchPreloadPlugin", (chunk, set) => {
|
51
|
+
if (chunkMap.prefetch) {
|
52
|
+
set.add(RuntimeGlobals.prefetchChunk);
|
70
53
|
compilation.addRuntimeModule(
|
71
54
|
chunk,
|
72
|
-
new
|
73
|
-
"prefetch",
|
74
|
-
RuntimeGlobals.prefetchChunk,
|
75
|
-
RuntimeGlobals.prefetchChunkHandlers
|
76
|
-
)
|
55
|
+
new ChunkPrefetchTriggerRuntimeModule(chunkMap.prefetch)
|
77
56
|
);
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
.for(RuntimeGlobals.preloadChunk)
|
82
|
-
.tap("ChunkPrefetchPreloadPlugin", (chunk, set) => {
|
57
|
+
}
|
58
|
+
if (chunkMap.preload) {
|
59
|
+
set.add(RuntimeGlobals.preloadChunk);
|
83
60
|
compilation.addRuntimeModule(
|
84
61
|
chunk,
|
85
|
-
new
|
86
|
-
"preload",
|
87
|
-
RuntimeGlobals.preloadChunk,
|
88
|
-
RuntimeGlobals.preloadChunkHandlers
|
89
|
-
)
|
62
|
+
new ChunkPreloadTriggerRuntimeModule(chunkMap.preload)
|
90
63
|
);
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
64
|
+
}
|
65
|
+
}
|
66
|
+
);
|
67
|
+
compilation.hooks.runtimeRequirementInTree
|
68
|
+
.for(RuntimeGlobals.prefetchChunk)
|
69
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
70
|
+
compilation.addRuntimeModule(
|
71
|
+
chunk,
|
72
|
+
new ChunkPrefetchFunctionRuntimeModule(
|
73
|
+
"prefetch",
|
74
|
+
RuntimeGlobals.prefetchChunk,
|
75
|
+
RuntimeGlobals.prefetchChunkHandlers
|
76
|
+
)
|
77
|
+
);
|
78
|
+
set.add(RuntimeGlobals.prefetchChunkHandlers);
|
79
|
+
});
|
80
|
+
compilation.hooks.runtimeRequirementInTree
|
81
|
+
.for(RuntimeGlobals.preloadChunk)
|
82
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
83
|
+
compilation.addRuntimeModule(
|
84
|
+
chunk,
|
85
|
+
new ChunkPrefetchFunctionRuntimeModule(
|
86
|
+
"preload",
|
87
|
+
RuntimeGlobals.preloadChunk,
|
88
|
+
RuntimeGlobals.preloadChunkHandlers
|
89
|
+
)
|
90
|
+
);
|
91
|
+
set.add(RuntimeGlobals.preloadChunkHandlers);
|
92
|
+
});
|
93
|
+
});
|
95
94
|
}
|
96
95
|
}
|
97
96
|
|
@@ -37,8 +37,7 @@ class BasicEffectRulePlugin {
|
|
37
37
|
if (unhandledProperties.has(this.ruleProperty)) {
|
38
38
|
unhandledProperties.delete(this.ruleProperty);
|
39
39
|
|
40
|
-
const value =
|
41
|
-
rule[/** @type {keyof RuleSetRule} */ (this.ruleProperty)];
|
40
|
+
const value = rule[this.ruleProperty];
|
42
41
|
|
43
42
|
result.effects.push({
|
44
43
|
type: this.effectType,
|
@@ -8,6 +8,7 @@
|
|
8
8
|
/** @typedef {import("../../declarations/WebpackOptions").RuleSetConditionOrConditions} RuleSetConditionOrConditions */
|
9
9
|
/** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
|
10
10
|
/** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
|
11
|
+
/** @typedef {import("./RuleSetCompiler").EffectData} EffectData */
|
11
12
|
/** @typedef {import("./RuleSetCompiler").RuleCondition} RuleCondition */
|
12
13
|
/** @typedef {import("./RuleSetCompiler").RuleConditionFunction} RuleConditionFunction */
|
13
14
|
|
@@ -22,7 +23,7 @@
|
|
22
23
|
class ObjectMatcherRulePlugin {
|
23
24
|
/**
|
24
25
|
* @param {ObjectMatcherRuleKeys} ruleProperty the rule property
|
25
|
-
* @param {
|
26
|
+
* @param {keyof EffectData=} dataProperty the data property
|
26
27
|
* @param {RuleConditionFunction=} additionalConditionFunction need to check
|
27
28
|
*/
|
28
29
|
constructor(ruleProperty, dataProperty, additionalConditionFunction) {
|
@@ -13,7 +13,9 @@ const { SyncHook } = require("tapable");
|
|
13
13
|
|
14
14
|
/** @typedef {(Falsy | RuleSetRule)[]} RuleSetRules */
|
15
15
|
|
16
|
-
/**
|
16
|
+
/**
|
17
|
+
* @typedef {(value: EffectData[keyof EffectData]) => boolean} RuleConditionFunction
|
18
|
+
*/
|
17
19
|
|
18
20
|
/**
|
19
21
|
* @typedef {object} RuleCondition
|
@@ -29,7 +31,19 @@ const { SyncHook } = require("tapable");
|
|
29
31
|
*/
|
30
32
|
|
31
33
|
/**
|
32
|
-
* @typedef {
|
34
|
+
* @typedef {object} EffectData
|
35
|
+
* @property {string=} resource
|
36
|
+
* @property {string=} realResource
|
37
|
+
* @property {string=} resourceQuery
|
38
|
+
* @property {string=} resourceFragment
|
39
|
+
* @property {string=} scheme
|
40
|
+
* @property {ImportAttributes=} assertions
|
41
|
+
* @property {string=} mimetype
|
42
|
+
* @property {string} dependency
|
43
|
+
* @property {Record<string, EXPECTED_ANY>} descriptionData
|
44
|
+
* @property {string=} compiler
|
45
|
+
* @property {string} issuer
|
46
|
+
* @property {string} issuerLayer
|
33
47
|
*/
|
34
48
|
|
35
49
|
/**
|
@@ -102,7 +116,7 @@ class RuleSetCompiler {
|
|
102
116
|
for (const condition of rule.conditions) {
|
103
117
|
const p = condition.property;
|
104
118
|
if (Array.isArray(p)) {
|
105
|
-
/** @type {EffectData |
|
119
|
+
/** @type {EffectData | EffectData[keyof EffectData] | undefined} */
|
106
120
|
let current = data;
|
107
121
|
for (const subProperty of p) {
|
108
122
|
if (
|
@@ -110,7 +124,7 @@ class RuleSetCompiler {
|
|
110
124
|
typeof current === "object" &&
|
111
125
|
Object.prototype.hasOwnProperty.call(current, subProperty)
|
112
126
|
) {
|
113
|
-
current = current[subProperty];
|
127
|
+
current = current[/** @type {keyof EffectData} */ (subProperty)];
|
114
128
|
} else {
|
115
129
|
current = undefined;
|
116
130
|
break;
|
@@ -121,7 +135,7 @@ class RuleSetCompiler {
|
|
121
135
|
continue;
|
122
136
|
}
|
123
137
|
} else if (p in data) {
|
124
|
-
const value = data[p];
|
138
|
+
const value = data[/** @type {keyof EffectData} */ (p)];
|
125
139
|
if (value !== undefined) {
|
126
140
|
if (!condition.fn(value)) return false;
|
127
141
|
continue;
|
@@ -15,6 +15,7 @@ const util = require("util");
|
|
15
15
|
/** @typedef {import("../../declarations/WebpackOptions").RuleSetUseItem} RuleSetUseItem */
|
16
16
|
/** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
|
17
17
|
/** @typedef {import("./RuleSetCompiler").Effect} Effect */
|
18
|
+
/** @typedef {import("./RuleSetCompiler").EffectData} EffectData */
|
18
19
|
|
19
20
|
class UseEffectRulePlugin {
|
20
21
|
/**
|
@@ -55,7 +56,7 @@ class UseEffectRulePlugin {
|
|
55
56
|
* @param {string} path options path
|
56
57
|
* @param {string} defaultIdent default ident when none is provided
|
57
58
|
* @param {RuleSetUseItem} item user provided use value
|
58
|
-
* @returns {Effect | ((
|
59
|
+
* @returns {(Effect | ((effectData: EffectData) => Effect[]))} effect
|
59
60
|
*/
|
60
61
|
const useToEffect = (path, defaultIdent, item) => {
|
61
62
|
if (typeof item === "function") {
|
@@ -139,7 +140,7 @@ class UseEffectRulePlugin {
|
|
139
140
|
/**
|
140
141
|
* @param {string} path current path
|
141
142
|
* @param {RuleSetUse} items user provided use value
|
142
|
-
* @returns {(Effect | ((
|
143
|
+
* @returns {(Effect | ((effectData: EffectData) => Effect[]))[]} effects
|
143
144
|
*/
|
144
145
|
const useToEffects = (path, items) => {
|
145
146
|
if (Array.isArray(items)) {
|
@@ -160,10 +161,7 @@ class UseEffectRulePlugin {
|
|
160
161
|
|
161
162
|
if (typeof use === "function") {
|
162
163
|
result.effects.push(data =>
|
163
|
-
useToEffectsWithoutIdent(
|
164
|
-
`${path}.use`,
|
165
|
-
use(/** @type {TODO} */ (data))
|
166
|
-
)
|
164
|
+
useToEffectsWithoutIdent(`${path}.use`, use(data))
|
167
165
|
);
|
168
166
|
} else {
|
169
167
|
for (const effect of useToEffects(`${path}.use`, use)) {
|
@@ -18,6 +18,8 @@ const StartupEntrypointRuntimeModule = require("./StartupEntrypointRuntimeModule
|
|
18
18
|
* @property {boolean=} asyncChunkLoading
|
19
19
|
*/
|
20
20
|
|
21
|
+
const PLUGIN_NAME = "StartupChunkDependenciesPlugin";
|
22
|
+
|
21
23
|
class StartupChunkDependenciesPlugin {
|
22
24
|
/**
|
23
25
|
* @param {Options} options options
|
@@ -36,53 +38,48 @@ class StartupChunkDependenciesPlugin {
|
|
36
38
|
* @returns {void}
|
37
39
|
*/
|
38
40
|
apply(compiler) {
|
39
|
-
compiler.hooks.thisCompilation.tap(
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
const
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
(chunk
|
58
|
-
|
59
|
-
if (chunkGraph.hasChunkEntryDependentChunks(chunk)) {
|
60
|
-
set.add(RuntimeGlobals.startup);
|
61
|
-
set.add(RuntimeGlobals.ensureChunk);
|
62
|
-
set.add(RuntimeGlobals.ensureChunkIncludeEntries);
|
63
|
-
compilation.addRuntimeModule(
|
64
|
-
chunk,
|
65
|
-
new StartupChunkDependenciesRuntimeModule(
|
66
|
-
this.asyncChunkLoading
|
67
|
-
)
|
68
|
-
);
|
69
|
-
}
|
70
|
-
}
|
71
|
-
);
|
72
|
-
compilation.hooks.runtimeRequirementInTree
|
73
|
-
.for(RuntimeGlobals.startupEntrypoint)
|
74
|
-
.tap("StartupChunkDependenciesPlugin", (chunk, set) => {
|
75
|
-
if (!isEnabledForChunk(chunk)) return;
|
76
|
-
set.add(RuntimeGlobals.require);
|
41
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
42
|
+
const globalChunkLoading = compilation.outputOptions.chunkLoading;
|
43
|
+
/**
|
44
|
+
* @param {Chunk} chunk chunk to check
|
45
|
+
* @returns {boolean} true, when the plugin is enabled for the chunk
|
46
|
+
*/
|
47
|
+
const isEnabledForChunk = chunk => {
|
48
|
+
const options = chunk.getEntryOptions();
|
49
|
+
const chunkLoading =
|
50
|
+
options && options.chunkLoading !== undefined
|
51
|
+
? options.chunkLoading
|
52
|
+
: globalChunkLoading;
|
53
|
+
return chunkLoading === this.chunkLoading;
|
54
|
+
};
|
55
|
+
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
56
|
+
PLUGIN_NAME,
|
57
|
+
(chunk, set, { chunkGraph }) => {
|
58
|
+
if (!isEnabledForChunk(chunk)) return;
|
59
|
+
if (chunkGraph.hasChunkEntryDependentChunks(chunk)) {
|
60
|
+
set.add(RuntimeGlobals.startup);
|
77
61
|
set.add(RuntimeGlobals.ensureChunk);
|
78
62
|
set.add(RuntimeGlobals.ensureChunkIncludeEntries);
|
79
63
|
compilation.addRuntimeModule(
|
80
64
|
chunk,
|
81
|
-
new
|
65
|
+
new StartupChunkDependenciesRuntimeModule(this.asyncChunkLoading)
|
82
66
|
);
|
83
|
-
}
|
84
|
-
|
85
|
-
|
67
|
+
}
|
68
|
+
}
|
69
|
+
);
|
70
|
+
compilation.hooks.runtimeRequirementInTree
|
71
|
+
.for(RuntimeGlobals.startupEntrypoint)
|
72
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
73
|
+
if (!isEnabledForChunk(chunk)) return;
|
74
|
+
set.add(RuntimeGlobals.require);
|
75
|
+
set.add(RuntimeGlobals.ensureChunk);
|
76
|
+
set.add(RuntimeGlobals.ensureChunkIncludeEntries);
|
77
|
+
compilation.addRuntimeModule(
|
78
|
+
chunk,
|
79
|
+
new StartupEntrypointRuntimeModule(this.asyncChunkLoading)
|
80
|
+
);
|
81
|
+
});
|
82
|
+
});
|
86
83
|
}
|
87
84
|
}
|
88
85
|
|
@@ -37,6 +37,8 @@ const decodeDataURI = uri => {
|
|
37
37
|
}
|
38
38
|
};
|
39
39
|
|
40
|
+
const PLUGIN_NAME = "DataUriPlugin";
|
41
|
+
|
40
42
|
class DataUriPlugin {
|
41
43
|
/**
|
42
44
|
* Apply the plugin
|
@@ -45,11 +47,11 @@ class DataUriPlugin {
|
|
45
47
|
*/
|
46
48
|
apply(compiler) {
|
47
49
|
compiler.hooks.compilation.tap(
|
48
|
-
|
50
|
+
PLUGIN_NAME,
|
49
51
|
(compilation, { normalModuleFactory }) => {
|
50
52
|
normalModuleFactory.hooks.resolveForScheme
|
51
53
|
.for("data")
|
52
|
-
.tap(
|
54
|
+
.tap(PLUGIN_NAME, resourceData => {
|
53
55
|
const match = URIRegEx.exec(resourceData.resource);
|
54
56
|
if (match) {
|
55
57
|
resourceData.data.mimetype = match[1] || "";
|
@@ -60,7 +62,7 @@ class DataUriPlugin {
|
|
60
62
|
});
|
61
63
|
NormalModule.getCompilationHooks(compilation)
|
62
64
|
.readResourceForScheme.for("data")
|
63
|
-
.tap(
|
65
|
+
.tap(PLUGIN_NAME, resource => decodeDataURI(resource));
|
64
66
|
}
|
65
67
|
);
|
66
68
|
}
|
@@ -10,6 +10,8 @@ const { NormalModule } = require("..");
|
|
10
10
|
|
11
11
|
/** @typedef {import("../Compiler")} Compiler */
|
12
12
|
|
13
|
+
const PLUGIN_NAME = "FileUriPlugin";
|
14
|
+
|
13
15
|
class FileUriPlugin {
|
14
16
|
/**
|
15
17
|
* Apply the plugin
|
@@ -18,11 +20,11 @@ class FileUriPlugin {
|
|
18
20
|
*/
|
19
21
|
apply(compiler) {
|
20
22
|
compiler.hooks.compilation.tap(
|
21
|
-
|
23
|
+
PLUGIN_NAME,
|
22
24
|
(compilation, { normalModuleFactory }) => {
|
23
25
|
normalModuleFactory.hooks.resolveForScheme
|
24
26
|
.for("file")
|
25
|
-
.tap(
|
27
|
+
.tap(PLUGIN_NAME, resourceData => {
|
26
28
|
const url = new URL(resourceData.resource);
|
27
29
|
const path = fileURLToPath(url);
|
28
30
|
const query = url.search;
|
@@ -36,7 +38,7 @@ class FileUriPlugin {
|
|
36
38
|
const hooks = NormalModule.getCompilationHooks(compilation);
|
37
39
|
hooks.readResource
|
38
40
|
.for(undefined)
|
39
|
-
.tapAsync(
|
41
|
+
.tapAsync(PLUGIN_NAME, (loaderContext, callback) => {
|
40
42
|
const { resourcePath } = loaderContext;
|
41
43
|
loaderContext.addDependency(resourcePath);
|
42
44
|
loaderContext.fs.readFile(resourcePath, callback);
|