webpack 5.59.0 → 5.71.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 +1 -7
- package/hot/lazy-compilation-node.js +3 -1
- package/hot/poll.js +1 -1
- package/hot/signal.js +1 -1
- package/lib/APIPlugin.js +33 -0
- package/lib/BannerPlugin.js +10 -4
- package/lib/Cache.js +1 -1
- package/lib/CacheFacade.js +4 -11
- package/lib/Chunk.js +6 -3
- package/lib/ChunkGraph.js +1 -2
- package/lib/ChunkGroup.js +1 -1
- package/lib/CleanPlugin.js +81 -20
- package/lib/Compilation.js +179 -91
- package/lib/Compiler.js +86 -17
- package/lib/ConstPlugin.js +2 -2
- package/lib/ContextModule.js +142 -51
- package/lib/ContextModuleFactory.js +65 -25
- package/lib/DelegatedModule.js +1 -1
- package/lib/DelegatedModuleFactoryPlugin.js +1 -1
- package/lib/Dependency.js +17 -0
- package/lib/DependencyTemplate.js +9 -0
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DllModule.js +1 -1
- package/lib/EntryOptionPlugin.js +2 -0
- package/lib/ErrorHelpers.js +2 -2
- package/lib/EvalDevToolModulePlugin.js +16 -1
- package/lib/EvalSourceMapDevToolPlugin.js +18 -1
- package/lib/ExportsInfo.js +4 -4
- package/lib/ExternalModule.js +94 -54
- package/lib/ExternalModuleFactoryPlugin.js +5 -5
- package/lib/FileSystemInfo.js +89 -44
- package/lib/Generator.js +3 -0
- package/lib/HookWebpackError.js +1 -1
- package/lib/HotModuleReplacementPlugin.js +3 -1
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/Module.js +27 -4
- package/lib/ModuleFilenameHelpers.js +8 -4
- package/lib/ModuleHashingError.js +29 -0
- package/lib/MultiCompiler.js +1 -1
- package/lib/MultiWatching.js +1 -1
- package/lib/NodeStuffPlugin.js +10 -0
- package/lib/NormalModule.js +41 -26
- package/lib/NormalModuleFactory.js +42 -37
- package/lib/ProgressPlugin.js +4 -5
- package/lib/RawModule.js +1 -1
- package/lib/RuntimeGlobals.js +29 -1
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +77 -1
- package/lib/RuntimeTemplate.js +114 -2
- package/lib/Template.js +2 -1
- package/lib/TemplatedPathPlugin.js +48 -23
- package/lib/WatchIgnorePlugin.js +19 -7
- package/lib/Watching.js +33 -19
- package/lib/WebpackOptionsApply.js +57 -11
- package/lib/asset/AssetGenerator.js +193 -63
- package/lib/asset/AssetModulesPlugin.js +3 -0
- package/lib/asset/RawDataUrlModule.js +148 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
- package/lib/buildChunkGraph.js +36 -6
- package/lib/cache/PackFileCacheStrategy.js +7 -4
- package/lib/cache/ResolverCachePlugin.js +90 -29
- package/lib/cli.js +44 -3
- package/lib/config/browserslistTargetHandler.js +41 -6
- package/lib/config/defaults.js +115 -19
- package/lib/config/normalization.js +9 -0
- package/lib/config/target.js +10 -0
- package/lib/container/ContainerEntryModule.js +8 -5
- package/lib/container/FallbackModule.js +4 -4
- package/lib/container/RemoteModule.js +4 -2
- package/lib/css/CssExportsGenerator.js +139 -0
- package/lib/css/CssGenerator.js +109 -0
- package/lib/css/CssLoadingRuntimeModule.js +440 -0
- package/lib/css/CssModulesPlugin.js +462 -0
- package/lib/css/CssParser.js +618 -0
- package/lib/css/walkCssTokens.js +659 -0
- package/lib/debug/ProfilingPlugin.js +24 -21
- package/lib/dependencies/AMDRequireDependency.js +6 -6
- package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
- package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -3
- package/lib/dependencies/CommonJsRequireContextDependency.js +5 -1
- package/lib/dependencies/ContextDependency.js +1 -0
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
- package/lib/dependencies/ContextElementDependency.js +41 -3
- package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
- package/lib/dependencies/CssExportDependency.js +85 -0
- package/lib/dependencies/CssImportDependency.js +75 -0
- package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
- package/lib/dependencies/CssUrlDependency.js +132 -0
- package/lib/dependencies/ExportsInfoDependency.js +6 -0
- package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
- package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +95 -0
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
- package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
- package/lib/dependencies/HarmonyImportDependency.js +23 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
- package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
- package/lib/dependencies/ImportContextDependency.js +0 -2
- package/lib/dependencies/ImportMetaContextDependency.js +35 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
- package/lib/dependencies/ImportMetaPlugin.js +22 -3
- package/lib/dependencies/LoaderPlugin.js +4 -2
- package/lib/dependencies/RequireContextDependency.js +0 -16
- package/lib/dependencies/RequireEnsureDependency.js +2 -2
- package/lib/dependencies/URLDependency.js +3 -8
- package/lib/dependencies/URLPlugin.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
- package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
- package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
- package/lib/hmr/LazyCompilationPlugin.js +54 -26
- package/lib/hmr/lazyCompilationBackend.js +51 -12
- package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
- package/lib/ids/HashedModuleIdsPlugin.js +11 -14
- package/lib/ids/IdHelpers.js +25 -11
- package/lib/ids/NamedModuleIdsPlugin.js +6 -9
- package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
- package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
- package/lib/ids/SyncModuleIdsPlugin.js +140 -0
- package/lib/index.js +13 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
- package/lib/javascript/BasicEvaluatedExpression.js +5 -2
- package/lib/javascript/ChunkHelpers.js +33 -0
- package/lib/javascript/JavascriptGenerator.js +1 -0
- package/lib/javascript/JavascriptModulesPlugin.js +27 -2
- package/lib/javascript/JavascriptParser.js +82 -48
- package/lib/javascript/StartupHelpers.js +7 -30
- package/lib/library/AssignLibraryPlugin.js +39 -15
- package/lib/library/EnableLibraryPlugin.js +11 -0
- package/lib/library/UmdLibraryPlugin.js +5 -3
- package/lib/node/NodeTargetPlugin.js +3 -0
- package/lib/node/NodeWatchFileSystem.js +85 -31
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
- package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
- package/lib/optimize/ConcatenatedModule.js +21 -9
- package/lib/optimize/ModuleConcatenationPlugin.js +5 -2
- package/lib/optimize/SplitChunksPlugin.js +8 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +27 -17
- package/lib/runtime/BaseUriRuntimeModule.js +31 -0
- package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
- package/lib/schemes/HttpUriPlugin.js +77 -14
- package/lib/serialization/FileMiddleware.js +44 -9
- package/lib/sharing/ConsumeSharedModule.js +8 -2
- package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
- package/lib/stats/DefaultStatsPrinterPlugin.js +89 -24
- package/lib/util/ArrayHelpers.js +30 -0
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/compileBooleanMatcher.js +1 -1
- package/lib/util/create-schema-validation.js +9 -2
- package/lib/util/createHash.js +12 -0
- package/lib/util/deprecation.js +10 -2
- package/lib/util/deterministicGrouping.js +1 -1
- package/lib/util/extractUrlAndGlobal.js +3 -0
- package/lib/util/fs.js +11 -0
- package/lib/util/hash/BatchedHash.js +7 -4
- package/lib/util/hash/md4.js +20 -0
- package/lib/util/hash/wasm-hash.js +163 -0
- package/lib/util/hash/xxhash64.js +5 -139
- package/lib/util/identifier.js +65 -44
- package/lib/util/internalSerializables.js +15 -0
- package/lib/util/nonNumericOnlyHash.js +22 -0
- package/lib/util/semver.js +17 -10
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +20 -9
- package/lib/webpack.js +10 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
- package/module.d.ts +215 -0
- package/package.json +23 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +254 -29
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +2 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssParserOptions.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
- package/types.d.ts +628 -179
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const util = require("util");
|
8
9
|
const Watchpack = require("watchpack");
|
9
10
|
|
10
11
|
/** @typedef {import("../../declarations/WebpackOptions").WatchOptions} WatchOptions */
|
@@ -68,7 +69,22 @@ class NodeWatchFileSystem {
|
|
68
69
|
if (callbackUndelayed) {
|
69
70
|
this.watcher.once("change", callbackUndelayed);
|
70
71
|
}
|
72
|
+
|
73
|
+
const fetchTimeInfo = () => {
|
74
|
+
const fileTimeInfoEntries = new Map();
|
75
|
+
const contextTimeInfoEntries = new Map();
|
76
|
+
if (this.watcher) {
|
77
|
+
this.watcher.collectTimeInfoEntries(
|
78
|
+
fileTimeInfoEntries,
|
79
|
+
contextTimeInfoEntries
|
80
|
+
);
|
81
|
+
}
|
82
|
+
return { fileTimeInfoEntries, contextTimeInfoEntries };
|
83
|
+
};
|
71
84
|
this.watcher.once("aggregated", (changes, removals) => {
|
85
|
+
// pause emitting events (avoids clearing aggregated changes and removals on timeout)
|
86
|
+
this.watcher.pause();
|
87
|
+
|
72
88
|
if (this.inputFileSystem && this.inputFileSystem.purge) {
|
73
89
|
const fs = this.inputFileSystem;
|
74
90
|
for (const item of changes) {
|
@@ -78,8 +94,14 @@ class NodeWatchFileSystem {
|
|
78
94
|
fs.purge(item);
|
79
95
|
}
|
80
96
|
}
|
81
|
-
const
|
82
|
-
callback(
|
97
|
+
const { fileTimeInfoEntries, contextTimeInfoEntries } = fetchTimeInfo();
|
98
|
+
callback(
|
99
|
+
null,
|
100
|
+
fileTimeInfoEntries,
|
101
|
+
contextTimeInfoEntries,
|
102
|
+
changes,
|
103
|
+
removals
|
104
|
+
);
|
83
105
|
});
|
84
106
|
|
85
107
|
this.watcher.watch({ files, directories, missing, startTime });
|
@@ -99,39 +121,71 @@ class NodeWatchFileSystem {
|
|
99
121
|
this.watcher.pause();
|
100
122
|
}
|
101
123
|
},
|
102
|
-
getAggregatedRemovals: (
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
124
|
+
getAggregatedRemovals: util.deprecate(
|
125
|
+
() => {
|
126
|
+
const items = this.watcher && this.watcher.aggregatedRemovals;
|
127
|
+
if (items && this.inputFileSystem && this.inputFileSystem.purge) {
|
128
|
+
const fs = this.inputFileSystem;
|
129
|
+
for (const item of items) {
|
130
|
+
fs.purge(item);
|
131
|
+
}
|
108
132
|
}
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
133
|
+
return items;
|
134
|
+
},
|
135
|
+
"Watcher.getAggregatedRemovals is deprecated in favor of Watcher.getInfo since that's more performant.",
|
136
|
+
"DEP_WEBPACK_WATCHER_GET_AGGREGATED_REMOVALS"
|
137
|
+
),
|
138
|
+
getAggregatedChanges: util.deprecate(
|
139
|
+
() => {
|
140
|
+
const items = this.watcher && this.watcher.aggregatedChanges;
|
141
|
+
if (items && this.inputFileSystem && this.inputFileSystem.purge) {
|
142
|
+
const fs = this.inputFileSystem;
|
143
|
+
for (const item of items) {
|
144
|
+
fs.purge(item);
|
145
|
+
}
|
146
|
+
}
|
147
|
+
return items;
|
148
|
+
},
|
149
|
+
"Watcher.getAggregatedChanges is deprecated in favor of Watcher.getInfo since that's more performant.",
|
150
|
+
"DEP_WEBPACK_WATCHER_GET_AGGREGATED_CHANGES"
|
151
|
+
),
|
152
|
+
getFileTimeInfoEntries: util.deprecate(
|
153
|
+
() => {
|
154
|
+
return fetchTimeInfo().fileTimeInfoEntries;
|
155
|
+
},
|
156
|
+
"Watcher.getFileTimeInfoEntries is deprecated in favor of Watcher.getInfo since that's more performant.",
|
157
|
+
"DEP_WEBPACK_WATCHER_FILE_TIME_INFO_ENTRIES"
|
158
|
+
),
|
159
|
+
getContextTimeInfoEntries: util.deprecate(
|
160
|
+
() => {
|
161
|
+
return fetchTimeInfo().contextTimeInfoEntries;
|
162
|
+
},
|
163
|
+
"Watcher.getContextTimeInfoEntries is deprecated in favor of Watcher.getInfo since that's more performant.",
|
164
|
+
"DEP_WEBPACK_WATCHER_CONTEXT_TIME_INFO_ENTRIES"
|
165
|
+
),
|
166
|
+
getInfo: () => {
|
167
|
+
const removals = this.watcher && this.watcher.aggregatedRemovals;
|
168
|
+
const changes = this.watcher && this.watcher.aggregatedChanges;
|
169
|
+
if (this.inputFileSystem && this.inputFileSystem.purge) {
|
115
170
|
const fs = this.inputFileSystem;
|
116
|
-
|
117
|
-
|
171
|
+
if (removals) {
|
172
|
+
for (const item of removals) {
|
173
|
+
fs.purge(item);
|
174
|
+
}
|
175
|
+
}
|
176
|
+
if (changes) {
|
177
|
+
for (const item of changes) {
|
178
|
+
fs.purge(item);
|
179
|
+
}
|
118
180
|
}
|
119
181
|
}
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
}
|
128
|
-
},
|
129
|
-
getContextTimeInfoEntries: () => {
|
130
|
-
if (this.watcher) {
|
131
|
-
return this.watcher.getTimeInfoEntries();
|
132
|
-
} else {
|
133
|
-
return new Map();
|
134
|
-
}
|
182
|
+
const { fileTimeInfoEntries, contextTimeInfoEntries } = fetchTimeInfo();
|
183
|
+
return {
|
184
|
+
changes,
|
185
|
+
removals,
|
186
|
+
fileTimeInfoEntries,
|
187
|
+
contextTimeInfoEntries
|
188
|
+
};
|
135
189
|
}
|
136
190
|
};
|
137
191
|
}
|
@@ -15,12 +15,33 @@ const { getInitialChunkIds } = require("../javascript/StartupHelpers");
|
|
15
15
|
const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
16
16
|
const { getUndoPath } = require("../util/identifier");
|
17
17
|
|
18
|
+
/** @typedef {import("../Chunk")} Chunk */
|
19
|
+
|
18
20
|
class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
19
21
|
constructor(runtimeRequirements) {
|
20
22
|
super("readFile chunk loading", RuntimeModule.STAGE_ATTACH);
|
21
23
|
this.runtimeRequirements = runtimeRequirements;
|
22
24
|
}
|
23
25
|
|
26
|
+
/**
|
27
|
+
* @private
|
28
|
+
* @param {Chunk} chunk chunk
|
29
|
+
* @param {string} rootOutputDir root output directory
|
30
|
+
* @returns {string} generated code
|
31
|
+
*/
|
32
|
+
_generateBaseUri(chunk, rootOutputDir) {
|
33
|
+
const options = chunk.getEntryOptions();
|
34
|
+
if (options && options.baseUri) {
|
35
|
+
return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
|
36
|
+
}
|
37
|
+
|
38
|
+
return `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${
|
39
|
+
rootOutputDir
|
40
|
+
? `__dirname + ${JSON.stringify("/" + rootOutputDir)}`
|
41
|
+
: "__filename"
|
42
|
+
});`;
|
43
|
+
}
|
44
|
+
|
24
45
|
/**
|
25
46
|
* @returns {string} runtime code
|
26
47
|
*/
|
@@ -46,7 +67,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|
46
67
|
);
|
47
68
|
const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
|
48
69
|
const hasJsMatcher = compileBooleanMatcher(conditionMap);
|
49
|
-
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph);
|
70
|
+
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
|
50
71
|
|
51
72
|
const outputName = this.compilation.getPath(
|
52
73
|
getChunkFilenameTemplate(chunk, this.compilation.outputOptions),
|
@@ -67,13 +88,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|
67
88
|
|
68
89
|
return Template.asString([
|
69
90
|
withBaseURI
|
70
|
-
?
|
71
|
-
`${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${
|
72
|
-
rootOutputDir
|
73
|
-
? `__dirname + ${JSON.stringify("/" + rootOutputDir)}`
|
74
|
-
: "__filename"
|
75
|
-
});`
|
76
|
-
])
|
91
|
+
? this._generateBaseUri(chunk, rootOutputDir)
|
77
92
|
: "// no baseURI",
|
78
93
|
"",
|
79
94
|
"// object to store loaded chunks",
|
@@ -15,12 +15,33 @@ const { getInitialChunkIds } = require("../javascript/StartupHelpers");
|
|
15
15
|
const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
16
16
|
const { getUndoPath } = require("../util/identifier");
|
17
17
|
|
18
|
+
/** @typedef {import("../Chunk")} Chunk */
|
19
|
+
|
18
20
|
class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
19
21
|
constructor(runtimeRequirements) {
|
20
22
|
super("require chunk loading", RuntimeModule.STAGE_ATTACH);
|
21
23
|
this.runtimeRequirements = runtimeRequirements;
|
22
24
|
}
|
23
25
|
|
26
|
+
/**
|
27
|
+
* @private
|
28
|
+
* @param {Chunk} chunk chunk
|
29
|
+
* @param {string} rootOutputDir root output directory
|
30
|
+
* @returns {string} generated code
|
31
|
+
*/
|
32
|
+
_generateBaseUri(chunk, rootOutputDir) {
|
33
|
+
const options = chunk.getEntryOptions();
|
34
|
+
if (options && options.baseUri) {
|
35
|
+
return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
|
36
|
+
}
|
37
|
+
|
38
|
+
return `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${
|
39
|
+
rootOutputDir !== "./"
|
40
|
+
? `__dirname + ${JSON.stringify("/" + rootOutputDir)}`
|
41
|
+
: "__filename"
|
42
|
+
});`;
|
43
|
+
}
|
44
|
+
|
24
45
|
/**
|
25
46
|
* @returns {string} runtime code
|
26
47
|
*/
|
@@ -46,7 +67,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|
46
67
|
);
|
47
68
|
const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
|
48
69
|
const hasJsMatcher = compileBooleanMatcher(conditionMap);
|
49
|
-
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph);
|
70
|
+
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
|
50
71
|
|
51
72
|
const outputName = this.compilation.getPath(
|
52
73
|
getChunkFilenameTemplate(chunk, this.compilation.outputOptions),
|
@@ -67,13 +88,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|
67
88
|
|
68
89
|
return Template.asString([
|
69
90
|
withBaseURI
|
70
|
-
?
|
71
|
-
`${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${
|
72
|
-
rootOutputDir !== "./"
|
73
|
-
? `__dirname + ${JSON.stringify("/" + rootOutputDir)}`
|
74
|
-
: "__filename"
|
75
|
-
});`
|
76
|
-
])
|
91
|
+
? this._generateBaseUri(chunk, rootOutputDir)
|
77
92
|
: "// no baseURI",
|
78
93
|
"",
|
79
94
|
"// object to store loaded chunks",
|
@@ -211,7 +226,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|
211
226
|
RuntimeGlobals.getUpdateManifestFilename
|
212
227
|
}());`
|
213
228
|
]),
|
214
|
-
|
229
|
+
"})['catch'](function(err) { if(err.code !== 'MODULE_NOT_FOUND') throw err; });"
|
215
230
|
]),
|
216
231
|
"}"
|
217
232
|
])
|
@@ -39,6 +39,7 @@ const {
|
|
39
39
|
/** @typedef {import("webpack-sources").Source} Source */
|
40
40
|
/** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
41
41
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
42
|
+
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
42
43
|
/** @typedef {import("../Compilation")} Compilation */
|
43
44
|
/** @typedef {import("../Dependency")} Dependency */
|
44
45
|
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
@@ -821,10 +822,6 @@ class ConcatenatedModule extends Module {
|
|
821
822
|
const topLevelDeclarations = this.buildInfo.topLevelDeclarations;
|
822
823
|
if (topLevelDeclarations !== undefined) {
|
823
824
|
for (const decl of m.buildInfo.topLevelDeclarations) {
|
824
|
-
// reserved names will always be renamed
|
825
|
-
if (RESERVED_NAMES.has(decl)) continue;
|
826
|
-
// TODO actually this is incorrect since with renaming there could be more
|
827
|
-
// We should do the renaming during build
|
828
825
|
topLevelDeclarations.add(decl);
|
829
826
|
}
|
830
827
|
}
|
@@ -1077,7 +1074,8 @@ class ConcatenatedModule extends Module {
|
|
1077
1074
|
runtimeTemplate,
|
1078
1075
|
moduleGraph,
|
1079
1076
|
chunkGraph,
|
1080
|
-
runtime: generationRuntime
|
1077
|
+
runtime: generationRuntime,
|
1078
|
+
codeGenerationResults
|
1081
1079
|
}) {
|
1082
1080
|
/** @type {Set<string>} */
|
1083
1081
|
const runtimeRequirements = new Set();
|
@@ -1104,12 +1102,15 @@ class ConcatenatedModule extends Module {
|
|
1104
1102
|
runtimeTemplate,
|
1105
1103
|
moduleGraph,
|
1106
1104
|
chunkGraph,
|
1107
|
-
runtime
|
1105
|
+
runtime,
|
1106
|
+
codeGenerationResults
|
1108
1107
|
);
|
1109
1108
|
}
|
1110
1109
|
|
1111
1110
|
// List of all used names to avoid conflicts
|
1112
1111
|
const allUsedNames = new Set(RESERVED_NAMES);
|
1112
|
+
// Updated Top level declarations are created by renaming
|
1113
|
+
const topLevelDeclarations = new Set();
|
1113
1114
|
|
1114
1115
|
// List of additional names in scope for module references
|
1115
1116
|
/** @type {Map<string, { usedNames: Set<string>, alreadyCheckedScopes: Set<TODO> }>} */
|
@@ -1254,6 +1255,7 @@ class ConcatenatedModule extends Module {
|
|
1254
1255
|
);
|
1255
1256
|
allUsedNames.add(newName);
|
1256
1257
|
info.internalNames.set(name, newName);
|
1258
|
+
topLevelDeclarations.add(newName);
|
1257
1259
|
const source = info.source;
|
1258
1260
|
const allIdentifiers = new Set(
|
1259
1261
|
references.map(r => r.identifier).concat(variable.identifiers)
|
@@ -1280,6 +1282,7 @@ class ConcatenatedModule extends Module {
|
|
1280
1282
|
} else {
|
1281
1283
|
allUsedNames.add(name);
|
1282
1284
|
info.internalNames.set(name, name);
|
1285
|
+
topLevelDeclarations.add(name);
|
1283
1286
|
}
|
1284
1287
|
}
|
1285
1288
|
let namespaceObjectName;
|
@@ -1297,6 +1300,7 @@ class ConcatenatedModule extends Module {
|
|
1297
1300
|
allUsedNames.add(namespaceObjectName);
|
1298
1301
|
}
|
1299
1302
|
info.namespaceObjectName = namespaceObjectName;
|
1303
|
+
topLevelDeclarations.add(namespaceObjectName);
|
1300
1304
|
break;
|
1301
1305
|
}
|
1302
1306
|
case "external": {
|
@@ -1308,6 +1312,7 @@ class ConcatenatedModule extends Module {
|
|
1308
1312
|
);
|
1309
1313
|
allUsedNames.add(externalName);
|
1310
1314
|
info.name = externalName;
|
1315
|
+
topLevelDeclarations.add(externalName);
|
1311
1316
|
break;
|
1312
1317
|
}
|
1313
1318
|
}
|
@@ -1320,6 +1325,7 @@ class ConcatenatedModule extends Module {
|
|
1320
1325
|
);
|
1321
1326
|
allUsedNames.add(externalNameInterop);
|
1322
1327
|
info.interopNamespaceObjectName = externalNameInterop;
|
1328
|
+
topLevelDeclarations.add(externalNameInterop);
|
1323
1329
|
}
|
1324
1330
|
if (
|
1325
1331
|
info.module.buildMeta.exportsType === "default" &&
|
@@ -1333,6 +1339,7 @@ class ConcatenatedModule extends Module {
|
|
1333
1339
|
);
|
1334
1340
|
allUsedNames.add(externalNameInterop);
|
1335
1341
|
info.interopNamespaceObject2Name = externalNameInterop;
|
1342
|
+
topLevelDeclarations.add(externalNameInterop);
|
1336
1343
|
}
|
1337
1344
|
if (
|
1338
1345
|
info.module.buildMeta.exportsType === "dynamic" ||
|
@@ -1346,6 +1353,7 @@ class ConcatenatedModule extends Module {
|
|
1346
1353
|
);
|
1347
1354
|
allUsedNames.add(externalNameInterop);
|
1348
1355
|
info.interopDefaultAccessName = externalNameInterop;
|
1356
|
+
topLevelDeclarations.add(externalNameInterop);
|
1349
1357
|
}
|
1350
1358
|
}
|
1351
1359
|
|
@@ -1615,6 +1623,7 @@ ${defineGetters}`
|
|
1615
1623
|
const data = new Map();
|
1616
1624
|
if (chunkInitFragments.length > 0)
|
1617
1625
|
data.set("chunkInitFragments", chunkInitFragments);
|
1626
|
+
data.set("topLevelDeclarations", topLevelDeclarations);
|
1618
1627
|
|
1619
1628
|
/** @type {CodeGenerationResult} */
|
1620
1629
|
const resultEntry = {
|
@@ -1634,6 +1643,7 @@ ${defineGetters}`
|
|
1634
1643
|
* @param {ModuleGraph} moduleGraph moduleGraph
|
1635
1644
|
* @param {ChunkGraph} chunkGraph chunkGraph
|
1636
1645
|
* @param {RuntimeSpec} runtime runtime
|
1646
|
+
* @param {CodeGenerationResults} codeGenerationResults codeGenerationResults
|
1637
1647
|
*/
|
1638
1648
|
_analyseModule(
|
1639
1649
|
modulesMap,
|
@@ -1642,7 +1652,8 @@ ${defineGetters}`
|
|
1642
1652
|
runtimeTemplate,
|
1643
1653
|
moduleGraph,
|
1644
1654
|
chunkGraph,
|
1645
|
-
runtime
|
1655
|
+
runtime,
|
1656
|
+
codeGenerationResults
|
1646
1657
|
) {
|
1647
1658
|
if (info.type === "concatenated") {
|
1648
1659
|
const m = info.module;
|
@@ -1657,7 +1668,8 @@ ${defineGetters}`
|
|
1657
1668
|
moduleGraph,
|
1658
1669
|
chunkGraph,
|
1659
1670
|
runtime,
|
1660
|
-
concatenationScope
|
1671
|
+
concatenationScope,
|
1672
|
+
codeGenerationResults
|
1661
1673
|
});
|
1662
1674
|
const source = codeGenResult.sources.get("javascript");
|
1663
1675
|
const data = codeGenResult.data;
|
@@ -1702,7 +1714,7 @@ ${defineGetters}`
|
|
1702
1714
|
info.globalScope = globalScope;
|
1703
1715
|
info.moduleScope = moduleScope;
|
1704
1716
|
} catch (err) {
|
1705
|
-
err.message += `\nwhile
|
1717
|
+
err.message += `\nwhile analyzing module ${m.identifier()} for concatenation`;
|
1706
1718
|
throw err;
|
1707
1719
|
}
|
1708
1720
|
}
|
@@ -56,6 +56,7 @@ class ModuleConcatenationPlugin {
|
|
56
56
|
* @returns {void}
|
57
57
|
*/
|
58
58
|
apply(compiler) {
|
59
|
+
const { _backCompat: backCompat } = compiler;
|
59
60
|
compiler.hooks.compilation.tap("ModuleConcatenationPlugin", compilation => {
|
60
61
|
const moduleGraph = compilation.moduleGraph;
|
61
62
|
const bailoutReasonMap = new Map();
|
@@ -389,8 +390,10 @@ class ModuleConcatenationPlugin {
|
|
389
390
|
};
|
390
391
|
|
391
392
|
const integrate = () => {
|
392
|
-
|
393
|
-
|
393
|
+
if (backCompat) {
|
394
|
+
ChunkGraph.setChunkGraphForModule(newModule, chunkGraph);
|
395
|
+
ModuleGraph.setModuleGraphForModule(newModule, moduleGraph);
|
396
|
+
}
|
394
397
|
|
395
398
|
for (const warning of concatConfiguration.getWarningsSorted()) {
|
396
399
|
moduleGraph
|
@@ -102,6 +102,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
|
102
102
|
|
103
103
|
/**
|
104
104
|
* @typedef {Object} FallbackCacheGroup
|
105
|
+
* @property {ChunkFilterFunction} chunksFilter
|
105
106
|
* @property {SplitChunksSizes} minSize
|
106
107
|
* @property {SplitChunksSizes} maxAsyncSize
|
107
108
|
* @property {SplitChunksSizes} maxInitialSize
|
@@ -658,6 +659,9 @@ module.exports = class SplitChunksPlugin {
|
|
658
659
|
automaticNameDelimiter: options.automaticNameDelimiter,
|
659
660
|
usedExports: options.usedExports,
|
660
661
|
fallbackCacheGroup: {
|
662
|
+
chunksFilter: normalizeChunksFilter(
|
663
|
+
fallbackCacheGroup.chunks || options.chunks || "all"
|
664
|
+
),
|
661
665
|
minSize: mergeSizes(
|
662
666
|
normalizeSizes(fallbackCacheGroup.minSize, defaultSizeTypes),
|
663
667
|
minSize
|
@@ -1598,6 +1602,7 @@ module.exports = class SplitChunksPlugin {
|
|
1598
1602
|
const { outputOptions } = compilation;
|
1599
1603
|
|
1600
1604
|
// Make sure that maxSize is fulfilled
|
1605
|
+
const { fallbackCacheGroup } = this.options;
|
1601
1606
|
for (const chunk of Array.from(compilation.chunks)) {
|
1602
1607
|
const chunkConfig = maxSizeQueueMap.get(chunk);
|
1603
1608
|
const {
|
@@ -1605,7 +1610,9 @@ module.exports = class SplitChunksPlugin {
|
|
1605
1610
|
maxAsyncSize,
|
1606
1611
|
maxInitialSize,
|
1607
1612
|
automaticNameDelimiter
|
1608
|
-
} = chunkConfig ||
|
1613
|
+
} = chunkConfig || fallbackCacheGroup;
|
1614
|
+
if (!chunkConfig && !fallbackCacheGroup.chunksFilter(chunk))
|
1615
|
+
continue;
|
1609
1616
|
/** @type {SplitChunksSizes} */
|
1610
1617
|
let maxSize;
|
1611
1618
|
if (chunk.isOnlyInitial()) {
|
@@ -22,6 +22,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
22
22
|
return Template.asString([
|
23
23
|
'var webpackThen = typeof Symbol === "function" ? Symbol("webpack then") : "__webpack_then__";',
|
24
24
|
'var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "__webpack_exports__";',
|
25
|
+
'var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__";',
|
25
26
|
`var completeQueue = ${runtimeTemplate.basicFunction("queue", [
|
26
27
|
"if(queue) {",
|
27
28
|
Template.indent([
|
@@ -56,10 +57,14 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
56
57
|
"obj[webpackExports] = r;",
|
57
58
|
"completeQueue(queue);",
|
58
59
|
"queue = 0;"
|
60
|
+
])}, ${runtimeTemplate.basicFunction("e", [
|
61
|
+
"obj[webpackError] = e;",
|
62
|
+
"completeQueue(queue);",
|
63
|
+
"queue = 0;"
|
59
64
|
])});`,
|
60
|
-
|
61
|
-
obj[webpackThen] = ${runtimeTemplate.expressionFunction(
|
62
|
-
"queueFunction(queue, fn), dep
|
65
|
+
"var obj = {};",
|
66
|
+
`obj[webpackThen] = ${runtimeTemplate.expressionFunction(
|
67
|
+
"queueFunction(queue, fn), dep['catch'](reject)",
|
63
68
|
"fn, reject"
|
64
69
|
)};`,
|
65
70
|
"return obj;"
|
@@ -67,13 +72,13 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
67
72
|
"}"
|
68
73
|
]),
|
69
74
|
"}",
|
70
|
-
|
71
|
-
ret[webpackThen] = ${runtimeTemplate.expressionFunction(
|
75
|
+
"var ret = {};",
|
76
|
+
`ret[webpackThen] = ${runtimeTemplate.expressionFunction(
|
72
77
|
"completeFunction(fn)",
|
73
78
|
"fn"
|
74
|
-
)}
|
75
|
-
ret[webpackExports] = dep;
|
76
|
-
return ret
|
79
|
+
)};`,
|
80
|
+
"ret[webpackExports] = dep;",
|
81
|
+
"return ret;"
|
77
82
|
])})`,
|
78
83
|
"deps"
|
79
84
|
)};`,
|
@@ -114,29 +119,34 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
|
|
114
119
|
"if (isEvaluating) { return completeFunction(fn); }",
|
115
120
|
"if (currentDeps) whenAll(currentDeps, fn, rejectFn);",
|
116
121
|
"queueFunction(queue, fn);",
|
117
|
-
"promise
|
122
|
+
"promise['catch'](rejectFn);"
|
118
123
|
]
|
119
124
|
)};`,
|
120
125
|
"module.exports = promise;",
|
121
126
|
`body(${runtimeTemplate.basicFunction("deps", [
|
122
|
-
"if(!deps) return outerResolve();",
|
123
127
|
"currentDeps = wrapDeps(deps);",
|
124
|
-
"var fn
|
128
|
+
"var fn;",
|
129
|
+
`var getResult = ${runtimeTemplate.returningFunction(
|
130
|
+
`currentDeps.map(${runtimeTemplate.basicFunction("d", [
|
131
|
+
"if(d[webpackError]) throw d[webpackError];",
|
132
|
+
"return d[webpackExports];"
|
133
|
+
])})`
|
134
|
+
)}`,
|
125
135
|
`var promise = new Promise(${runtimeTemplate.basicFunction(
|
126
136
|
"resolve, reject",
|
127
137
|
[
|
128
138
|
`fn = ${runtimeTemplate.expressionFunction(
|
129
|
-
|
130
|
-
"d[webpackExports]",
|
131
|
-
"d"
|
132
|
-
)}))`
|
139
|
+
"resolve(getResult)"
|
133
140
|
)};`,
|
134
141
|
"fn.r = 0;",
|
135
142
|
"whenAll(currentDeps, fn, reject);"
|
136
143
|
]
|
137
144
|
)});`,
|
138
|
-
"return fn.r ? promise :
|
139
|
-
])}
|
145
|
+
"return fn.r ? promise : getResult();"
|
146
|
+
])}, ${runtimeTemplate.expressionFunction(
|
147
|
+
"err && reject(promise[webpackError] = err), outerResolve()",
|
148
|
+
"err"
|
149
|
+
)});`,
|
140
150
|
"isEvaluating = false;"
|
141
151
|
])};`
|
142
152
|
]);
|
@@ -0,0 +1,31 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Ivan Kopeykin @vankop
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
9
|
+
const RuntimeModule = require("../RuntimeModule");
|
10
|
+
|
11
|
+
class BaseUriRuntimeModule extends RuntimeModule {
|
12
|
+
constructor() {
|
13
|
+
super("base uri", RuntimeModule.STAGE_ATTACH);
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @returns {string} runtime code
|
18
|
+
*/
|
19
|
+
generate() {
|
20
|
+
const { chunk } = this;
|
21
|
+
|
22
|
+
const options = chunk.getEntryOptions();
|
23
|
+
return `${RuntimeGlobals.baseURI} = ${
|
24
|
+
options.baseUri === undefined
|
25
|
+
? "undefined"
|
26
|
+
: JSON.stringify(options.baseUri)
|
27
|
+
};`;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
module.exports = BaseUriRuntimeModule;
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
*/
|
4
|
+
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const RuntimeGlobals = require("../RuntimeGlobals");
|
8
|
+
const Template = require("../Template");
|
9
|
+
const HelperRuntimeModule = require("./HelperRuntimeModule");
|
10
|
+
|
11
|
+
class CreateScriptRuntimeModule extends HelperRuntimeModule {
|
12
|
+
constructor() {
|
13
|
+
super("trusted types script");
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @returns {string} runtime code
|
18
|
+
*/
|
19
|
+
generate() {
|
20
|
+
const { compilation } = this;
|
21
|
+
const { runtimeTemplate, outputOptions } = compilation;
|
22
|
+
const { trustedTypes } = outputOptions;
|
23
|
+
const fn = RuntimeGlobals.createScript;
|
24
|
+
|
25
|
+
return Template.asString(
|
26
|
+
`${fn} = ${runtimeTemplate.returningFunction(
|
27
|
+
trustedTypes
|
28
|
+
? `${RuntimeGlobals.getTrustedTypesPolicy}().createScript(script)`
|
29
|
+
: "script",
|
30
|
+
"script"
|
31
|
+
)};`
|
32
|
+
);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
module.exports = CreateScriptRuntimeModule;
|
@@ -10,7 +10,7 @@ const HelperRuntimeModule = require("./HelperRuntimeModule");
|
|
10
10
|
|
11
11
|
class CreateScriptUrlRuntimeModule extends HelperRuntimeModule {
|
12
12
|
constructor() {
|
13
|
-
super("trusted types");
|
13
|
+
super("trusted types script url");
|
14
14
|
}
|
15
15
|
|
16
16
|
/**
|
@@ -22,39 +22,14 @@ class CreateScriptUrlRuntimeModule extends HelperRuntimeModule {
|
|
22
22
|
const { trustedTypes } = outputOptions;
|
23
23
|
const fn = RuntimeGlobals.createScriptUrl;
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
"var policy;",
|
34
|
-
`${fn} = ${runtimeTemplate.basicFunction("url", [
|
35
|
-
"// Create Trusted Type policy if Trusted Types are available and the policy doesn't exist yet.",
|
36
|
-
"if (policy === undefined) {",
|
37
|
-
Template.indent([
|
38
|
-
"policy = {",
|
39
|
-
Template.indent([
|
40
|
-
`createScriptURL: ${runtimeTemplate.returningFunction(
|
41
|
-
"url",
|
42
|
-
"url"
|
43
|
-
)}`
|
44
|
-
]),
|
45
|
-
"};",
|
46
|
-
'if (typeof trustedTypes !== "undefined" && trustedTypes.createPolicy) {',
|
47
|
-
Template.indent([
|
48
|
-
`policy = trustedTypes.createPolicy(${JSON.stringify(
|
49
|
-
trustedTypes.policyName
|
50
|
-
)}, policy);`
|
51
|
-
]),
|
52
|
-
"}"
|
53
|
-
]),
|
54
|
-
"}",
|
55
|
-
"return policy.createScriptURL(url);"
|
56
|
-
])};`
|
57
|
-
]);
|
25
|
+
return Template.asString(
|
26
|
+
`${fn} = ${runtimeTemplate.returningFunction(
|
27
|
+
trustedTypes
|
28
|
+
? `${RuntimeGlobals.getTrustedTypesPolicy}().createScriptURL(url)`
|
29
|
+
: "url",
|
30
|
+
"url"
|
31
|
+
)};`
|
32
|
+
);
|
58
33
|
}
|
59
34
|
}
|
60
35
|
|