webpack 5.105.4 → 5.106.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.
- package/README.md +3 -6
- package/lib/BannerPlugin.js +13 -13
- package/lib/Chunk.js +25 -0
- package/lib/ChunkGraph.js +8 -4
- package/lib/CleanPlugin.js +23 -20
- package/lib/CompatibilityPlugin.js +1 -1
- package/lib/Compilation.js +34 -11
- package/lib/Compiler.js +59 -1
- package/lib/CssModule.js +17 -2
- package/lib/Dependency.js +1 -1
- package/lib/DllPlugin.js +17 -17
- package/lib/DllReferencePlugin.js +20 -18
- package/lib/DotenvPlugin.js +29 -27
- package/lib/ExternalModule.js +39 -6
- package/lib/FileSystemInfo.js +3 -1
- package/lib/IgnorePlugin.js +12 -11
- package/lib/LoaderOptionsPlugin.js +17 -15
- package/lib/ManifestPlugin.js +27 -25
- package/lib/Module.js +69 -7
- package/lib/ModuleGraph.js +3 -0
- package/lib/ModuleParseError.js +1 -1
- package/lib/ModuleTypeConstants.js +1 -1
- package/lib/NormalModule.js +7 -3
- package/lib/NormalModuleFactory.js +20 -1
- package/lib/ProgressPlugin.js +39 -29
- package/lib/RuntimeGlobals.js +6 -0
- package/lib/RuntimeTemplate.js +1 -1
- package/lib/SourceMapDevToolPlugin.js +13 -11
- package/lib/TemplatedPathPlugin.js +4 -3
- package/lib/WatchIgnorePlugin.js +15 -13
- package/lib/WebpackOptionsApply.js +4 -4
- package/lib/asset/AssetModulesPlugin.js +50 -29
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +27 -13
- package/lib/config/normalization.js +3 -2
- package/lib/container/ContainerPlugin.js +46 -42
- package/lib/container/ContainerReferencePlugin.js +42 -26
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/ModuleFederationPlugin.js +17 -13
- package/lib/css/CssGenerator.js +306 -192
- package/lib/css/CssInjectStyleRuntimeModule.js +179 -0
- package/lib/css/CssLoadingRuntimeModule.js +1 -4
- package/lib/css/CssModulesPlugin.js +197 -98
- package/lib/css/CssParser.js +243 -134
- package/lib/css/walkCssTokens.js +115 -12
- package/lib/debug/ProfilingPlugin.js +16 -13
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +20 -15
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -3
- package/lib/dependencies/CommonJsExportRequireDependency.js +4 -2
- package/lib/dependencies/CommonJsExportsDependency.js +1 -1
- package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -1
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +63 -2
- package/lib/dependencies/CommonJsRequireContextDependency.js +21 -0
- package/lib/dependencies/CommonJsRequireDependency.js +42 -1
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/CssIcssExportDependency.js +211 -88
- package/lib/dependencies/CssIcssImportDependency.js +13 -70
- package/lib/dependencies/CssIcssSymbolDependency.js +19 -30
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +13 -2
- package/lib/dependencies/HarmonyExportExpressionDependency.js +35 -5
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -3
- package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
- package/lib/dependencies/HarmonyImportDependency.js +21 -8
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +4 -1
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +13 -2
- package/lib/dependencies/ImportContextDependency.js +1 -1
- package/lib/dependencies/ImportDependency.js +16 -2
- package/lib/dependencies/ImportMetaPlugin.js +39 -29
- package/lib/dependencies/ImportParserPlugin.js +4 -5
- package/lib/dependencies/ImportPhase.js +65 -22
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +1 -4
- package/lib/ids/HashedModuleIdsPlugin.js +21 -23
- package/lib/ids/OccurrenceChunkIdsPlugin.js +15 -11
- package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -11
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -4
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -4
- package/lib/javascript/EnableChunkLoadingPlugin.js +1 -2
- package/lib/javascript/JavascriptModulesPlugin.js +38 -12
- package/lib/javascript/JavascriptParser.js +5 -3
- package/lib/json/JsonModulesPlugin.js +28 -21
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +35 -13
- package/lib/library/SystemLibraryPlugin.js +1 -1
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +22 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +18 -31
- package/lib/optimize/ConcatenatedModule.js +4 -3
- package/lib/optimize/InnerGraphPlugin.js +11 -5
- package/lib/optimize/LimitChunkCountPlugin.js +22 -18
- package/lib/optimize/MergeDuplicateChunksPlugin.js +15 -12
- package/lib/optimize/MinChunkSizePlugin.js +20 -16
- package/lib/optimize/RemoveEmptyChunksPlugin.js +0 -1
- package/lib/rules/RuleSetCompiler.js +1 -0
- package/lib/schemes/HttpUriPlugin.js +20 -11
- package/lib/schemes/VirtualUrlPlugin.js +77 -30
- package/lib/serialization/FileMiddleware.js +7 -7
- package/lib/sharing/ConsumeSharedPlugin.js +32 -25
- package/lib/sharing/ProvideSharedPlugin.js +29 -25
- package/lib/util/{propertyName.js → property.js} +26 -1
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +148 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +54 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +105 -0
- package/lib/wasm-async/AsyncWebAssemblyParser.js +30 -6
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +26 -2
- package/lib/web/FetchCompileAsyncWasmPlugin.js +23 -0
- package/lib/web/JsonpTemplatePlugin.js +1 -0
- package/lib/webpack.js +34 -4
- package/package.json +18 -16
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +82 -22
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +1 -1
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +1 -1
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +8 -0
- package/types.d.ts +511 -114
- package/lib/util/create-schema-validation.js +0 -41
- package/lib/util/propertyAccess.js +0 -30
|
@@ -6,30 +6,11 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const { JSON_MODULE_TYPE } = require("../ModuleTypeConstants");
|
|
9
|
-
const createSchemaValidation = require("../util/create-schema-validation");
|
|
10
9
|
const JsonGenerator = require("./JsonGenerator");
|
|
11
10
|
const JsonParser = require("./JsonParser");
|
|
12
11
|
|
|
13
12
|
/** @typedef {import("../Compiler")} Compiler */
|
|
14
13
|
|
|
15
|
-
const validate = createSchemaValidation(
|
|
16
|
-
require("../../schemas/plugins/json/JsonModulesPluginParser.check"),
|
|
17
|
-
() => require("../../schemas/plugins/json/JsonModulesPluginParser.json"),
|
|
18
|
-
{
|
|
19
|
-
name: "Json Modules Plugin",
|
|
20
|
-
baseDataPath: "parser"
|
|
21
|
-
}
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
const validateGenerator = createSchemaValidation(
|
|
25
|
-
require("../../schemas/plugins/json/JsonModulesPluginGenerator.check"),
|
|
26
|
-
() => require("../../schemas/plugins/json/JsonModulesPluginGenerator.json"),
|
|
27
|
-
{
|
|
28
|
-
name: "Json Modules Plugin",
|
|
29
|
-
baseDataPath: "generator"
|
|
30
|
-
}
|
|
31
|
-
);
|
|
32
|
-
|
|
33
14
|
const PLUGIN_NAME = "JsonModulesPlugin";
|
|
34
15
|
|
|
35
16
|
/**
|
|
@@ -49,13 +30,39 @@ class JsonModulesPlugin {
|
|
|
49
30
|
normalModuleFactory.hooks.createParser
|
|
50
31
|
.for(JSON_MODULE_TYPE)
|
|
51
32
|
.tap(PLUGIN_NAME, (parserOptions) => {
|
|
52
|
-
validate(
|
|
33
|
+
compiler.validate(
|
|
34
|
+
() =>
|
|
35
|
+
require("../../schemas/plugins/json/JsonModulesPluginParser.json"),
|
|
36
|
+
parserOptions,
|
|
37
|
+
{
|
|
38
|
+
name: "Json Modules Plugin",
|
|
39
|
+
baseDataPath: "parser"
|
|
40
|
+
},
|
|
41
|
+
(options) =>
|
|
42
|
+
require("../../schemas/plugins/json/JsonModulesPluginParser.check")(
|
|
43
|
+
options
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
|
|
53
47
|
return new JsonParser(parserOptions);
|
|
54
48
|
});
|
|
55
49
|
normalModuleFactory.hooks.createGenerator
|
|
56
50
|
.for(JSON_MODULE_TYPE)
|
|
57
51
|
.tap(PLUGIN_NAME, (generatorOptions) => {
|
|
58
|
-
|
|
52
|
+
compiler.validate(
|
|
53
|
+
() =>
|
|
54
|
+
require("../../schemas/plugins/json/JsonModulesPluginGenerator.json"),
|
|
55
|
+
generatorOptions,
|
|
56
|
+
{
|
|
57
|
+
name: "Json Modules Plugin",
|
|
58
|
+
baseDataPath: "generator"
|
|
59
|
+
},
|
|
60
|
+
(options) =>
|
|
61
|
+
require("../../schemas/plugins/json/JsonModulesPluginGenerator.check")(
|
|
62
|
+
options
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
|
|
59
66
|
return new JsonGenerator(generatorOptions);
|
|
60
67
|
});
|
|
61
68
|
}
|
|
@@ -9,7 +9,7 @@ const { ConcatSource } = require("webpack-sources");
|
|
|
9
9
|
const { UsageState } = require("../ExportsInfo");
|
|
10
10
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
11
11
|
const Template = require("../Template");
|
|
12
|
-
const propertyAccess = require("../util/
|
|
12
|
+
const { propertyAccess } = require("../util/property");
|
|
13
13
|
const { getEntryRuntime } = require("../util/runtime");
|
|
14
14
|
const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
15
15
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
const { ConcatSource } = require("webpack-sources");
|
|
9
9
|
const { UsageState } = require("../ExportsInfo");
|
|
10
10
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
11
|
-
const propertyAccess = require("../util/
|
|
11
|
+
const { propertyAccess } = require("../util/property");
|
|
12
12
|
const { getEntryRuntime } = require("../util/runtime");
|
|
13
13
|
const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
14
14
|
|
|
@@ -12,7 +12,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
|
12
12
|
const Template = require("../Template");
|
|
13
13
|
const HarmonyExportImportedSpecifierDependency = require("../dependencies/HarmonyExportImportedSpecifierDependency");
|
|
14
14
|
const ConcatenatedModule = require("../optimize/ConcatenatedModule");
|
|
15
|
-
const propertyAccess = require("../util/
|
|
15
|
+
const { propertyAccess } = require("../util/property");
|
|
16
16
|
const { getEntryRuntime, getRuntimeKey } = require("../util/runtime");
|
|
17
17
|
const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
18
18
|
|
|
@@ -252,19 +252,15 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
252
252
|
* @param {LibraryContext<T>} libraryContext context
|
|
253
253
|
* @returns {Source} source with library export
|
|
254
254
|
*/
|
|
255
|
-
renderStartup(
|
|
256
|
-
|
|
257
|
-
module,
|
|
258
|
-
{
|
|
255
|
+
renderStartup(source, module, renderContext, { options, compilation }) {
|
|
256
|
+
const {
|
|
259
257
|
moduleGraph,
|
|
260
258
|
chunk,
|
|
261
259
|
codeGenerationResults,
|
|
262
260
|
inlined,
|
|
263
261
|
inlinedInIIFE,
|
|
264
262
|
runtimeTemplate
|
|
265
|
-
}
|
|
266
|
-
{ options, compilation }
|
|
267
|
-
) {
|
|
263
|
+
} = renderContext;
|
|
268
264
|
let result = new ConcatSource(source);
|
|
269
265
|
const exportInfos = options.export
|
|
270
266
|
? [
|
|
@@ -283,8 +279,11 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
283
279
|
)) ||
|
|
284
280
|
{};
|
|
285
281
|
|
|
286
|
-
const
|
|
287
|
-
|
|
282
|
+
const isInlinedEntryWithoutIIFE = inlined && !inlinedInIIFE;
|
|
283
|
+
// Direct export bindings from on-demand concatenation
|
|
284
|
+
const definitions = isInlinedEntryWithoutIIFE
|
|
285
|
+
? exportsFinalNameByRuntime
|
|
286
|
+
: {};
|
|
288
287
|
|
|
289
288
|
/** @type {string[]} */
|
|
290
289
|
const shortHandedExports = [];
|
|
@@ -299,23 +298,37 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
299
298
|
module.buildMeta && module.buildMeta.treatAsCommonJs;
|
|
300
299
|
const skipRenderDefaultExport = Boolean(treatAsCommonJs);
|
|
301
300
|
|
|
301
|
+
const moduleExportsInfo = moduleGraph.getExportsInfo(module);
|
|
302
|
+
|
|
303
|
+
// Define ESM compatibility flag will rely on `__webpack_exports__`
|
|
304
|
+
const needHarmonyCompatibilityFlag =
|
|
305
|
+
moduleExportsInfo.otherExportsInfo.getUsed(chunk.runtime) !==
|
|
306
|
+
UsageState.Unused ||
|
|
307
|
+
moduleExportsInfo
|
|
308
|
+
.getReadOnlyExportInfo("__esModule")
|
|
309
|
+
.getUsed(chunk.runtime) !== UsageState.Unused;
|
|
310
|
+
|
|
311
|
+
let needExportsDeclaration =
|
|
312
|
+
!isInlinedEntryWithoutIIFE || isAsync || needHarmonyCompatibilityFlag;
|
|
313
|
+
|
|
302
314
|
if (isAsync) {
|
|
303
315
|
result.add(
|
|
304
316
|
`${RuntimeGlobals.exports} = await ${RuntimeGlobals.exports};\n`
|
|
305
317
|
);
|
|
306
318
|
}
|
|
307
319
|
|
|
320
|
+
// Try to find all known exports of the entry module
|
|
308
321
|
outer: for (const exportInfo of exportInfos) {
|
|
309
322
|
if (!exportInfo.provided) continue;
|
|
310
323
|
|
|
311
324
|
const originalName = exportInfo.name;
|
|
312
|
-
|
|
325
|
+
// Skip rendering the default export in some cases
|
|
313
326
|
if (skipRenderDefaultExport && originalName === "default") continue;
|
|
314
327
|
|
|
328
|
+
// Try to find all exports from the reexported modules
|
|
315
329
|
const target = exportInfo.findTarget(moduleGraph, (_m) => true);
|
|
316
330
|
if (target) {
|
|
317
331
|
const reexportsInfo = moduleGraph.getExportsInfo(target.module);
|
|
318
|
-
|
|
319
332
|
for (const reexportInfo of reexportsInfo.orderedExports) {
|
|
320
333
|
if (
|
|
321
334
|
reexportInfo.provided === false &&
|
|
@@ -332,14 +345,16 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
332
345
|
(exportInfo.getUsedName(originalName, chunk.runtime));
|
|
333
346
|
/** @type {string | undefined} */
|
|
334
347
|
const definition = definitions[usedName];
|
|
335
|
-
|
|
336
348
|
/** @type {string | undefined} */
|
|
337
349
|
let finalName;
|
|
338
350
|
|
|
339
351
|
if (definition) {
|
|
340
352
|
finalName = definition;
|
|
341
353
|
} else {
|
|
354
|
+
// Fallback to `__webpack_exports__` property access
|
|
355
|
+
// when no direct export binding was found
|
|
342
356
|
finalName = `${RuntimeGlobals.exports}${Template.toIdentifier(originalName)}`;
|
|
357
|
+
needExportsDeclaration = true;
|
|
343
358
|
result.add(
|
|
344
359
|
`${runtimeTemplate.renderConst()} ${finalName} = ${RuntimeGlobals.exports}${propertyAccess(
|
|
345
360
|
[usedName]
|
|
@@ -348,6 +363,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
348
363
|
}
|
|
349
364
|
|
|
350
365
|
if (
|
|
366
|
+
// If the name includes `property access` and `call expressions`
|
|
351
367
|
finalName &&
|
|
352
368
|
(finalName.includes(".") ||
|
|
353
369
|
finalName.includes("[") ||
|
|
@@ -382,7 +398,9 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
382
398
|
alreadyRenderedExports.add(originalName);
|
|
383
399
|
}
|
|
384
400
|
|
|
401
|
+
// Add default export `__webpack_exports__` statement to keep better compatibility
|
|
385
402
|
if (treatAsCommonJs) {
|
|
403
|
+
needExportsDeclaration = true;
|
|
386
404
|
shortHandedExports.push(`${RuntimeGlobals.exports} as default`);
|
|
387
405
|
}
|
|
388
406
|
|
|
@@ -405,6 +423,10 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
405
423
|
);
|
|
406
424
|
}
|
|
407
425
|
|
|
426
|
+
if (!needExportsDeclaration) {
|
|
427
|
+
renderContext.needExportsDeclaration = false;
|
|
428
|
+
}
|
|
429
|
+
|
|
408
430
|
return result;
|
|
409
431
|
}
|
|
410
432
|
|
|
@@ -9,7 +9,7 @@ const { ConcatSource } = require("webpack-sources");
|
|
|
9
9
|
const { UsageState } = require("../ExportsInfo");
|
|
10
10
|
const ExternalModule = require("../ExternalModule");
|
|
11
11
|
const Template = require("../Template");
|
|
12
|
-
const propertyAccess = require("../util/
|
|
12
|
+
const { propertyAccess } = require("../util/property");
|
|
13
13
|
const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
14
14
|
|
|
15
15
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
const { WEBASSEMBLY_MODULE_TYPE_ASYNC } = require("../ModuleTypeConstants");
|
|
9
9
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
10
10
|
const Template = require("../Template");
|
|
11
|
+
const AsyncWasmCompileRuntimeModule = require("../wasm-async/AsyncWasmCompileRuntimeModule");
|
|
11
12
|
const AsyncWasmLoadingRuntimeModule = require("../wasm-async/AsyncWasmLoadingRuntimeModule");
|
|
12
13
|
|
|
13
14
|
/** @typedef {import("../Chunk")} Chunk */
|
|
@@ -116,6 +117,27 @@ class ReadFileCompileAsyncWasmPlugin {
|
|
|
116
117
|
})
|
|
117
118
|
);
|
|
118
119
|
});
|
|
120
|
+
|
|
121
|
+
compilation.hooks.runtimeRequirementInTree
|
|
122
|
+
.for(RuntimeGlobals.compileWasm)
|
|
123
|
+
.tap(PLUGIN_NAME, (chunk, set, { chunkGraph }) => {
|
|
124
|
+
if (!isEnabledForChunk(chunk)) return;
|
|
125
|
+
if (
|
|
126
|
+
!chunkGraph.hasModuleInGraph(
|
|
127
|
+
chunk,
|
|
128
|
+
(m) => m.type === WEBASSEMBLY_MODULE_TYPE_ASYNC
|
|
129
|
+
)
|
|
130
|
+
) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
compilation.addRuntimeModule(
|
|
134
|
+
chunk,
|
|
135
|
+
new AsyncWasmCompileRuntimeModule({
|
|
136
|
+
generateLoadBinaryCode,
|
|
137
|
+
supportsStreaming: false
|
|
138
|
+
})
|
|
139
|
+
);
|
|
140
|
+
});
|
|
119
141
|
});
|
|
120
142
|
}
|
|
121
143
|
}
|
|
@@ -11,7 +11,6 @@ const {
|
|
|
11
11
|
compareChunks,
|
|
12
12
|
compareModulesByIdentifier
|
|
13
13
|
} = require("../util/comparators");
|
|
14
|
-
const createSchemaValidation = require("../util/create-schema-validation");
|
|
15
14
|
const identifierUtils = require("../util/identifier");
|
|
16
15
|
|
|
17
16
|
/** @typedef {import("../../declarations/plugins/optimize/AggressiveSplittingPlugin").AggressiveSplittingPluginOptions} AggressiveSplittingPluginOptions */
|
|
@@ -21,16 +20,6 @@ const identifierUtils = require("../util/identifier");
|
|
|
21
20
|
/** @typedef {import("../Compiler")} Compiler */
|
|
22
21
|
/** @typedef {import("../Module")} Module */
|
|
23
22
|
|
|
24
|
-
const validate = createSchemaValidation(
|
|
25
|
-
require("../../schemas/plugins/optimize/AggressiveSplittingPlugin.check"),
|
|
26
|
-
() =>
|
|
27
|
-
require("../../schemas/plugins/optimize/AggressiveSplittingPlugin.json"),
|
|
28
|
-
{
|
|
29
|
-
name: "Aggressive Splitting Plugin",
|
|
30
|
-
baseDataPath: "options"
|
|
31
|
-
}
|
|
32
|
-
);
|
|
33
|
-
|
|
34
23
|
/**
|
|
35
24
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
|
36
25
|
* @param {Chunk} oldChunk the old chunk
|
|
@@ -62,26 +51,8 @@ class AggressiveSplittingPlugin {
|
|
|
62
51
|
* @param {AggressiveSplittingPluginOptions=} options options object
|
|
63
52
|
*/
|
|
64
53
|
constructor(options = {}) {
|
|
65
|
-
validate(options);
|
|
66
|
-
|
|
67
54
|
/** @type {AggressiveSplittingPluginOptions} */
|
|
68
55
|
this.options = options;
|
|
69
|
-
|
|
70
|
-
if (typeof this.options.minSize !== "number") {
|
|
71
|
-
this.options.minSize = 30 * 1024;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (typeof this.options.maxSize !== "number") {
|
|
75
|
-
this.options.maxSize = 50 * 1024;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (typeof this.options.chunkOverhead !== "number") {
|
|
79
|
-
this.options.chunkOverhead = 0;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (typeof this.options.entryChunkMultiplicator !== "number") {
|
|
83
|
-
this.options.entryChunkMultiplicator = 1;
|
|
84
|
-
}
|
|
85
56
|
}
|
|
86
57
|
|
|
87
58
|
/**
|
|
@@ -98,6 +69,22 @@ class AggressiveSplittingPlugin {
|
|
|
98
69
|
* @returns {void}
|
|
99
70
|
*/
|
|
100
71
|
apply(compiler) {
|
|
72
|
+
compiler.hooks.validate.tap(PLUGIN_NAME, () => {
|
|
73
|
+
compiler.validate(
|
|
74
|
+
() =>
|
|
75
|
+
require("../../schemas/plugins/optimize/AggressiveSplittingPlugin.json"),
|
|
76
|
+
this.options,
|
|
77
|
+
{
|
|
78
|
+
name: "Aggressive Splitting Plugin",
|
|
79
|
+
baseDataPath: "options"
|
|
80
|
+
},
|
|
81
|
+
(options) =>
|
|
82
|
+
require("../../schemas/plugins/optimize/AggressiveSplittingPlugin.check")(
|
|
83
|
+
options
|
|
84
|
+
)
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
101
88
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
102
89
|
let needAdditionalSeal = false;
|
|
103
90
|
/** @type {SplitData[]} */
|
|
@@ -147,8 +134,8 @@ class AggressiveSplittingPlugin {
|
|
|
147
134
|
? [...recordedSplits, ...newSplits]
|
|
148
135
|
: recordedSplits;
|
|
149
136
|
|
|
150
|
-
const minSize =
|
|
151
|
-
const maxSize =
|
|
137
|
+
const minSize = this.options.minSize || 30 * 1024;
|
|
138
|
+
const maxSize = this.options.maxSize || 50 * 1024;
|
|
152
139
|
|
|
153
140
|
/**
|
|
154
141
|
* @param {SplitData} splitData split data
|
|
@@ -45,8 +45,7 @@ const {
|
|
|
45
45
|
const createHash = require("../util/createHash");
|
|
46
46
|
const { makePathsRelative } = require("../util/identifier");
|
|
47
47
|
const makeSerializable = require("../util/makeSerializable");
|
|
48
|
-
const propertyAccess = require("../util/
|
|
49
|
-
const { propertyName } = require("../util/propertyName");
|
|
48
|
+
const { propertyAccess, propertyName } = require("../util/property");
|
|
50
49
|
const {
|
|
51
50
|
filterRuntime,
|
|
52
51
|
intersectRuntime,
|
|
@@ -1004,7 +1003,9 @@ class ConcatenatedModule extends Module {
|
|
|
1004
1003
|
if (!(connection.dependency instanceof HarmonyImportDependency)) {
|
|
1005
1004
|
return false;
|
|
1006
1005
|
}
|
|
1007
|
-
if (
|
|
1006
|
+
if (
|
|
1007
|
+
!Module.getSourceBasicTypes(connection.module).has(JAVASCRIPT_TYPE)
|
|
1008
|
+
) {
|
|
1008
1009
|
return false;
|
|
1009
1010
|
}
|
|
1010
1011
|
return (
|
|
@@ -78,6 +78,12 @@ class InnerGraphPlugin {
|
|
|
78
78
|
|
|
79
79
|
parser.hooks.program.tap(PLUGIN_NAME, () => {
|
|
80
80
|
InnerGraph.enable(parser.state);
|
|
81
|
+
|
|
82
|
+
statementWithTopLevelSymbol = new WeakMap();
|
|
83
|
+
statementPurePart = new WeakMap();
|
|
84
|
+
classWithTopLevelSymbol = new WeakMap();
|
|
85
|
+
declWithTopLevelSymbol = new WeakMap();
|
|
86
|
+
pureDeclarators = new WeakSet();
|
|
81
87
|
});
|
|
82
88
|
|
|
83
89
|
parser.hooks.finish.tap(PLUGIN_NAME, () => {
|
|
@@ -98,17 +104,17 @@ class InnerGraphPlugin {
|
|
|
98
104
|
// 3. variable declarators (const x = ...)
|
|
99
105
|
|
|
100
106
|
/** @type {WeakMap<Node | MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration, TopLevelSymbol>} */
|
|
101
|
-
|
|
107
|
+
let statementWithTopLevelSymbol = new WeakMap();
|
|
102
108
|
/** @type {WeakMap<Node | MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration, Node>} */
|
|
103
|
-
|
|
109
|
+
let statementPurePart = new WeakMap();
|
|
104
110
|
|
|
105
111
|
/** @type {WeakMap<ClassExpression | ClassDeclaration | MaybeNamedClassDeclaration, TopLevelSymbol>} */
|
|
106
|
-
|
|
112
|
+
let classWithTopLevelSymbol = new WeakMap();
|
|
107
113
|
|
|
108
114
|
/** @type {WeakMap<VariableDeclarator, TopLevelSymbol>} */
|
|
109
|
-
|
|
115
|
+
let declWithTopLevelSymbol = new WeakMap();
|
|
110
116
|
/** @type {WeakSet<VariableDeclarator>} */
|
|
111
|
-
|
|
117
|
+
let pureDeclarators = new WeakSet();
|
|
112
118
|
|
|
113
119
|
// The following hooks are used during prewalking:
|
|
114
120
|
|
|
@@ -8,21 +8,11 @@
|
|
|
8
8
|
const { STAGE_ADVANCED } = require("../OptimizationStages");
|
|
9
9
|
const LazyBucketSortedSet = require("../util/LazyBucketSortedSet");
|
|
10
10
|
const { compareChunks } = require("../util/comparators");
|
|
11
|
-
const createSchemaValidation = require("../util/create-schema-validation");
|
|
12
11
|
|
|
13
12
|
/** @typedef {import("../../declarations/plugins/optimize/LimitChunkCountPlugin").LimitChunkCountPluginOptions} LimitChunkCountPluginOptions */
|
|
14
13
|
/** @typedef {import("../Chunk")} Chunk */
|
|
15
14
|
/** @typedef {import("../Compiler")} Compiler */
|
|
16
15
|
|
|
17
|
-
const validate = createSchemaValidation(
|
|
18
|
-
require("../../schemas/plugins/optimize/LimitChunkCountPlugin.check"),
|
|
19
|
-
() => require("../../schemas/plugins/optimize/LimitChunkCountPlugin.json"),
|
|
20
|
-
{
|
|
21
|
-
name: "Limit Chunk Count Plugin",
|
|
22
|
-
baseDataPath: "options"
|
|
23
|
-
}
|
|
24
|
-
);
|
|
25
|
-
|
|
26
16
|
/**
|
|
27
17
|
* @typedef {object} ChunkCombination
|
|
28
18
|
* @property {boolean} deleted this is set to true when combination was removed
|
|
@@ -58,7 +48,6 @@ class LimitChunkCountPlugin {
|
|
|
58
48
|
* @param {LimitChunkCountPluginOptions=} options options object
|
|
59
49
|
*/
|
|
60
50
|
constructor(options = { maxChunks: 1 }) {
|
|
61
|
-
validate(options);
|
|
62
51
|
/** @type {LimitChunkCountPluginOptions} */
|
|
63
52
|
this.options = options;
|
|
64
53
|
}
|
|
@@ -68,7 +57,22 @@ class LimitChunkCountPlugin {
|
|
|
68
57
|
* @returns {void}
|
|
69
58
|
*/
|
|
70
59
|
apply(compiler) {
|
|
71
|
-
|
|
60
|
+
compiler.hooks.validate.tap(PLUGIN_NAME, () => {
|
|
61
|
+
compiler.validate(
|
|
62
|
+
() =>
|
|
63
|
+
require("../../schemas/plugins/optimize/LimitChunkCountPlugin.json"),
|
|
64
|
+
this.options,
|
|
65
|
+
{
|
|
66
|
+
name: "Limit Chunk Count Plugin",
|
|
67
|
+
baseDataPath: "options"
|
|
68
|
+
},
|
|
69
|
+
(options) =>
|
|
70
|
+
require("../../schemas/plugins/optimize/LimitChunkCountPlugin.check")(
|
|
71
|
+
options
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
72
76
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
73
77
|
compilation.hooks.optimizeChunks.tap(
|
|
74
78
|
{
|
|
@@ -77,7 +81,7 @@ class LimitChunkCountPlugin {
|
|
|
77
81
|
},
|
|
78
82
|
(chunks) => {
|
|
79
83
|
const chunkGraph = compilation.chunkGraph;
|
|
80
|
-
const maxChunks = options.maxChunks;
|
|
84
|
+
const maxChunks = this.options.maxChunks;
|
|
81
85
|
if (!maxChunks) return;
|
|
82
86
|
if (maxChunks < 1) return;
|
|
83
87
|
if (compilation.chunks.size <= maxChunks) return;
|
|
@@ -150,11 +154,11 @@ class LimitChunkCountPlugin {
|
|
|
150
154
|
const integratedSize = chunkGraph.getIntegratedChunksSize(
|
|
151
155
|
a,
|
|
152
156
|
b,
|
|
153
|
-
options
|
|
157
|
+
this.options
|
|
154
158
|
);
|
|
155
159
|
|
|
156
|
-
const aSize = chunkGraph.getChunkSize(a, options);
|
|
157
|
-
const bSize = chunkGraph.getChunkSize(b, options);
|
|
160
|
+
const aSize = chunkGraph.getChunkSize(a, this.options);
|
|
161
|
+
const bSize = chunkGraph.getChunkSize(b, this.options);
|
|
158
162
|
/** @type {ChunkCombination} */
|
|
159
163
|
const c = {
|
|
160
164
|
deleted: false,
|
|
@@ -252,7 +256,7 @@ class LimitChunkCountPlugin {
|
|
|
252
256
|
const newIntegratedSize = chunkGraph.getIntegratedChunksSize(
|
|
253
257
|
a,
|
|
254
258
|
combination.b,
|
|
255
|
-
options
|
|
259
|
+
this.options
|
|
256
260
|
);
|
|
257
261
|
const finishUpdate = combinations.startUpdate(combination);
|
|
258
262
|
combination.a = a;
|
|
@@ -271,7 +275,7 @@ class LimitChunkCountPlugin {
|
|
|
271
275
|
const newIntegratedSize = chunkGraph.getIntegratedChunksSize(
|
|
272
276
|
combination.a,
|
|
273
277
|
a,
|
|
274
|
-
options
|
|
278
|
+
this.options
|
|
275
279
|
);
|
|
276
280
|
|
|
277
281
|
const finishUpdate = combinations.startUpdate(combination);
|
|
@@ -6,23 +6,12 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const { STAGE_BASIC } = require("../OptimizationStages");
|
|
9
|
-
const createSchemaValidation = require("../util/create-schema-validation");
|
|
10
9
|
const { runtimeEqual } = require("../util/runtime");
|
|
11
10
|
|
|
12
11
|
/** @typedef {import("../../declarations/plugins/optimize/MergeDuplicateChunksPlugin").MergeDuplicateChunksPluginOptions} MergeDuplicateChunksPluginOptions */
|
|
13
12
|
/** @typedef {import("../Compiler")} Compiler */
|
|
14
13
|
/** @typedef {import("../Chunk")} Chunk */
|
|
15
14
|
|
|
16
|
-
const validate = createSchemaValidation(
|
|
17
|
-
require("../../schemas/plugins/optimize/MergeDuplicateChunksPlugin.check"),
|
|
18
|
-
() =>
|
|
19
|
-
require("../../schemas/plugins/optimize/MergeDuplicateChunksPlugin.json"),
|
|
20
|
-
{
|
|
21
|
-
name: "Merge Duplicate Chunks Plugin",
|
|
22
|
-
baseDataPath: "options"
|
|
23
|
-
}
|
|
24
|
-
);
|
|
25
|
-
|
|
26
15
|
const PLUGIN_NAME = "MergeDuplicateChunksPlugin";
|
|
27
16
|
|
|
28
17
|
class MergeDuplicateChunksPlugin {
|
|
@@ -30,7 +19,6 @@ class MergeDuplicateChunksPlugin {
|
|
|
30
19
|
* @param {MergeDuplicateChunksPluginOptions=} options options object
|
|
31
20
|
*/
|
|
32
21
|
constructor(options = { stage: STAGE_BASIC }) {
|
|
33
|
-
validate(options);
|
|
34
22
|
/** @type {MergeDuplicateChunksPluginOptions} */
|
|
35
23
|
this.options = options;
|
|
36
24
|
}
|
|
@@ -40,6 +28,21 @@ class MergeDuplicateChunksPlugin {
|
|
|
40
28
|
* @returns {void}
|
|
41
29
|
*/
|
|
42
30
|
apply(compiler) {
|
|
31
|
+
compiler.hooks.validate.tap(PLUGIN_NAME, () => {
|
|
32
|
+
compiler.validate(
|
|
33
|
+
() =>
|
|
34
|
+
require("../../schemas/plugins/optimize/MergeDuplicateChunksPlugin.json"),
|
|
35
|
+
this.options,
|
|
36
|
+
{
|
|
37
|
+
name: "Merge Duplicate Chunks Plugin",
|
|
38
|
+
baseDataPath: "options"
|
|
39
|
+
},
|
|
40
|
+
(options) =>
|
|
41
|
+
require("../../schemas/plugins/optimize/MergeDuplicateChunksPlugin.check")(
|
|
42
|
+
options
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
});
|
|
43
46
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
44
47
|
compilation.hooks.optimizeChunks.tap(
|
|
45
48
|
{
|
|
@@ -6,21 +6,11 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const { STAGE_ADVANCED } = require("../OptimizationStages");
|
|
9
|
-
const createSchemaValidation = require("../util/create-schema-validation");
|
|
10
9
|
|
|
11
10
|
/** @typedef {import("../../declarations/plugins/optimize/MinChunkSizePlugin").MinChunkSizePluginOptions} MinChunkSizePluginOptions */
|
|
12
11
|
/** @typedef {import("../Chunk")} Chunk */
|
|
13
12
|
/** @typedef {import("../Compiler")} Compiler */
|
|
14
13
|
|
|
15
|
-
const validate = createSchemaValidation(
|
|
16
|
-
require("../../schemas/plugins/optimize/MinChunkSizePlugin.check"),
|
|
17
|
-
() => require("../../schemas/plugins/optimize/MinChunkSizePlugin.json"),
|
|
18
|
-
{
|
|
19
|
-
name: "Min Chunk Size Plugin",
|
|
20
|
-
baseDataPath: "options"
|
|
21
|
-
}
|
|
22
|
-
);
|
|
23
|
-
|
|
24
14
|
const PLUGIN_NAME = "MinChunkSizePlugin";
|
|
25
15
|
|
|
26
16
|
class MinChunkSizePlugin {
|
|
@@ -28,7 +18,6 @@ class MinChunkSizePlugin {
|
|
|
28
18
|
* @param {MinChunkSizePluginOptions} options options object
|
|
29
19
|
*/
|
|
30
20
|
constructor(options) {
|
|
31
|
-
validate(options);
|
|
32
21
|
/** @type {MinChunkSizePluginOptions} */
|
|
33
22
|
this.options = options;
|
|
34
23
|
}
|
|
@@ -39,8 +28,20 @@ class MinChunkSizePlugin {
|
|
|
39
28
|
* @returns {void}
|
|
40
29
|
*/
|
|
41
30
|
apply(compiler) {
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
compiler.hooks.validate.tap(PLUGIN_NAME, () => {
|
|
32
|
+
compiler.validate(
|
|
33
|
+
() => require("../../schemas/plugins/optimize/MinChunkSizePlugin.json"),
|
|
34
|
+
this.options,
|
|
35
|
+
{
|
|
36
|
+
name: "Min Chunk Size Plugin",
|
|
37
|
+
baseDataPath: "options"
|
|
38
|
+
},
|
|
39
|
+
(options) =>
|
|
40
|
+
require("../../schemas/plugins/optimize/MinChunkSizePlugin.check")(
|
|
41
|
+
options
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
});
|
|
44
45
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
45
46
|
compilation.hooks.optimizeChunks.tap(
|
|
46
47
|
{
|
|
@@ -65,7 +66,10 @@ class MinChunkSizePlugin {
|
|
|
65
66
|
for (const a of chunks) {
|
|
66
67
|
// check if one of the chunks sizes is smaller than the minChunkSize
|
|
67
68
|
// and filter pairs that can NOT be integrated!
|
|
68
|
-
if (
|
|
69
|
+
if (
|
|
70
|
+
chunkGraph.getChunkSize(a, equalOptions) <
|
|
71
|
+
this.options.minChunkSize
|
|
72
|
+
) {
|
|
69
73
|
smallChunks.push(a);
|
|
70
74
|
for (const b of visitedChunks) {
|
|
71
75
|
if (chunkGraph.canChunksBeIntegrated(b, a)) {
|
|
@@ -79,7 +83,7 @@ class MinChunkSizePlugin {
|
|
|
79
83
|
}
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
|
-
chunkSizesMap.set(a, chunkGraph.getChunkSize(a, options));
|
|
86
|
+
chunkSizesMap.set(a, chunkGraph.getChunkSize(a, this.options));
|
|
83
87
|
visitedChunks.push(a);
|
|
84
88
|
}
|
|
85
89
|
|
|
@@ -91,7 +95,7 @@ class MinChunkSizePlugin {
|
|
|
91
95
|
const ab = chunkGraph.getIntegratedChunksSize(
|
|
92
96
|
pair[0],
|
|
93
97
|
pair[1],
|
|
94
|
-
options
|
|
98
|
+
this.options
|
|
95
99
|
);
|
|
96
100
|
/** @type {[number, number, Chunk, Chunk]} */
|
|
97
101
|
const extendedPair = [a + b - ab, ab, pair[0], pair[1]];
|