webpack 5.91.0 → 5.92.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/bin/webpack.js +1 -2
- package/lib/APIPlugin.js +6 -2
- package/lib/Cache.js +1 -1
- package/lib/Chunk.js +7 -4
- package/lib/ChunkGraph.js +20 -7
- package/lib/ChunkGroup.js +9 -3
- package/lib/CleanPlugin.js +1 -1
- package/lib/Compilation.js +33 -27
- package/lib/Compiler.js +28 -8
- package/lib/ConcatenationScope.js +3 -3
- package/lib/ContextModule.js +95 -43
- package/lib/DefinePlugin.js +14 -4
- package/lib/Dependency.js +8 -8
- package/lib/DependencyTemplate.js +10 -5
- package/lib/DllReferencePlugin.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +11 -0
- package/lib/ExportsInfo.js +22 -4
- package/lib/ExternalModule.js +49 -18
- package/lib/FileSystemInfo.js +68 -41
- package/lib/FlagDependencyExportsPlugin.js +21 -7
- package/lib/Generator.js +2 -3
- package/lib/HotModuleReplacementPlugin.js +108 -45
- package/lib/IgnorePlugin.js +4 -1
- package/lib/LibManifestPlugin.js +2 -2
- package/lib/Module.js +11 -12
- package/lib/ModuleFactory.js +3 -3
- package/lib/ModuleFilenameHelpers.js +29 -16
- package/lib/ModuleGraph.js +5 -5
- package/lib/MultiCompiler.js +36 -1
- package/lib/NormalModule.js +10 -12
- package/lib/NormalModuleFactory.js +17 -8
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/ProgressPlugin.js +1 -1
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/ResolverFactory.js +3 -3
- package/lib/RuntimeTemplate.js +22 -18
- package/lib/Stats.js +1 -1
- package/lib/Template.js +5 -5
- package/lib/TemplatedPathPlugin.js +16 -1
- package/lib/asset/AssetGenerator.js +15 -0
- package/lib/buildChunkGraph.js +3 -3
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +2 -2
- package/lib/cache/ResolverCachePlugin.js +8 -8
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/cli.js +5 -5
- package/lib/config/browserslistTargetHandler.js +7 -1
- package/lib/config/defaults.js +85 -34
- package/lib/config/target.js +18 -11
- package/lib/container/ContainerEntryModule.js +1 -1
- package/lib/css/CssExportsGenerator.js +43 -17
- package/lib/css/CssGenerator.js +22 -12
- package/lib/css/CssLoadingRuntimeModule.js +8 -5
- package/lib/css/CssModulesPlugin.js +197 -100
- package/lib/css/CssParser.js +24 -15
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +2 -2
- package/lib/dependencies/CssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +9 -2
- package/lib/dependencies/CssUrlDependency.js +5 -4
- package/lib/dependencies/ExportsInfoDependency.js +1 -1
- package/lib/dependencies/ExternalModuleDependency.js +4 -2
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +41 -18
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +43 -32
- package/lib/dependencies/ImportDependency.js +2 -2
- package/lib/dependencies/ImportEagerDependency.js +2 -2
- package/lib/dependencies/ImportMetaPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +3 -1
- package/lib/dependencies/ImportWeakDependency.js +2 -2
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/dependencies/ModuleDependency.js +2 -2
- package/lib/dependencies/PureExpressionDependency.js +63 -49
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +90 -2
- package/lib/hmr/LazyCompilationPlugin.js +2 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +6 -6
- package/lib/ids/NamedChunkIdsPlugin.js +1 -1
- package/lib/ids/NamedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/index.js +11 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +0 -1
- package/lib/javascript/JavascriptModulesPlugin.js +174 -17
- package/lib/javascript/JavascriptParser.js +37 -16
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +3 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
- package/lib/library/JsonpLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +2 -2
- package/lib/library/SystemLibraryPlugin.js +2 -2
- package/lib/library/UmdLibraryPlugin.js +33 -12
- package/lib/logging/createConsoleLogger.js +2 -2
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeEnvironmentPlugin.js +1 -1
- package/lib/node/NodeTemplatePlugin.js +1 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
- package/lib/node/nodeConsole.js +1 -1
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +11 -76
- package/lib/optimize/InnerGraph.js +1 -1
- package/lib/optimize/LimitChunkCountPlugin.js +1 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +1 -1
- package/lib/optimize/RealContentHashPlugin.js +3 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +2 -2
- package/lib/optimize/SplitChunksPlugin.js +8 -8
- package/lib/performance/SizeLimitsPlugin.js +2 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +11 -1
- package/lib/rules/RuleSetCompiler.js +9 -7
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +4 -4
- package/lib/serialization/FileMiddleware.js +3 -3
- package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
- package/lib/serialization/ObjectMiddleware.js +6 -5
- package/lib/serialization/PlainObjectSerializer.js +2 -2
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/serialization/SingleItemMiddleware.js +2 -2
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/stats/StatsPrinter.js +6 -6
- package/lib/util/ArrayQueue.js +14 -21
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Queue.js +8 -2
- package/lib/util/SortableSet.js +16 -4
- package/lib/util/TupleQueue.js +8 -2
- package/lib/util/WeakTupleMap.js +3 -3
- package/lib/util/binarySearchBounds.js +1 -1
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +4 -2
- package/lib/util/conventions.js +1 -1
- package/lib/util/createHash.js +3 -5
- package/lib/util/deprecation.js +3 -3
- package/lib/util/deterministicGrouping.js +2 -2
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +15 -15
- package/lib/util/identifier.js +5 -5
- package/lib/util/mergeScope.js +79 -0
- package/lib/util/runtime.js +2 -17
- package/lib/util/semver.js +3 -0
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +17 -17
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webpack.js +12 -3
- package/package.json +20 -18
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +30 -2
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +213 -81
@@ -22,7 +22,7 @@ const { getUndoPath } = require("../util/identifier");
|
|
22
22
|
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
23
23
|
|
24
24
|
/**
|
25
|
-
* @typedef {
|
25
|
+
* @typedef {object} JsonpCompilationPluginHooks
|
26
26
|
* @property {SyncWaterfallHook<[string, Chunk]>} linkPreload
|
27
27
|
* @property {SyncWaterfallHook<[string, Chunk]>} linkPrefetch
|
28
28
|
*/
|
@@ -89,7 +89,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
89
89
|
const chunk = /** @type {Chunk} */ (this.chunk);
|
90
90
|
const {
|
91
91
|
runtimeTemplate,
|
92
|
-
outputOptions: { importFunctionName }
|
92
|
+
outputOptions: { environment, importFunctionName, crossOriginLoading }
|
93
93
|
} = compilation;
|
94
94
|
const fn = RuntimeGlobals.ensureChunkHandlers;
|
95
95
|
const withBaseURI = this._runtimeRequirements.has(RuntimeGlobals.baseURI);
|
@@ -105,6 +105,14 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
105
105
|
const withHmr = this._runtimeRequirements.has(
|
106
106
|
RuntimeGlobals.hmrDownloadUpdateHandlers
|
107
107
|
);
|
108
|
+
const { linkPreload, linkPrefetch } =
|
109
|
+
ModuleChunkLoadingRuntimeModule.getCompilationHooks(compilation);
|
110
|
+
const withPrefetch =
|
111
|
+
environment.document &&
|
112
|
+
this._runtimeRequirements.has(RuntimeGlobals.prefetchChunkHandlers);
|
113
|
+
const withPreload =
|
114
|
+
environment.document &&
|
115
|
+
this._runtimeRequirements.has(RuntimeGlobals.preloadChunkHandlers);
|
108
116
|
const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
|
109
117
|
const hasJsMatcher = compileBooleanMatcher(conditionMap);
|
110
118
|
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
|
@@ -229,6 +237,86 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|
229
237
|
])
|
230
238
|
: "// no chunk on demand loading",
|
231
239
|
"",
|
240
|
+
withPrefetch && hasJsMatcher !== false
|
241
|
+
? `${
|
242
|
+
RuntimeGlobals.prefetchChunkHandlers
|
243
|
+
}.j = ${runtimeTemplate.basicFunction("chunkId", [
|
244
|
+
`if((!${
|
245
|
+
RuntimeGlobals.hasOwnProperty
|
246
|
+
}(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
|
247
|
+
hasJsMatcher === true ? "true" : hasJsMatcher("chunkId")
|
248
|
+
}) {`,
|
249
|
+
Template.indent([
|
250
|
+
"installedChunks[chunkId] = null;",
|
251
|
+
linkPrefetch.call(
|
252
|
+
Template.asString([
|
253
|
+
"var link = document.createElement('link');",
|
254
|
+
crossOriginLoading
|
255
|
+
? `link.crossOrigin = ${JSON.stringify(
|
256
|
+
crossOriginLoading
|
257
|
+
)};`
|
258
|
+
: "",
|
259
|
+
`if (${RuntimeGlobals.scriptNonce}) {`,
|
260
|
+
Template.indent(
|
261
|
+
`link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
|
262
|
+
),
|
263
|
+
"}",
|
264
|
+
'link.rel = "prefetch";',
|
265
|
+
'link.as = "script";',
|
266
|
+
`link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`
|
267
|
+
]),
|
268
|
+
chunk
|
269
|
+
),
|
270
|
+
"document.head.appendChild(link);"
|
271
|
+
]),
|
272
|
+
"}"
|
273
|
+
])};`
|
274
|
+
: "// no prefetching",
|
275
|
+
"",
|
276
|
+
withPreload && hasJsMatcher !== false
|
277
|
+
? `${
|
278
|
+
RuntimeGlobals.preloadChunkHandlers
|
279
|
+
}.j = ${runtimeTemplate.basicFunction("chunkId", [
|
280
|
+
`if((!${
|
281
|
+
RuntimeGlobals.hasOwnProperty
|
282
|
+
}(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
|
283
|
+
hasJsMatcher === true ? "true" : hasJsMatcher("chunkId")
|
284
|
+
}) {`,
|
285
|
+
Template.indent([
|
286
|
+
"installedChunks[chunkId] = null;",
|
287
|
+
linkPreload.call(
|
288
|
+
Template.asString([
|
289
|
+
"var link = document.createElement('link');",
|
290
|
+
"link.charset = 'utf-8';",
|
291
|
+
`if (${RuntimeGlobals.scriptNonce}) {`,
|
292
|
+
Template.indent(
|
293
|
+
`link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
|
294
|
+
),
|
295
|
+
"}",
|
296
|
+
'link.rel = "modulepreload";',
|
297
|
+
`link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`,
|
298
|
+
crossOriginLoading
|
299
|
+
? crossOriginLoading === "use-credentials"
|
300
|
+
? 'link.crossOrigin = "use-credentials";'
|
301
|
+
: Template.asString([
|
302
|
+
"if (link.href.indexOf(window.location.origin + '/') !== 0) {",
|
303
|
+
Template.indent(
|
304
|
+
`link.crossOrigin = ${JSON.stringify(
|
305
|
+
crossOriginLoading
|
306
|
+
)};`
|
307
|
+
),
|
308
|
+
"}"
|
309
|
+
])
|
310
|
+
: ""
|
311
|
+
]),
|
312
|
+
chunk
|
313
|
+
),
|
314
|
+
"document.head.appendChild(link);"
|
315
|
+
]),
|
316
|
+
"}"
|
317
|
+
])};`
|
318
|
+
: "// no preloaded",
|
319
|
+
"",
|
232
320
|
withExternalInstallChunk
|
233
321
|
? Template.asString([
|
234
322
|
`${RuntimeGlobals.externalInstallChunk} = installChunk;`
|
@@ -38,7 +38,7 @@ const { registerNotSerializable } = require("../util/serialization");
|
|
38
38
|
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
39
39
|
|
40
40
|
/**
|
41
|
-
* @typedef {
|
41
|
+
* @typedef {object} BackendApi
|
42
42
|
* @property {function(Error=): void} dispose
|
43
43
|
* @property {function(Module): { client: string, data: string, active: boolean }} module
|
44
44
|
*/
|
@@ -319,7 +319,7 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
|
|
319
319
|
|
320
320
|
class LazyCompilationPlugin {
|
321
321
|
/**
|
322
|
-
* @param {
|
322
|
+
* @param {object} options options
|
323
323
|
* @param {(function(Compiler, function(Error?, BackendApi?): void): void) | function(Compiler): Promise<BackendApi>} options.backend the backend
|
324
324
|
* @param {boolean} options.entries true, when entries are lazy compiled
|
325
325
|
* @param {boolean} options.imports true, when import() modules are lazy compiled
|
@@ -14,7 +14,7 @@ const {
|
|
14
14
|
/** @typedef {import("../Compiler")} Compiler */
|
15
15
|
|
16
16
|
/**
|
17
|
-
* @typedef {
|
17
|
+
* @typedef {object} ChunkModuleIdRangePluginOptions
|
18
18
|
* @property {string} name the chunk name
|
19
19
|
* @property {("index" | "index2" | "preOrderIndex" | "postOrderIndex")=} order order
|
20
20
|
* @property {number=} start start id
|
@@ -16,7 +16,7 @@ const {
|
|
16
16
|
/** @typedef {import("../Module")} Module */
|
17
17
|
|
18
18
|
/**
|
19
|
-
* @typedef {
|
19
|
+
* @typedef {object} DeterministicChunkIdsPluginOptions
|
20
20
|
* @property {string=} context context for ids
|
21
21
|
* @property {number=} maxLength maximum length of ids
|
22
22
|
*/
|
@@ -18,7 +18,7 @@ const {
|
|
18
18
|
/** @typedef {import("../Module")} Module */
|
19
19
|
|
20
20
|
/**
|
21
|
-
* @typedef {
|
21
|
+
* @typedef {object} DeterministicModuleIdsPluginOptions
|
22
22
|
* @property {string=} context context relative to which module identifiers are computed
|
23
23
|
* @property {function(Module): boolean=} test selector function for modules
|
24
24
|
* @property {number=} maxLength maximum id length in digits (used as starting point)
|
package/lib/ids/IdHelpers.js
CHANGED
@@ -78,7 +78,7 @@ const shortenLongString = (string, delimiter, hashFunction) => {
|
|
78
78
|
/**
|
79
79
|
* @param {Module} module the module
|
80
80
|
* @param {string} context context directory
|
81
|
-
* @param {
|
81
|
+
* @param {object=} associatedObjectForCache an object to which the cache will be attached
|
82
82
|
* @returns {string} short module name
|
83
83
|
*/
|
84
84
|
const getShortModuleName = (module, context, associatedObjectForCache) => {
|
@@ -98,7 +98,7 @@ exports.getShortModuleName = getShortModuleName;
|
|
98
98
|
* @param {Module} module the module
|
99
99
|
* @param {string} context context directory
|
100
100
|
* @param {string | Hash} hashFunction hash function to use
|
101
|
-
* @param {
|
101
|
+
* @param {object=} associatedObjectForCache an object to which the cache will be attached
|
102
102
|
* @returns {string} long module name
|
103
103
|
*/
|
104
104
|
const getLongModuleName = (
|
@@ -116,7 +116,7 @@ exports.getLongModuleName = getLongModuleName;
|
|
116
116
|
/**
|
117
117
|
* @param {Module} module the module
|
118
118
|
* @param {string} context context directory
|
119
|
-
* @param {
|
119
|
+
* @param {object=} associatedObjectForCache an object to which the cache will be attached
|
120
120
|
* @returns {string} full module name
|
121
121
|
*/
|
122
122
|
const getFullModuleName = (module, context, associatedObjectForCache) => {
|
@@ -134,7 +134,7 @@ exports.getFullModuleName = getFullModuleName;
|
|
134
134
|
* @param {string} context context directory
|
135
135
|
* @param {string} delimiter delimiter for names
|
136
136
|
* @param {string | Hash} hashFunction hash function to use
|
137
|
-
* @param {
|
137
|
+
* @param {object=} associatedObjectForCache an object to which the cache will be attached
|
138
138
|
* @returns {string} short chunk name
|
139
139
|
*/
|
140
140
|
const getShortChunkName = (
|
@@ -164,7 +164,7 @@ exports.getShortChunkName = getShortChunkName;
|
|
164
164
|
* @param {string} context context directory
|
165
165
|
* @param {string} delimiter delimiter for names
|
166
166
|
* @param {string | Hash} hashFunction hash function to use
|
167
|
-
* @param {
|
167
|
+
* @param {object=} associatedObjectForCache an object to which the cache will be attached
|
168
168
|
* @returns {string} short chunk name
|
169
169
|
*/
|
170
170
|
const getLongChunkName = (
|
@@ -197,7 +197,7 @@ exports.getLongChunkName = getLongChunkName;
|
|
197
197
|
* @param {Chunk} chunk the chunk
|
198
198
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
199
199
|
* @param {string} context context directory
|
200
|
-
* @param {
|
200
|
+
* @param {object=} associatedObjectForCache an object to which the cache will be attached
|
201
201
|
* @returns {string} full chunk name
|
202
202
|
*/
|
203
203
|
const getFullChunkName = (
|
@@ -15,7 +15,7 @@ const plugin = "SyncModuleIdsPlugin";
|
|
15
15
|
|
16
16
|
class SyncModuleIdsPlugin {
|
17
17
|
/**
|
18
|
-
* @param {
|
18
|
+
* @param {object} options options
|
19
19
|
* @param {string} options.path path to file
|
20
20
|
* @param {string=} options.context context for module names
|
21
21
|
* @param {function(Module): boolean} options.test selector for modules
|
@@ -63,7 +63,7 @@ class SyncModuleIdsPlugin {
|
|
63
63
|
if (this._write) {
|
64
64
|
compiler.hooks.emitRecords.tapAsync(plugin, callback => {
|
65
65
|
if (!data || !dataChanged) return callback();
|
66
|
-
/** @type {
|
66
|
+
/** @type {{[key: string]: string | number}} */
|
67
67
|
const json = {};
|
68
68
|
const sorted = Array.from(data).sort(([a], [b]) => (a < b ? -1 : 1));
|
69
69
|
for (const [key, value] of sorted) {
|
package/lib/index.js
CHANGED
@@ -60,6 +60,8 @@ const memoize = require("./util/memoize");
|
|
60
60
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleTraceDependency} StatsModuleTraceDependency */
|
61
61
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleTraceItem} StatsModuleTraceItem */
|
62
62
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsProfile} StatsProfile */
|
63
|
+
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
64
|
+
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
63
65
|
|
64
66
|
/**
|
65
67
|
* @template {Function} T
|
@@ -221,6 +223,9 @@ module.exports = mergeExports(fn, {
|
|
221
223
|
get HotModuleReplacementPlugin() {
|
222
224
|
return require("./HotModuleReplacementPlugin");
|
223
225
|
},
|
226
|
+
get InitFragment() {
|
227
|
+
return require("./InitFragment");
|
228
|
+
},
|
224
229
|
get IgnorePlugin() {
|
225
230
|
return require("./IgnorePlugin");
|
226
231
|
},
|
@@ -277,6 +282,9 @@ module.exports = mergeExports(fn, {
|
|
277
282
|
get Parser() {
|
278
283
|
return require("./Parser");
|
279
284
|
},
|
285
|
+
get PlatformPlugin() {
|
286
|
+
return require("./PlatformPlugin");
|
287
|
+
},
|
280
288
|
get PrefetchPlugin() {
|
281
289
|
return require("./PrefetchPlugin");
|
282
290
|
},
|
@@ -576,6 +584,9 @@ module.exports = mergeExports(fn, {
|
|
576
584
|
},
|
577
585
|
get LazySet() {
|
578
586
|
return require("./util/LazySet");
|
587
|
+
},
|
588
|
+
get compileBooleanMatcher() {
|
589
|
+
return require("./util/compileBooleanMatcher");
|
579
590
|
}
|
580
591
|
},
|
581
592
|
|
@@ -32,7 +32,7 @@ class CommonJsChunkFormatPlugin {
|
|
32
32
|
"CommonJsChunkFormatPlugin",
|
33
33
|
compilation => {
|
34
34
|
compilation.hooks.additionalChunkRuntimeRequirements.tap(
|
35
|
-
"
|
35
|
+
"CommonJsChunkFormatPlugin",
|
36
36
|
(chunk, set, { chunkGraph }) => {
|
37
37
|
if (chunk.hasRuntime()) return;
|
38
38
|
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) {
|
@@ -199,7 +199,6 @@ class JavascriptGenerator extends Generator {
|
|
199
199
|
chunkGraph: generateContext.chunkGraph,
|
200
200
|
module,
|
201
201
|
runtime: generateContext.runtime,
|
202
|
-
runtimes: generateContext.runtimes,
|
203
202
|
runtimeRequirements: generateContext.runtimeRequirements,
|
204
203
|
concatenationScope: generateContext.concatenationScope,
|
205
204
|
codeGenerationResults: generateContext.codeGenerationResults,
|
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const eslintScope = require("eslint-scope");
|
8
9
|
const { SyncWaterfallHook, SyncHook, SyncBailHook } = require("tapable");
|
9
10
|
const vm = require("vm");
|
10
11
|
const {
|
@@ -12,7 +13,8 @@ const {
|
|
12
13
|
OriginalSource,
|
13
14
|
PrefixSource,
|
14
15
|
RawSource,
|
15
|
-
CachedSource
|
16
|
+
CachedSource,
|
17
|
+
ReplaceSource
|
16
18
|
} = require("webpack-sources");
|
17
19
|
const Compilation = require("../Compilation");
|
18
20
|
const { tryRunOrWebpackError } = require("../HookWebpackError");
|
@@ -30,11 +32,13 @@ const { last, someInIterable } = require("../util/IterableHelpers");
|
|
30
32
|
const StringXor = require("../util/StringXor");
|
31
33
|
const { compareModulesByIdentifier } = require("../util/comparators");
|
32
34
|
const createHash = require("../util/createHash");
|
35
|
+
const { getPathInAst, getAllReferences } = require("../util/mergeScope");
|
33
36
|
const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
|
34
37
|
const { intersectRuntime } = require("../util/runtime");
|
35
38
|
const JavascriptGenerator = require("./JavascriptGenerator");
|
36
39
|
const JavascriptParser = require("./JavascriptParser");
|
37
40
|
|
41
|
+
/** @typedef {import("eslint-scope").Variable} Variable */
|
38
42
|
/** @typedef {import("webpack-sources").Source} Source */
|
39
43
|
/** @typedef {import("../Chunk")} Chunk */
|
40
44
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
@@ -85,7 +89,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
85
89
|
};
|
86
90
|
|
87
91
|
/**
|
88
|
-
* @typedef {
|
92
|
+
* @typedef {object} RenderContext
|
89
93
|
* @property {Chunk} chunk the chunk
|
90
94
|
* @property {DependencyTemplates} dependencyTemplates the dependency templates
|
91
95
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
@@ -96,7 +100,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
96
100
|
*/
|
97
101
|
|
98
102
|
/**
|
99
|
-
* @typedef {
|
103
|
+
* @typedef {object} MainRenderContext
|
100
104
|
* @property {Chunk} chunk the chunk
|
101
105
|
* @property {DependencyTemplates} dependencyTemplates the dependency templates
|
102
106
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
@@ -108,7 +112,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
108
112
|
*/
|
109
113
|
|
110
114
|
/**
|
111
|
-
* @typedef {
|
115
|
+
* @typedef {object} ChunkRenderContext
|
112
116
|
* @property {Chunk} chunk the chunk
|
113
117
|
* @property {DependencyTemplates} dependencyTemplates the dependency templates
|
114
118
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
@@ -120,7 +124,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
120
124
|
*/
|
121
125
|
|
122
126
|
/**
|
123
|
-
* @typedef {
|
127
|
+
* @typedef {object} RenderBootstrapContext
|
124
128
|
* @property {Chunk} chunk the chunk
|
125
129
|
* @property {CodeGenerationResults} codeGenerationResults results of code generation
|
126
130
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
@@ -132,7 +136,7 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
132
136
|
/** @typedef {RenderContext & { inlined: boolean }} StartupRenderContext */
|
133
137
|
|
134
138
|
/**
|
135
|
-
* @typedef {
|
139
|
+
* @typedef {object} CompilationHooks
|
136
140
|
* @property {SyncWaterfallHook<[Source, Module, ChunkRenderContext]>} renderModuleContent
|
137
141
|
* @property {SyncWaterfallHook<[Source, Module, ChunkRenderContext]>} renderModuleContainer
|
138
142
|
* @property {SyncWaterfallHook<[Source, Module, ChunkRenderContext]>} renderModulePackage
|
@@ -818,13 +822,19 @@ class JavascriptModulesPlugin {
|
|
818
822
|
const lastInlinedModule = last(inlinedModules);
|
819
823
|
const startupSource = new ConcatSource();
|
820
824
|
startupSource.add(`var ${RuntimeGlobals.exports} = {};\n`);
|
825
|
+
const renamedInlinedModule = this.renameInlineModule(
|
826
|
+
allModules,
|
827
|
+
renderContext,
|
828
|
+
inlinedModules,
|
829
|
+
chunkRenderContext,
|
830
|
+
hooks
|
831
|
+
);
|
832
|
+
|
821
833
|
for (const m of inlinedModules) {
|
822
|
-
const renderedModule =
|
823
|
-
m
|
824
|
-
chunkRenderContext,
|
825
|
-
|
826
|
-
false
|
827
|
-
);
|
834
|
+
const renderedModule =
|
835
|
+
renamedInlinedModule.get(m) ||
|
836
|
+
this.renderModule(m, chunkRenderContext, hooks, false);
|
837
|
+
|
828
838
|
if (renderedModule) {
|
829
839
|
const innerStrict = !allStrict && m.buildInfo.strict;
|
830
840
|
const runtimeRequirements = chunkGraph.getModuleRuntimeRequirements(
|
@@ -840,11 +850,9 @@ class JavascriptModulesPlugin {
|
|
840
850
|
? // TODO check globals and top-level declarations of other entries and chunk modules
|
841
851
|
// to make a better decision
|
842
852
|
"it need to be isolated against other entry modules."
|
843
|
-
:
|
844
|
-
?
|
845
|
-
:
|
846
|
-
? `it uses a non-standard name for the exports (${m.exportsArgument}).`
|
847
|
-
: hooks.embedInRuntimeBailout.call(m, renderContext);
|
853
|
+
: exports && !webpackExports
|
854
|
+
? `it uses a non-standard name for the exports (${m.exportsArgument}).`
|
855
|
+
: hooks.embedInRuntimeBailout.call(m, renderContext);
|
848
856
|
let footer;
|
849
857
|
if (iife !== undefined) {
|
850
858
|
startupSource.add(
|
@@ -1383,6 +1391,155 @@ class JavascriptModulesPlugin {
|
|
1383
1391
|
"JavascriptModulesPlugin.getCompilationHooks().renderRequire"
|
1384
1392
|
);
|
1385
1393
|
}
|
1394
|
+
|
1395
|
+
/**
|
1396
|
+
* @param {Module[]} allModules allModules
|
1397
|
+
* @param {MainRenderContext} renderContext renderContext
|
1398
|
+
* @param {Set<Module>} inlinedModules inlinedModules
|
1399
|
+
* @param {ChunkRenderContext} chunkRenderContext chunkRenderContext
|
1400
|
+
* @param {CompilationHooks} hooks hooks
|
1401
|
+
* @returns {Map<Module, Source>} renamed inlined modules
|
1402
|
+
*/
|
1403
|
+
renameInlineModule(
|
1404
|
+
allModules,
|
1405
|
+
renderContext,
|
1406
|
+
inlinedModules,
|
1407
|
+
chunkRenderContext,
|
1408
|
+
hooks
|
1409
|
+
) {
|
1410
|
+
const { runtimeTemplate } = renderContext;
|
1411
|
+
|
1412
|
+
/** @type {Map<Module, { source: Source, ast: any, variables: Set<Variable>, usedInNonInlined: Set<Variable>}>} */
|
1413
|
+
const inlinedModulesToInfo = new Map();
|
1414
|
+
/** @type {Set<string>} */
|
1415
|
+
const nonInlinedModuleThroughIdentifiers = new Set();
|
1416
|
+
/** @type {Map<Module, Source>} */
|
1417
|
+
const renamedInlinedModules = new Map();
|
1418
|
+
|
1419
|
+
for (const m of allModules) {
|
1420
|
+
const isInlinedModule = inlinedModules && inlinedModules.has(m);
|
1421
|
+
const moduleSource = this.renderModule(
|
1422
|
+
m,
|
1423
|
+
chunkRenderContext,
|
1424
|
+
hooks,
|
1425
|
+
isInlinedModule ? false : true
|
1426
|
+
);
|
1427
|
+
|
1428
|
+
if (!moduleSource) continue;
|
1429
|
+
const code = /** @type {string} */ (moduleSource.source());
|
1430
|
+
const ast = JavascriptParser._parse(code, {
|
1431
|
+
sourceType: "auto"
|
1432
|
+
});
|
1433
|
+
|
1434
|
+
const scopeManager = eslintScope.analyze(ast, {
|
1435
|
+
ecmaVersion: 6,
|
1436
|
+
sourceType: "module",
|
1437
|
+
optimistic: true,
|
1438
|
+
ignoreEval: true
|
1439
|
+
});
|
1440
|
+
|
1441
|
+
const globalScope = scopeManager.acquire(ast);
|
1442
|
+
if (inlinedModules && inlinedModules.has(m)) {
|
1443
|
+
const moduleScope = globalScope.childScopes[0];
|
1444
|
+
inlinedModulesToInfo.set(m, {
|
1445
|
+
source: moduleSource,
|
1446
|
+
ast,
|
1447
|
+
variables: new Set(moduleScope.variables),
|
1448
|
+
usedInNonInlined: new Set()
|
1449
|
+
});
|
1450
|
+
} else {
|
1451
|
+
for (const ref of globalScope.through) {
|
1452
|
+
nonInlinedModuleThroughIdentifiers.add(ref.identifier.name);
|
1453
|
+
}
|
1454
|
+
}
|
1455
|
+
}
|
1456
|
+
|
1457
|
+
for (const [, { variables, usedInNonInlined }] of inlinedModulesToInfo) {
|
1458
|
+
for (const variable of variables) {
|
1459
|
+
if (nonInlinedModuleThroughIdentifiers.has(variable.name)) {
|
1460
|
+
usedInNonInlined.add(variable);
|
1461
|
+
}
|
1462
|
+
}
|
1463
|
+
}
|
1464
|
+
|
1465
|
+
for (const [m, moduleInfo] of inlinedModulesToInfo) {
|
1466
|
+
const { ast, source: _source, usedInNonInlined } = moduleInfo;
|
1467
|
+
const source = new ReplaceSource(_source);
|
1468
|
+
if (usedInNonInlined.size === 0) {
|
1469
|
+
renamedInlinedModules.set(m, source);
|
1470
|
+
continue;
|
1471
|
+
}
|
1472
|
+
|
1473
|
+
const usedNames = new Set(
|
1474
|
+
Array.from(inlinedModulesToInfo.get(m).variables).map(v => v.name)
|
1475
|
+
);
|
1476
|
+
|
1477
|
+
for (const variable of usedInNonInlined) {
|
1478
|
+
const references = getAllReferences(variable);
|
1479
|
+
const allIdentifiers = new Set(
|
1480
|
+
references.map(r => r.identifier).concat(variable.identifiers)
|
1481
|
+
);
|
1482
|
+
|
1483
|
+
const newName = this.findNewName(
|
1484
|
+
variable.name,
|
1485
|
+
usedNames,
|
1486
|
+
m.readableIdentifier(runtimeTemplate.requestShortener)
|
1487
|
+
);
|
1488
|
+
usedNames.add(newName);
|
1489
|
+
for (const identifier of allIdentifiers) {
|
1490
|
+
const r = identifier.range;
|
1491
|
+
const path = getPathInAst(ast, identifier);
|
1492
|
+
if (path && path.length > 1) {
|
1493
|
+
const maybeProperty =
|
1494
|
+
path[1].type === "AssignmentPattern" && path[1].left === path[0]
|
1495
|
+
? path[2]
|
1496
|
+
: path[1];
|
1497
|
+
if (maybeProperty.type === "Property" && maybeProperty.shorthand) {
|
1498
|
+
source.insert(r[1], `: ${newName}`);
|
1499
|
+
continue;
|
1500
|
+
}
|
1501
|
+
}
|
1502
|
+
source.replace(r[0], r[1] - 1, newName);
|
1503
|
+
}
|
1504
|
+
}
|
1505
|
+
|
1506
|
+
renamedInlinedModules.set(m, source);
|
1507
|
+
}
|
1508
|
+
|
1509
|
+
return renamedInlinedModules;
|
1510
|
+
}
|
1511
|
+
|
1512
|
+
/**
|
1513
|
+
* @param {string} oldName oldName
|
1514
|
+
* @param {Set<string>} usedName usedName
|
1515
|
+
* @param {string} extraInfo extraInfo
|
1516
|
+
* @returns {string} extraInfo
|
1517
|
+
*/
|
1518
|
+
findNewName(oldName, usedName, extraInfo) {
|
1519
|
+
let name = oldName;
|
1520
|
+
|
1521
|
+
// Remove uncool stuff
|
1522
|
+
extraInfo = extraInfo.replace(
|
1523
|
+
/\.+\/|(\/index)?\.([a-zA-Z0-9]{1,4})($|\s|\?)|\s*\+\s*\d+\s*modules/g,
|
1524
|
+
""
|
1525
|
+
);
|
1526
|
+
const splittedInfo = extraInfo.split("/");
|
1527
|
+
while (splittedInfo.length) {
|
1528
|
+
name = splittedInfo.pop() + (name ? "_" + name : "");
|
1529
|
+
const nameIdent = Template.toIdentifier(name);
|
1530
|
+
if (!usedName.has(nameIdent)) {
|
1531
|
+
return nameIdent;
|
1532
|
+
}
|
1533
|
+
}
|
1534
|
+
|
1535
|
+
let i = 0;
|
1536
|
+
let nameWithNumber = Template.toIdentifier(`${name}_${i}`);
|
1537
|
+
while (usedName.has(nameWithNumber)) {
|
1538
|
+
i++;
|
1539
|
+
nameWithNumber = Template.toIdentifier(`${name}_${i}`);
|
1540
|
+
}
|
1541
|
+
return nameWithNumber;
|
1542
|
+
}
|
1386
1543
|
}
|
1387
1544
|
|
1388
1545
|
module.exports = JavascriptModulesPlugin;
|