webpack 5.59.0 → 5.76.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 +22 -24
- package/bin/webpack.js +0 -0
- package/hot/dev-server.js +17 -4
- 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 +13 -5
- package/lib/Cache.js +1 -1
- package/lib/CacheFacade.js +4 -11
- package/lib/Chunk.js +6 -3
- package/lib/ChunkGraph.js +94 -8
- package/lib/ChunkGroup.js +1 -1
- package/lib/CleanPlugin.js +81 -20
- package/lib/Compilation.js +188 -93
- package/lib/Compiler.js +87 -18
- 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/DllReferencePlugin.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 +25 -4
- package/lib/ExportsInfo.js +5 -5
- package/lib/ExternalModule.js +94 -54
- package/lib/ExternalModuleFactoryPlugin.js +5 -5
- package/lib/FileSystemInfo.js +124 -58
- 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 +28 -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 +13 -3
- package/lib/NormalModule.js +51 -33
- 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 +84 -1
- package/lib/RuntimeTemplate.js +114 -2
- package/lib/Template.js +3 -2
- package/lib/TemplatedPathPlugin.js +48 -23
- package/lib/WatchIgnorePlugin.js +19 -7
- package/lib/Watching.js +33 -19
- package/lib/WebpackOptionsApply.js +79 -11
- package/lib/asset/AssetGenerator.js +228 -71
- package/lib/asset/AssetModulesPlugin.js +3 -0
- package/lib/asset/AssetParser.js +1 -0
- package/lib/asset/AssetSourceGenerator.js +31 -6
- package/lib/asset/AssetSourceParser.js +1 -0
- package/lib/asset/RawDataUrlModule.js +148 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
- package/lib/buildChunkGraph.js +38 -7
- package/lib/cache/PackFileCacheStrategy.js +15 -8
- 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 +123 -19
- package/lib/config/normalization.js +10 -2
- package/lib/config/target.js +10 -0
- package/lib/container/ContainerEntryModule.js +8 -5
- package/lib/container/FallbackModule.js +4 -4
- package/lib/container/ModuleFederationPlugin.js +2 -0
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/RemoteRuntimeModule.js +8 -7
- package/lib/css/CssExportsGenerator.js +139 -0
- package/lib/css/CssGenerator.js +109 -0
- package/lib/css/CssLoadingRuntimeModule.js +442 -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 +344 -61
- package/lib/dependencies/CommonJsRequireContextDependency.js +6 -2
- package/lib/dependencies/CommonJsRequireDependency.js +2 -1
- package/lib/dependencies/ContextDependency.js +16 -2
- package/lib/dependencies/ContextDependencyHelpers.js +21 -8
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
- package/lib/dependencies/ContextElementDependency.js +25 -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 +127 -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/ImportParserPlugin.js +35 -29
- package/lib/dependencies/JsonExportsDependency.js +17 -21
- package/lib/dependencies/LoaderDependency.js +13 -0
- package/lib/dependencies/LoaderImportDependency.js +13 -0
- package/lib/dependencies/LoaderPlugin.js +4 -2
- package/lib/dependencies/ModuleDependency.js +11 -1
- package/lib/dependencies/ProvidedDependency.js +31 -8
- package/lib/dependencies/RequireContextDependency.js +0 -16
- package/lib/dependencies/RequireEnsureDependency.js +2 -2
- package/lib/dependencies/RequireResolveContextDependency.js +2 -2
- package/lib/dependencies/RequireResolveDependency.js +2 -1
- package/lib/dependencies/URLDependency.js +3 -8
- package/lib/dependencies/URLPlugin.js +22 -1
- package/lib/dependencies/WorkerPlugin.js +2 -0
- 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 +26 -12
- 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 +20 -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 +143 -73
- package/lib/javascript/StartupHelpers.js +7 -30
- package/lib/json/JsonData.js +8 -0
- package/lib/json/JsonParser.js +4 -6
- 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 +62 -26
- package/lib/optimize/ModuleConcatenationPlugin.js +26 -4
- package/lib/optimize/RealContentHashPlugin.js +45 -15
- package/lib/optimize/SplitChunksPlugin.js +8 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +50 -66
- 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/runtime/LoadScriptRuntimeModule.js +11 -9
- package/lib/runtime/NonceRuntimeModule.js +24 -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/ProvideSharedPlugin.js +1 -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 +90 -25
- 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/wasm-sync/WebAssemblyParser.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +31 -18
- 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 +28 -32
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +321 -30
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +4 -0
- 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 +869 -296
@@ -5,50 +5,26 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
-
const Entrypoint = require("../Entrypoint");
|
9
8
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
10
9
|
const Template = require("../Template");
|
11
10
|
const { isSubset } = require("../util/SetHelpers");
|
12
|
-
const {
|
11
|
+
const { getAllChunks } = require("./ChunkHelpers");
|
13
12
|
|
14
13
|
/** @typedef {import("../util/Hash")} Hash */
|
15
14
|
/** @typedef {import("../Chunk")} Chunk */
|
16
15
|
/** @typedef {import("../Compilation")} Compilation */
|
17
16
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
17
|
+
/** @typedef {import("../ChunkGraph").EntryModuleWithChunkGroup} EntryModuleWithChunkGroup */
|
18
18
|
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
19
19
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
20
20
|
/** @typedef {(string|number)[]} EntryItem */
|
21
21
|
|
22
|
-
// TODO move to this file to ../javascript/ChunkHelpers.js
|
23
|
-
|
24
|
-
/**
|
25
|
-
* @param {Entrypoint} entrypoint a chunk group
|
26
|
-
* @param {Chunk} excludedChunk1 current chunk which is excluded
|
27
|
-
* @param {Chunk} excludedChunk2 runtime chunk which is excluded
|
28
|
-
* @returns {Set<Chunk>} chunks
|
29
|
-
*/
|
30
|
-
const getAllChunks = (entrypoint, excludedChunk1, excludedChunk2) => {
|
31
|
-
const queue = new Set([entrypoint]);
|
32
|
-
const chunks = new Set();
|
33
|
-
for (const entrypoint of queue) {
|
34
|
-
for (const chunk of entrypoint.chunks) {
|
35
|
-
if (chunk === excludedChunk1) continue;
|
36
|
-
if (chunk === excludedChunk2) continue;
|
37
|
-
chunks.add(chunk);
|
38
|
-
}
|
39
|
-
for (const parent of entrypoint.parentsIterable) {
|
40
|
-
if (parent instanceof Entrypoint) queue.add(parent);
|
41
|
-
}
|
42
|
-
}
|
43
|
-
return chunks;
|
44
|
-
};
|
45
|
-
|
46
22
|
const EXPORT_PREFIX = "var __webpack_exports__ = ";
|
47
23
|
|
48
24
|
/**
|
49
25
|
* @param {ChunkGraph} chunkGraph chunkGraph
|
50
26
|
* @param {RuntimeTemplate} runtimeTemplate runtimeTemplate
|
51
|
-
* @param {
|
27
|
+
* @param {EntryModuleWithChunkGroup[]} entries entries
|
52
28
|
* @param {Chunk} chunk chunk
|
53
29
|
* @param {boolean} passive true: passive startup with on chunks loaded
|
54
30
|
* @returns {string} runtime code
|
@@ -126,7 +102,7 @@ exports.generateEntryStartup = (
|
|
126
102
|
/**
|
127
103
|
* @param {Hash} hash the hash to update
|
128
104
|
* @param {ChunkGraph} chunkGraph chunkGraph
|
129
|
-
* @param {
|
105
|
+
* @param {EntryModuleWithChunkGroup[]} entries entries
|
130
106
|
* @param {Chunk} chunk chunk
|
131
107
|
* @returns {void}
|
132
108
|
*/
|
@@ -143,12 +119,13 @@ exports.updateHashForEntryStartup = (hash, chunkGraph, entries, chunk) => {
|
|
143
119
|
/**
|
144
120
|
* @param {Chunk} chunk the chunk
|
145
121
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
122
|
+
* @param {function(Chunk, ChunkGraph): boolean} filterFn filter function
|
146
123
|
* @returns {Set<number | string>} initially fulfilled chunk ids
|
147
124
|
*/
|
148
|
-
exports.getInitialChunkIds = (chunk, chunkGraph) => {
|
125
|
+
exports.getInitialChunkIds = (chunk, chunkGraph, filterFn) => {
|
149
126
|
const initialChunkIds = new Set(chunk.ids);
|
150
127
|
for (const c of chunk.getAllInitialChunks()) {
|
151
|
-
if (c === chunk ||
|
128
|
+
if (c === chunk || filterFn(c, chunkGraph)) continue;
|
152
129
|
for (const id of c.ids) initialChunkIds.add(id);
|
153
130
|
}
|
154
131
|
return initialChunkIds;
|
package/lib/json/JsonData.js
CHANGED
@@ -24,6 +24,14 @@ class JsonData {
|
|
24
24
|
}
|
25
25
|
return this._data;
|
26
26
|
}
|
27
|
+
|
28
|
+
updateHash(hash) {
|
29
|
+
if (this._buffer === undefined && this._data !== undefined) {
|
30
|
+
this._buffer = Buffer.from(JSON.stringify(this._data));
|
31
|
+
}
|
32
|
+
|
33
|
+
if (this._buffer) return hash.update(this._buffer);
|
34
|
+
}
|
27
35
|
}
|
28
36
|
|
29
37
|
register(JsonData, "webpack/lib/json/JsonData", null, {
|
package/lib/json/JsonParser.js
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
-
const parseJson = require("json-parse-better-errors");
|
8
|
+
const parseJson = require("json-parse-even-better-errors");
|
9
9
|
const Parser = require("../Parser");
|
10
10
|
const JsonExportsDependency = require("../dependencies/JsonExportsDependency");
|
11
11
|
const JsonData = require("./JsonData");
|
@@ -41,15 +41,13 @@ class JsonParser extends Parser {
|
|
41
41
|
typeof source === "object"
|
42
42
|
? source
|
43
43
|
: parseFn(source[0] === "\ufeff" ? source.slice(1) : source);
|
44
|
-
|
45
|
-
state.module.buildInfo.jsonData =
|
44
|
+
const jsonData = new JsonData(data);
|
45
|
+
state.module.buildInfo.jsonData = jsonData;
|
46
46
|
state.module.buildInfo.strict = true;
|
47
47
|
state.module.buildMeta.exportsType = "default";
|
48
48
|
state.module.buildMeta.defaultObject =
|
49
49
|
typeof data === "object" ? "redirect-warn" : false;
|
50
|
-
state.module.addDependency(
|
51
|
-
new JsonExportsDependency(JsonExportsDependency.getExportsFromData(data))
|
52
|
-
);
|
50
|
+
state.module.addDependency(new JsonExportsDependency(jsonData));
|
53
51
|
return state;
|
54
52
|
}
|
55
53
|
}
|
@@ -92,7 +92,7 @@ const accessWithInit = (accessor, existingLength, initLast = false) => {
|
|
92
92
|
* @property {LibraryType} type
|
93
93
|
* @property {string[] | "global"} prefix name prefix
|
94
94
|
* @property {string | false} declare declare name as variable
|
95
|
-
* @property {"error"|"copy"|"assign"} unnamed behavior for unnamed library name
|
95
|
+
* @property {"error"|"static"|"copy"|"assign"} unnamed behavior for unnamed library name
|
96
96
|
* @property {"copy"|"assign"=} named behavior for named library name
|
97
97
|
*/
|
98
98
|
|
@@ -174,7 +174,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
174
174
|
|
175
175
|
_getPrefix(compilation) {
|
176
176
|
return this.prefix === "global"
|
177
|
-
? [compilation.
|
177
|
+
? [compilation.runtimeTemplate.globalObject]
|
178
178
|
: this.prefix;
|
179
179
|
}
|
180
180
|
|
@@ -222,9 +222,15 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
222
222
|
* @param {LibraryContext<T>} libraryContext context
|
223
223
|
* @returns {string | undefined} bailout reason
|
224
224
|
*/
|
225
|
-
embedInRuntimeBailout(
|
225
|
+
embedInRuntimeBailout(
|
226
|
+
module,
|
227
|
+
{ chunk, codeGenerationResults },
|
228
|
+
{ options, compilation }
|
229
|
+
) {
|
230
|
+
const { data } = codeGenerationResults.get(module, chunk.runtime);
|
226
231
|
const topLevelDeclarations =
|
227
|
-
|
232
|
+
(data && data.get("topLevelDeclarations")) ||
|
233
|
+
(module.buildInfo && module.buildInfo.topLevelDeclarations);
|
228
234
|
if (!topLevelDeclarations)
|
229
235
|
return "it doesn't tell about top level declarations.";
|
230
236
|
const fullNameResolved = this._getResolvedFullName(
|
@@ -261,19 +267,42 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
261
267
|
* @param {LibraryContext<T>} libraryContext context
|
262
268
|
* @returns {Source} source with library export
|
263
269
|
*/
|
264
|
-
renderStartup(
|
270
|
+
renderStartup(
|
271
|
+
source,
|
272
|
+
module,
|
273
|
+
{ moduleGraph, chunk },
|
274
|
+
{ options, compilation }
|
275
|
+
) {
|
265
276
|
const fullNameResolved = this._getResolvedFullName(
|
266
277
|
options,
|
267
278
|
chunk,
|
268
279
|
compilation
|
269
280
|
);
|
281
|
+
const staticExports = this.unnamed === "static";
|
270
282
|
const exportAccess = options.export
|
271
283
|
? propertyAccess(
|
272
284
|
Array.isArray(options.export) ? options.export : [options.export]
|
273
285
|
)
|
274
286
|
: "";
|
275
287
|
const result = new ConcatSource(source);
|
276
|
-
if (
|
288
|
+
if (staticExports) {
|
289
|
+
const exportsInfo = moduleGraph.getExportsInfo(module);
|
290
|
+
const exportTarget = accessWithInit(
|
291
|
+
fullNameResolved,
|
292
|
+
this._getPrefix(compilation).length,
|
293
|
+
true
|
294
|
+
);
|
295
|
+
for (const exportInfo of exportsInfo.orderedExports) {
|
296
|
+
if (!exportInfo.provided) continue;
|
297
|
+
const nameAccess = propertyAccess([exportInfo.name]);
|
298
|
+
result.add(
|
299
|
+
`${exportTarget}${nameAccess} = __webpack_exports__${exportAccess}${nameAccess};\n`
|
300
|
+
);
|
301
|
+
}
|
302
|
+
result.add(
|
303
|
+
`Object.defineProperty(${exportTarget}, "__esModule", { value: true });\n`
|
304
|
+
);
|
305
|
+
} else if (options.name ? this.named === "copy" : this.unnamed === "copy") {
|
277
306
|
result.add(
|
278
307
|
`var __webpack_export_target__ = ${accessWithInit(
|
279
308
|
fullNameResolved,
|
@@ -325,15 +354,10 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
325
354
|
*/
|
326
355
|
chunkHash(chunk, hash, chunkHashContext, { options, compilation }) {
|
327
356
|
hash.update("AssignLibraryPlugin");
|
328
|
-
const
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
const fullName = options.name ? prefix.concat(options.name) : prefix;
|
333
|
-
const fullNameResolved = fullName.map(n =>
|
334
|
-
compilation.getPath(n, {
|
335
|
-
chunk
|
336
|
-
})
|
357
|
+
const fullNameResolved = this._getResolvedFullName(
|
358
|
+
options,
|
359
|
+
chunk,
|
360
|
+
compilation
|
337
361
|
);
|
338
362
|
if (options.name ? this.named === "copy" : this.unnamed === "copy") {
|
339
363
|
hash.update("copy");
|
@@ -167,6 +167,17 @@ class EnableLibraryPlugin {
|
|
167
167
|
}).apply(compiler);
|
168
168
|
break;
|
169
169
|
}
|
170
|
+
case "commonjs-static": {
|
171
|
+
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
172
|
+
const AssignLibraryPlugin = require("./AssignLibraryPlugin");
|
173
|
+
new AssignLibraryPlugin({
|
174
|
+
type,
|
175
|
+
prefix: ["exports"],
|
176
|
+
declare: false,
|
177
|
+
unnamed: "static"
|
178
|
+
}).apply(compiler);
|
179
|
+
break;
|
180
|
+
}
|
170
181
|
case "commonjs2":
|
171
182
|
case "commonjs-module": {
|
172
183
|
//@ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
@@ -310,9 +310,11 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
310
310
|
: " var a = factory();\n") +
|
311
311
|
" for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n" +
|
312
312
|
" }\n") +
|
313
|
-
`})(${
|
314
|
-
runtimeTemplate.
|
315
|
-
|
313
|
+
`})(${runtimeTemplate.outputOptions.globalObject}, ${
|
314
|
+
runtimeTemplate.supportsArrowFunction()
|
315
|
+
? `(${externalsArguments(externals)}) =>`
|
316
|
+
: `function(${externalsArguments(externals)})`
|
317
|
+
} {\nreturn `,
|
316
318
|
"webpack/universalModuleDefinition"
|
317
319
|
),
|
318
320
|
source,
|
@@ -34,6 +34,8 @@ const builtins = [
|
|
34
34
|
"net",
|
35
35
|
"os",
|
36
36
|
"path",
|
37
|
+
"path/posix",
|
38
|
+
"path/win32",
|
37
39
|
"perf_hooks",
|
38
40
|
"process",
|
39
41
|
"punycode",
|
@@ -52,6 +54,7 @@ const builtins = [
|
|
52
54
|
"tty",
|
53
55
|
"url",
|
54
56
|
"util",
|
57
|
+
"util/types",
|
55
58
|
"v8",
|
56
59
|
"vm",
|
57
60
|
"wasi",
|
@@ -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
|
])
|