webpack 5.102.1 → 5.103.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.
- package/README.md +121 -134
- package/lib/CompatibilityPlugin.js +25 -2
- package/lib/Compilation.js +25 -2
- package/lib/ConcatenationScope.js +0 -15
- package/lib/CssModule.js +6 -1
- package/lib/DefinePlugin.js +11 -11
- package/lib/Dependency.js +8 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DotenvPlugin.js +457 -0
- package/lib/EnvironmentPlugin.js +19 -16
- package/lib/EvalSourceMapDevToolPlugin.js +16 -0
- package/lib/ExportsInfo.js +6 -2
- package/lib/ExternalModule.js +20 -28
- package/lib/ExternalModuleFactoryPlugin.js +10 -8
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/ManifestPlugin.js +235 -0
- package/lib/Module.js +3 -0
- package/lib/ModuleGraph.js +2 -1
- package/lib/ModuleSourceTypesConstants.js +0 -6
- package/lib/MultiCompiler.js +1 -1
- package/lib/NodeStuffPlugin.js +419 -121
- package/lib/NormalModule.js +17 -16
- package/lib/RuntimeGlobals.js +22 -4
- package/lib/RuntimePlugin.js +27 -6
- package/lib/RuntimeTemplate.js +115 -56
- package/lib/SourceMapDevToolPlugin.js +20 -0
- package/lib/WebpackOptionsApply.js +33 -9
- package/lib/asset/AssetBytesGenerator.js +1 -1
- package/lib/asset/AssetGenerator.js +1 -2
- package/lib/asset/AssetSourceGenerator.js +1 -1
- package/lib/config/browserslistTargetHandler.js +5 -0
- package/lib/config/defaults.js +98 -18
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +6 -0
- package/lib/css/CssGenerator.js +283 -57
- package/lib/css/CssLoadingRuntimeModule.js +2 -0
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
- package/lib/css/CssModulesPlugin.js +84 -34
- package/lib/css/CssParser.js +1174 -667
- package/lib/css/walkCssTokens.js +97 -0
- package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
- package/lib/dependencies/CommonJsPlugin.js +12 -0
- package/lib/dependencies/CssIcssExportDependency.js +247 -8
- package/lib/dependencies/CssIcssFromIdentifierDependency.js +124 -0
- package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +48 -0
- package/lib/dependencies/CssIcssImportDependency.js +60 -54
- package/lib/dependencies/CssIcssLocalIdentifierDependency.js +61 -0
- package/lib/dependencies/{CssSelfLocalIdentifierDependency.js → CssIcssSelfLocalIdentifierDependency.js} +88 -10
- package/lib/dependencies/CssIcssSymbolDependency.js +31 -29
- package/lib/dependencies/CssImportDependency.js +15 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +95 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +32 -21
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +12 -8
- package/lib/dependencies/HarmonyImportDependency.js +23 -27
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
- package/lib/dependencies/ImportDependency.js +8 -2
- package/lib/dependencies/ImportEagerDependency.js +6 -3
- package/lib/dependencies/ImportMetaPlugin.js +97 -9
- package/lib/dependencies/ImportParserPlugin.js +19 -21
- package/lib/dependencies/ImportPhase.js +121 -0
- package/lib/dependencies/ImportWeakDependency.js +6 -3
- package/lib/dependencies/ModuleDependency.js +5 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
- package/lib/hmr/LazyCompilationPlugin.js +1 -0
- package/lib/ids/IdHelpers.js +4 -1
- package/lib/index.js +6 -0
- package/lib/javascript/ChunkHelpers.js +16 -5
- package/lib/javascript/JavascriptGenerator.js +101 -101
- package/lib/javascript/JavascriptModulesPlugin.js +23 -13
- package/lib/javascript/JavascriptParser.js +142 -38
- package/lib/json/JsonParser.js +7 -1
- package/lib/library/ModuleLibraryPlugin.js +0 -10
- package/lib/library/SystemLibraryPlugin.js +4 -0
- package/lib/library/UmdLibraryPlugin.js +1 -1
- package/lib/node/NodeTargetPlugin.js +9 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
- package/lib/optimize/ConcatenatedModule.js +161 -135
- package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
- package/lib/util/comparators.js +4 -3
- package/lib/util/internalSerializables.js +4 -4
- package/lib/util/jsonParseEvenBetterErrors.js +10 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +8 -5
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +8 -4
- package/lib/web/FetchCompileWasmPlugin.js +0 -2
- package/lib/webpack.js +85 -82
- package/module.d.ts +5 -0
- package/package.json +16 -14
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +109 -27
- package/schemas/plugins/ManifestPlugin.check.d.ts +7 -0
- package/schemas/plugins/ManifestPlugin.check.js +6 -0
- package/schemas/plugins/ManifestPlugin.json +98 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
- 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/json/JsonModulesPluginParser.check.js +1 -1
- package/types.d.ts +560 -293
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
package/lib/NormalModule.js
CHANGED
|
@@ -96,7 +96,6 @@ const memoize = require("./util/memoize");
|
|
|
96
96
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
|
97
97
|
/** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
|
|
98
98
|
/** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
|
|
99
|
-
/** @typedef {import("../declarations/WebpackOptions").RuleSetRule["extractSourceMap"]} ExtractSourceMapOptions */
|
|
100
99
|
/**
|
|
101
100
|
* @template T
|
|
102
101
|
* @typedef {import("./util/deprecation").FakeHook<T>} FakeHook
|
|
@@ -255,7 +254,7 @@ makeSerializable(
|
|
|
255
254
|
* @property {Generator} generator the generator used
|
|
256
255
|
* @property {GeneratorOptions=} generatorOptions the options of the generator used
|
|
257
256
|
* @property {ResolveOptions=} resolveOptions options used for resolving requests from this module
|
|
258
|
-
* @property {boolean
|
|
257
|
+
* @property {boolean} extractSourceMap enable/disable extracting source map
|
|
259
258
|
*/
|
|
260
259
|
|
|
261
260
|
/**
|
|
@@ -353,34 +352,36 @@ class NormalModule extends Module {
|
|
|
353
352
|
super(type, context || getContext(resource), layer);
|
|
354
353
|
|
|
355
354
|
// Info from Factory
|
|
356
|
-
/** @type {
|
|
355
|
+
/** @type {NormalModuleCreateData['request']} */
|
|
357
356
|
this.request = request;
|
|
358
|
-
/** @type {
|
|
357
|
+
/** @type {NormalModuleCreateData['userRequest']} */
|
|
359
358
|
this.userRequest = userRequest;
|
|
360
|
-
/** @type {
|
|
359
|
+
/** @type {NormalModuleCreateData['rawRequest']} */
|
|
361
360
|
this.rawRequest = rawRequest;
|
|
362
361
|
/** @type {boolean} */
|
|
363
362
|
this.binary = /^(asset|webassembly)\b/.test(type);
|
|
364
|
-
/** @type {
|
|
363
|
+
/** @type {NormalModuleCreateData['parser'] | undefined} */
|
|
365
364
|
this.parser = parser;
|
|
366
|
-
/** @type {
|
|
365
|
+
/** @type {NormalModuleCreateData['parserOptions']} */
|
|
367
366
|
this.parserOptions = parserOptions;
|
|
368
|
-
/** @type {
|
|
367
|
+
/** @type {NormalModuleCreateData['generator'] | undefined} */
|
|
369
368
|
this.generator = generator;
|
|
370
|
-
/** @type {
|
|
369
|
+
/** @type {NormalModuleCreateData['generatorOptions']} */
|
|
371
370
|
this.generatorOptions = generatorOptions;
|
|
372
|
-
/** @type {
|
|
371
|
+
/** @type {NormalModuleCreateData['resource']} */
|
|
373
372
|
this.resource = resource;
|
|
373
|
+
/** @type {NormalModuleCreateData['resourceResolveData']} */
|
|
374
374
|
this.resourceResolveData = resourceResolveData;
|
|
375
|
-
/** @type {
|
|
375
|
+
/** @type {NormalModuleCreateData['matchResource']} */
|
|
376
376
|
this.matchResource = matchResource;
|
|
377
|
-
/** @type {
|
|
377
|
+
/** @type {NormalModuleCreateData['loaders']} */
|
|
378
378
|
this.loaders = loaders;
|
|
379
379
|
if (resolveOptions !== undefined) {
|
|
380
380
|
// already declared in super class
|
|
381
|
+
/** @type {NormalModuleCreateData['resolveOptions']} */
|
|
381
382
|
this.resolveOptions = resolveOptions;
|
|
382
383
|
}
|
|
383
|
-
/** @type {
|
|
384
|
+
/** @type {NormalModuleCreateData['extractSourceMap']} */
|
|
384
385
|
this.extractSourceMap = extractSourceMap;
|
|
385
386
|
|
|
386
387
|
// Info from Build
|
|
@@ -487,6 +488,7 @@ class NormalModule extends Module {
|
|
|
487
488
|
this.context = m.context;
|
|
488
489
|
this.matchResource = m.matchResource;
|
|
489
490
|
this.loaders = m.loaders;
|
|
491
|
+
this.extractSourceMap = m.extractSourceMap;
|
|
490
492
|
}
|
|
491
493
|
|
|
492
494
|
/**
|
|
@@ -1721,7 +1723,6 @@ class NormalModule extends Module {
|
|
|
1721
1723
|
write(this._lastSuccessfulBuildMeta);
|
|
1722
1724
|
write(this._forceBuild);
|
|
1723
1725
|
write(this._codeGeneratorData);
|
|
1724
|
-
write(this.extractSourceMap);
|
|
1725
1726
|
super.serialize(context);
|
|
1726
1727
|
}
|
|
1727
1728
|
|
|
@@ -1746,7 +1747,8 @@ class NormalModule extends Module {
|
|
|
1746
1747
|
parserOptions: /** @type {EXPECTED_ANY} */ (null),
|
|
1747
1748
|
generator: /** @type {EXPECTED_ANY} */ (null),
|
|
1748
1749
|
generatorOptions: /** @type {EXPECTED_ANY} */ (null),
|
|
1749
|
-
resolveOptions: /** @type {EXPECTED_ANY} */ (null)
|
|
1750
|
+
resolveOptions: /** @type {EXPECTED_ANY} */ (null),
|
|
1751
|
+
extractSourceMap: /** @type {EXPECTED_ANY} */ (null)
|
|
1750
1752
|
});
|
|
1751
1753
|
obj.deserialize(context);
|
|
1752
1754
|
return obj;
|
|
@@ -1762,7 +1764,6 @@ class NormalModule extends Module {
|
|
|
1762
1764
|
this._lastSuccessfulBuildMeta = read();
|
|
1763
1765
|
this._forceBuild = read();
|
|
1764
1766
|
this._codeGeneratorData = read();
|
|
1765
|
-
this.extractSourceMap = read();
|
|
1766
1767
|
super.deserialize(context);
|
|
1767
1768
|
}
|
|
1768
1769
|
}
|
package/lib/RuntimeGlobals.js
CHANGED
|
@@ -78,11 +78,29 @@ module.exports.createScript = "__webpack_require__.ts";
|
|
|
78
78
|
*/
|
|
79
79
|
module.exports.createScriptUrl = "__webpack_require__.tu";
|
|
80
80
|
|
|
81
|
+
/**
|
|
82
|
+
* merge multiple CSS stylesheets (CSSStyleSheet or string) into one CSS text string
|
|
83
|
+
* Arguments: (sheets: Array<CSSStyleSheet | string> | CSSStyleSheet | string) => string
|
|
84
|
+
*/
|
|
85
|
+
module.exports.cssMergeStyleSheets = "__webpack_require__.mcs";
|
|
86
|
+
|
|
81
87
|
/**
|
|
82
88
|
* The current scope when getting a module from a remote
|
|
83
89
|
*/
|
|
84
90
|
module.exports.currentRemoteGetScope = "__webpack_require__.R";
|
|
85
91
|
|
|
92
|
+
/**
|
|
93
|
+
* resolve async transitive dependencies for deferred module
|
|
94
|
+
*/
|
|
95
|
+
module.exports.deferredModuleAsyncTransitiveDependencies =
|
|
96
|
+
"__webpack_require__.zT";
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* the internal symbol for getting the async transitive dependencies for deferred module
|
|
100
|
+
*/
|
|
101
|
+
module.exports.deferredModuleAsyncTransitiveDependenciesSymbol =
|
|
102
|
+
"__webpack_require__.zS";
|
|
103
|
+
|
|
86
104
|
/**
|
|
87
105
|
* the exported property define getters function
|
|
88
106
|
*/
|
|
@@ -258,14 +276,14 @@ module.exports.loadScript = "__webpack_require__.l";
|
|
|
258
276
|
module.exports.makeDeferredNamespaceObject = "__webpack_require__.z";
|
|
259
277
|
|
|
260
278
|
/**
|
|
261
|
-
*
|
|
279
|
+
* define compatibility on export
|
|
262
280
|
*/
|
|
263
|
-
module.exports.
|
|
281
|
+
module.exports.makeNamespaceObject = "__webpack_require__.r";
|
|
264
282
|
|
|
265
283
|
/**
|
|
266
|
-
*
|
|
284
|
+
* make a optimized deferred namespace object
|
|
267
285
|
*/
|
|
268
|
-
module.exports.
|
|
286
|
+
module.exports.makeOptimizedDeferredNamespaceObject = "__webpack_require__.zO";
|
|
269
287
|
|
|
270
288
|
/**
|
|
271
289
|
* the internal module object
|
package/lib/RuntimePlugin.js
CHANGED
|
@@ -24,7 +24,10 @@ const GetTrustedTypesPolicyRuntimeModule = require("./runtime/GetTrustedTypesPol
|
|
|
24
24
|
const GlobalRuntimeModule = require("./runtime/GlobalRuntimeModule");
|
|
25
25
|
const HasOwnPropertyRuntimeModule = require("./runtime/HasOwnPropertyRuntimeModule");
|
|
26
26
|
const LoadScriptRuntimeModule = require("./runtime/LoadScriptRuntimeModule");
|
|
27
|
-
const
|
|
27
|
+
const {
|
|
28
|
+
MakeDeferredNamespaceObjectRuntimeModule,
|
|
29
|
+
MakeOptimizedDeferredNamespaceObjectRuntimeModule
|
|
30
|
+
} = require("./runtime/MakeDeferredNamespaceObjectRuntime");
|
|
28
31
|
const MakeNamespaceObjectRuntimeModule = require("./runtime/MakeNamespaceObjectRuntimeModule");
|
|
29
32
|
const NonceRuntimeModule = require("./runtime/NonceRuntimeModule");
|
|
30
33
|
const OnChunksLoadedRuntimeModule = require("./runtime/OnChunksLoadedRuntimeModule");
|
|
@@ -78,6 +81,7 @@ const GLOBALS_ON_REQUIRE = [
|
|
|
78
81
|
RuntimeGlobals.loadScript,
|
|
79
82
|
RuntimeGlobals.systemContext,
|
|
80
83
|
RuntimeGlobals.onChunksLoaded,
|
|
84
|
+
RuntimeGlobals.makeOptimizedDeferredNamespaceObject,
|
|
81
85
|
RuntimeGlobals.makeDeferredNamespaceObject
|
|
82
86
|
];
|
|
83
87
|
|
|
@@ -96,11 +100,11 @@ const TREE_DEPENDENCIES = {
|
|
|
96
100
|
RuntimeGlobals.makeNamespaceObject,
|
|
97
101
|
RuntimeGlobals.require
|
|
98
102
|
],
|
|
103
|
+
[RuntimeGlobals.makeOptimizedDeferredNamespaceObject]: [
|
|
104
|
+
RuntimeGlobals.require
|
|
105
|
+
],
|
|
99
106
|
[RuntimeGlobals.makeDeferredNamespaceObject]: [
|
|
100
|
-
RuntimeGlobals.definePropertyGetters,
|
|
101
|
-
RuntimeGlobals.makeNamespaceObject,
|
|
102
107
|
RuntimeGlobals.createFakeNamespaceObject,
|
|
103
|
-
RuntimeGlobals.hasOwnProperty,
|
|
104
108
|
RuntimeGlobals.require
|
|
105
109
|
],
|
|
106
110
|
[RuntimeGlobals.initializeSharing]: [RuntimeGlobals.shareScopeMap],
|
|
@@ -190,12 +194,23 @@ class RuntimePlugin {
|
|
|
190
194
|
);
|
|
191
195
|
return true;
|
|
192
196
|
});
|
|
197
|
+
compilation.hooks.runtimeRequirementInTree
|
|
198
|
+
.for(RuntimeGlobals.makeOptimizedDeferredNamespaceObject)
|
|
199
|
+
.tap("RuntimePlugin", (chunk, runtimeRequirement) => {
|
|
200
|
+
compilation.addRuntimeModule(
|
|
201
|
+
chunk,
|
|
202
|
+
new MakeOptimizedDeferredNamespaceObjectRuntimeModule(
|
|
203
|
+
runtimeRequirement.has(RuntimeGlobals.asyncModule)
|
|
204
|
+
)
|
|
205
|
+
);
|
|
206
|
+
return true;
|
|
207
|
+
});
|
|
193
208
|
compilation.hooks.runtimeRequirementInTree
|
|
194
209
|
.for(RuntimeGlobals.makeDeferredNamespaceObject)
|
|
195
210
|
.tap("RuntimePlugin", (chunk, runtimeRequirement) => {
|
|
196
211
|
compilation.addRuntimeModule(
|
|
197
212
|
chunk,
|
|
198
|
-
new
|
|
213
|
+
new MakeDeferredNamespaceObjectRuntimeModule(
|
|
199
214
|
runtimeRequirement.has(RuntimeGlobals.asyncModule)
|
|
200
215
|
)
|
|
201
216
|
);
|
|
@@ -238,7 +253,13 @@ class RuntimePlugin {
|
|
|
238
253
|
|
|
239
254
|
if (publicPath === "auto") {
|
|
240
255
|
const module = new AutoPublicPathRuntimeModule();
|
|
241
|
-
if (
|
|
256
|
+
if (
|
|
257
|
+
scriptType !== "module" &&
|
|
258
|
+
!outputOptions.environment.globalThis
|
|
259
|
+
) {
|
|
260
|
+
set.add(RuntimeGlobals.global);
|
|
261
|
+
}
|
|
262
|
+
|
|
242
263
|
compilation.addRuntimeModule(chunk, module);
|
|
243
264
|
} else {
|
|
244
265
|
const module = new PublicPathRuntimeModule(publicPath);
|
package/lib/RuntimeTemplate.js
CHANGED
|
@@ -11,15 +11,24 @@ const Template = require("./Template");
|
|
|
11
11
|
const {
|
|
12
12
|
getOutgoingAsyncModules
|
|
13
13
|
} = require("./async-modules/AsyncModuleHelpers");
|
|
14
|
+
const { ImportPhaseUtils } = require("./dependencies/ImportPhase");
|
|
14
15
|
const {
|
|
15
16
|
getMakeDeferredNamespaceModeFromExportsType,
|
|
16
17
|
getOptimizedDeferredModule
|
|
17
18
|
} = require("./runtime/MakeDeferredNamespaceObjectRuntime");
|
|
18
19
|
const { equals } = require("./util/ArrayHelpers");
|
|
19
20
|
const compileBooleanMatcher = require("./util/compileBooleanMatcher");
|
|
21
|
+
const memoize = require("./util/memoize");
|
|
20
22
|
const propertyAccess = require("./util/propertyAccess");
|
|
21
23
|
const { forEachRuntime, subtractRuntime } = require("./util/runtime");
|
|
22
24
|
|
|
25
|
+
const getHarmonyImportDependency = memoize(() =>
|
|
26
|
+
require("./dependencies/HarmonyImportDependency")
|
|
27
|
+
);
|
|
28
|
+
const getImportDependency = memoize(() =>
|
|
29
|
+
require("./dependencies/ImportDependency")
|
|
30
|
+
);
|
|
31
|
+
|
|
23
32
|
/** @typedef {import("./config/defaults").OutputNormalizedWithDefaults} OutputOptions */
|
|
24
33
|
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
|
25
34
|
/** @typedef {import("./Chunk")} Chunk */
|
|
@@ -32,6 +41,8 @@ const { forEachRuntime, subtractRuntime } = require("./util/runtime");
|
|
|
32
41
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
|
33
42
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
|
34
43
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
|
44
|
+
/** @typedef {import("./dependencies/ImportPhase").ImportPhaseType} ImportPhaseType */
|
|
45
|
+
/** @typedef {import("./NormalModuleFactory").ModuleDependency} ModuleDependency */
|
|
35
46
|
|
|
36
47
|
/**
|
|
37
48
|
* @param {Module} module the module
|
|
@@ -617,6 +628,7 @@ class RuntimeTemplate {
|
|
|
617
628
|
* @param {string} options.message a message for the comment
|
|
618
629
|
* @param {boolean=} options.strict if the current module is in strict esm mode
|
|
619
630
|
* @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
|
|
631
|
+
* @param {Dependency} options.dependency dependency
|
|
620
632
|
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
|
621
633
|
* @returns {string} the promise expression
|
|
622
634
|
*/
|
|
@@ -628,6 +640,7 @@ class RuntimeTemplate {
|
|
|
628
640
|
message,
|
|
629
641
|
strict,
|
|
630
642
|
weak,
|
|
643
|
+
dependency,
|
|
631
644
|
runtimeRequirements
|
|
632
645
|
}) {
|
|
633
646
|
if (!module) {
|
|
@@ -684,42 +697,45 @@ class RuntimeTemplate {
|
|
|
684
697
|
type: "statements"
|
|
685
698
|
})} } `;
|
|
686
699
|
}
|
|
687
|
-
const moduleIdExpr = this.moduleId({
|
|
688
|
-
module,
|
|
689
|
-
chunkGraph,
|
|
690
|
-
request,
|
|
691
|
-
weak
|
|
692
|
-
});
|
|
693
700
|
const exportsType = module.getExportsType(chunkGraph.moduleGraph, strict);
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
701
|
+
|
|
702
|
+
const isModuleDeferred =
|
|
703
|
+
(dependency instanceof getHarmonyImportDependency() ||
|
|
704
|
+
dependency instanceof getImportDependency()) &&
|
|
705
|
+
ImportPhaseUtils.isDefer(dependency.phase) &&
|
|
706
|
+
!(/** @type {BuildMeta} */ (module.buildMeta).async);
|
|
707
|
+
|
|
708
|
+
if (isModuleDeferred) {
|
|
709
|
+
runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject);
|
|
710
|
+
const mode = getMakeDeferredNamespaceModeFromExportsType(exportsType);
|
|
711
|
+
const asyncDeps = Array.from(
|
|
712
|
+
getOutgoingAsyncModules(chunkGraph.moduleGraph, module),
|
|
713
|
+
(m) => chunkGraph.getModuleId(m)
|
|
714
|
+
).filter((id) => id !== null);
|
|
715
|
+
if (asyncDeps.length) {
|
|
697
716
|
if (header) {
|
|
698
|
-
const rawModule = this.moduleRaw({
|
|
699
|
-
module,
|
|
700
|
-
chunkGraph,
|
|
701
|
-
request,
|
|
702
|
-
weak,
|
|
703
|
-
runtimeRequirements
|
|
704
|
-
});
|
|
705
717
|
appending = `.then(${this.basicFunction(
|
|
706
718
|
"",
|
|
707
|
-
`${header}return ${
|
|
719
|
+
`${header}return ${RuntimeGlobals.deferredModuleAsyncTransitiveDependencies}(${JSON.stringify(asyncDeps)});`
|
|
708
720
|
)})`;
|
|
709
721
|
} else {
|
|
710
722
|
runtimeRequirements.add(RuntimeGlobals.require);
|
|
711
|
-
appending = `.then(${
|
|
723
|
+
appending = `.then(${this.returningFunction(`${RuntimeGlobals.deferredModuleAsyncTransitiveDependencies}(${JSON.stringify(asyncDeps)})`)})`;
|
|
712
724
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
725
|
+
appending += `.then(${RuntimeGlobals.makeDeferredNamespaceObject}.bind(${RuntimeGlobals.require}, ${comment}${idExpr}, ${mode}))`;
|
|
726
|
+
} else if (header) {
|
|
727
|
+
appending = `.then(${this.basicFunction(
|
|
728
|
+
"",
|
|
729
|
+
`${header}return ${RuntimeGlobals.makeDeferredNamespaceObject}(${comment}${idExpr}, ${mode});`
|
|
730
|
+
)})`;
|
|
731
|
+
} else {
|
|
732
|
+
runtimeRequirements.add(RuntimeGlobals.require);
|
|
733
|
+
appending = `.then(${RuntimeGlobals.makeDeferredNamespaceObject}.bind(${RuntimeGlobals.require}, ${comment}${idExpr}, ${mode}))`;
|
|
734
|
+
}
|
|
735
|
+
} else {
|
|
736
|
+
let fakeType = 16;
|
|
737
|
+
switch (exportsType) {
|
|
738
|
+
case "namespace":
|
|
723
739
|
if (header) {
|
|
724
740
|
const rawModule = this.moduleRaw({
|
|
725
741
|
module,
|
|
@@ -736,23 +752,56 @@ class RuntimeTemplate {
|
|
|
736
752
|
runtimeRequirements.add(RuntimeGlobals.require);
|
|
737
753
|
appending = `.then(${RuntimeGlobals.require}.bind(${RuntimeGlobals.require}, ${comment}${idExpr}))`;
|
|
738
754
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
fakeType |=
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
755
|
+
break;
|
|
756
|
+
case "dynamic":
|
|
757
|
+
fakeType |= 4;
|
|
758
|
+
/* fall through */
|
|
759
|
+
case "default-with-named":
|
|
760
|
+
fakeType |= 2;
|
|
761
|
+
/* fall through */
|
|
762
|
+
case "default-only":
|
|
763
|
+
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
|
764
|
+
if (chunkGraph.moduleGraph.isAsync(module)) {
|
|
765
|
+
if (header) {
|
|
766
|
+
const rawModule = this.moduleRaw({
|
|
767
|
+
module,
|
|
768
|
+
chunkGraph,
|
|
769
|
+
request,
|
|
770
|
+
weak,
|
|
771
|
+
runtimeRequirements
|
|
772
|
+
});
|
|
773
|
+
appending = `.then(${this.basicFunction(
|
|
774
|
+
"",
|
|
775
|
+
`${header}return ${rawModule};`
|
|
776
|
+
)})`;
|
|
777
|
+
} else {
|
|
778
|
+
runtimeRequirements.add(RuntimeGlobals.require);
|
|
779
|
+
appending = `.then(${RuntimeGlobals.require}.bind(${RuntimeGlobals.require}, ${comment}${idExpr}))`;
|
|
780
|
+
}
|
|
781
|
+
appending += `.then(${this.returningFunction(
|
|
782
|
+
`${RuntimeGlobals.createFakeNamespaceObject}(m, ${fakeType})`,
|
|
783
|
+
"m"
|
|
750
784
|
)})`;
|
|
751
785
|
} else {
|
|
752
|
-
|
|
786
|
+
fakeType |= 1;
|
|
787
|
+
if (header) {
|
|
788
|
+
const moduleIdExpr = this.moduleId({
|
|
789
|
+
module,
|
|
790
|
+
chunkGraph,
|
|
791
|
+
request,
|
|
792
|
+
weak
|
|
793
|
+
});
|
|
794
|
+
const returnExpression = `${RuntimeGlobals.createFakeNamespaceObject}(${moduleIdExpr}, ${fakeType})`;
|
|
795
|
+
appending = `.then(${this.basicFunction(
|
|
796
|
+
"",
|
|
797
|
+
`${header}return ${returnExpression};`
|
|
798
|
+
)})`;
|
|
799
|
+
} else {
|
|
800
|
+
appending = `.then(${RuntimeGlobals.createFakeNamespaceObject}.bind(${RuntimeGlobals.require}, ${comment}${idExpr}, ${fakeType}))`;
|
|
801
|
+
}
|
|
753
802
|
}
|
|
754
|
-
|
|
755
|
-
|
|
803
|
+
break;
|
|
804
|
+
}
|
|
756
805
|
}
|
|
757
806
|
|
|
758
807
|
return `${promise || "Promise.resolve()"}${appending}`;
|
|
@@ -806,7 +855,7 @@ class RuntimeTemplate {
|
|
|
806
855
|
* @param {Module} options.originModule module in which the statement is emitted
|
|
807
856
|
* @param {boolean=} options.weak true, if this is a weak dependency
|
|
808
857
|
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
|
809
|
-
* @param {
|
|
858
|
+
* @param {ModuleDependency} options.dependency module dependency
|
|
810
859
|
* @returns {[string, string]} the import statement and the compat statement
|
|
811
860
|
*/
|
|
812
861
|
importStatement({
|
|
@@ -818,7 +867,7 @@ class RuntimeTemplate {
|
|
|
818
867
|
importVar,
|
|
819
868
|
originModule,
|
|
820
869
|
weak,
|
|
821
|
-
|
|
870
|
+
dependency,
|
|
822
871
|
runtimeRequirements
|
|
823
872
|
}) {
|
|
824
873
|
if (!module) {
|
|
@@ -866,15 +915,22 @@ class RuntimeTemplate {
|
|
|
866
915
|
);
|
|
867
916
|
runtimeRequirements.add(RuntimeGlobals.require);
|
|
868
917
|
let importContent;
|
|
869
|
-
|
|
918
|
+
|
|
919
|
+
const isModuleDeferred =
|
|
920
|
+
(dependency instanceof getHarmonyImportDependency() ||
|
|
921
|
+
dependency instanceof getImportDependency()) &&
|
|
922
|
+
ImportPhaseUtils.isDefer(dependency.phase) &&
|
|
923
|
+
!(/** @type {BuildMeta} */ (module.buildMeta).async);
|
|
924
|
+
|
|
925
|
+
if (isModuleDeferred) {
|
|
870
926
|
/** @type {Set<Module>} */
|
|
871
927
|
const outgoingAsyncModules = getOutgoingAsyncModules(moduleGraph, module);
|
|
872
928
|
|
|
873
929
|
importContent = `/* deferred harmony import */ ${optDeclaration}${importVar} = ${getOptimizedDeferredModule(
|
|
874
|
-
this,
|
|
875
|
-
exportsType,
|
|
876
930
|
moduleId,
|
|
877
|
-
|
|
931
|
+
exportsType,
|
|
932
|
+
Array.from(outgoingAsyncModules, (mod) => chunkGraph.getModuleId(mod)),
|
|
933
|
+
runtimeRequirements
|
|
878
934
|
)};\n`;
|
|
879
935
|
|
|
880
936
|
return [importContent, ""];
|
|
@@ -908,7 +964,7 @@ class RuntimeTemplate {
|
|
|
908
964
|
* @param {InitFragment<GenerateContext>[]} options.initFragments init fragments will be added here
|
|
909
965
|
* @param {RuntimeSpec} options.runtime runtime for which this code will be generated
|
|
910
966
|
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
|
911
|
-
* @param {
|
|
967
|
+
* @param {ModuleDependency} options.dependency module dependency
|
|
912
968
|
* @returns {string} expression
|
|
913
969
|
*/
|
|
914
970
|
exportFromImport({
|
|
@@ -926,7 +982,7 @@ class RuntimeTemplate {
|
|
|
926
982
|
initFragments,
|
|
927
983
|
runtime,
|
|
928
984
|
runtimeRequirements,
|
|
929
|
-
|
|
985
|
+
dependency
|
|
930
986
|
}) {
|
|
931
987
|
if (!module) {
|
|
932
988
|
return this.missingModule({
|
|
@@ -942,13 +998,16 @@ class RuntimeTemplate {
|
|
|
942
998
|
(originModule.buildMeta).strictHarmonyModule
|
|
943
999
|
);
|
|
944
1000
|
|
|
945
|
-
const
|
|
946
|
-
|
|
1001
|
+
const isModuleDeferred =
|
|
1002
|
+
(dependency instanceof getHarmonyImportDependency() ||
|
|
1003
|
+
dependency instanceof getImportDependency()) &&
|
|
1004
|
+
ImportPhaseUtils.isDefer(dependency.phase) &&
|
|
1005
|
+
!(/** @type {BuildMeta} */ (module.buildMeta).async);
|
|
947
1006
|
|
|
948
1007
|
if (defaultInterop) {
|
|
949
1008
|
// when the defaultInterop is used (when a ESM imports a CJS module),
|
|
950
1009
|
if (exportName.length > 0 && exportName[0] === "default") {
|
|
951
|
-
if (
|
|
1010
|
+
if (isModuleDeferred && exportsType !== "namespace") {
|
|
952
1011
|
const exportsInfo = moduleGraph.getExportsInfo(module);
|
|
953
1012
|
const name = exportName.slice(1);
|
|
954
1013
|
const used = exportsInfo.getUsedName(name, runtime);
|
|
@@ -1002,7 +1061,7 @@ class RuntimeTemplate {
|
|
|
1002
1061
|
) {
|
|
1003
1062
|
return "/* __esModule */true";
|
|
1004
1063
|
}
|
|
1005
|
-
} else if (
|
|
1064
|
+
} else if (isModuleDeferred) {
|
|
1006
1065
|
// now exportName.length is 0
|
|
1007
1066
|
// fall through to the end of this function, create the namespace there.
|
|
1008
1067
|
} else if (
|
|
@@ -1045,7 +1104,7 @@ class RuntimeTemplate {
|
|
|
1045
1104
|
? ""
|
|
1046
1105
|
: `${Template.toNormalComment(propertyAccess(exportName))} `;
|
|
1047
1106
|
const access = `${importVar}${
|
|
1048
|
-
|
|
1107
|
+
isModuleDeferred ? ".a" : ""
|
|
1049
1108
|
}${comment}${propertyAccess(used)}`;
|
|
1050
1109
|
if (isCall && callContext === false) {
|
|
1051
1110
|
return asiSafe
|
|
@@ -1056,7 +1115,7 @@ class RuntimeTemplate {
|
|
|
1056
1115
|
}
|
|
1057
1116
|
return access;
|
|
1058
1117
|
}
|
|
1059
|
-
if (
|
|
1118
|
+
if (isModuleDeferred) {
|
|
1060
1119
|
initFragments.push(
|
|
1061
1120
|
new InitFragment(
|
|
1062
1121
|
`var ${importVar}_deferred_namespace_cache;\n`,
|
|
@@ -20,6 +20,7 @@ const { makePathsAbsolute } = require("./util/identifier");
|
|
|
20
20
|
/** @typedef {import("webpack-sources").MapOptions} MapOptions */
|
|
21
21
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
22
22
|
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
|
|
23
|
+
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").Rules} Rules */
|
|
23
24
|
/** @typedef {import("./CacheFacade").ItemCacheFacade} ItemCacheFacade */
|
|
24
25
|
/** @typedef {import("./Chunk")} Chunk */
|
|
25
26
|
/** @typedef {import("./Compilation").Asset} Asset */
|
|
@@ -433,6 +434,25 @@ class SourceMapDevToolPlugin {
|
|
|
433
434
|
moduleToSourceNameMapping.get(m)
|
|
434
435
|
);
|
|
435
436
|
sourceMap.sources = /** @type {string[]} */ (moduleFilenames);
|
|
437
|
+
sourceMap.ignoreList = options.ignoreList
|
|
438
|
+
? sourceMap.sources.reduce(
|
|
439
|
+
/** @type {(acc: number[], sourceName: string, idx: number) => number[]} */ (
|
|
440
|
+
(acc, sourceName, idx) => {
|
|
441
|
+
const rule = /** @type {Rules} */ (
|
|
442
|
+
options.ignoreList
|
|
443
|
+
);
|
|
444
|
+
if (
|
|
445
|
+
ModuleFilenameHelpers.matchPart(sourceName, rule)
|
|
446
|
+
) {
|
|
447
|
+
acc.push(idx);
|
|
448
|
+
}
|
|
449
|
+
return acc;
|
|
450
|
+
}
|
|
451
|
+
),
|
|
452
|
+
[]
|
|
453
|
+
)
|
|
454
|
+
: [];
|
|
455
|
+
|
|
436
456
|
if (options.noSources) {
|
|
437
457
|
sourceMap.sourcesContent = undefined;
|
|
438
458
|
}
|
|
@@ -18,6 +18,7 @@ const FlagDependencyExportsPlugin = require("./FlagDependencyExportsPlugin");
|
|
|
18
18
|
|
|
19
19
|
const JavascriptMetaInfoPlugin = require("./JavascriptMetaInfoPlugin");
|
|
20
20
|
|
|
21
|
+
const NodeStuffPlugin = require("./NodeStuffPlugin");
|
|
21
22
|
const OptionsApply = require("./OptionsApply");
|
|
22
23
|
|
|
23
24
|
const RecordIdsPlugin = require("./RecordIdsPlugin");
|
|
@@ -109,7 +110,15 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
109
110
|
if (options.externalsPresets.node) {
|
|
110
111
|
const NodeTargetPlugin = require("./node/NodeTargetPlugin");
|
|
111
112
|
|
|
112
|
-
|
|
113
|
+
// Some older versions of Node.js don't support all built-in modules via import, only via `require`,
|
|
114
|
+
// but шt seems like there shouldn't be a warning here since these versions are rarely used in real applications
|
|
115
|
+
new NodeTargetPlugin(
|
|
116
|
+
options.output.module &&
|
|
117
|
+
compiler.platform.node === null &&
|
|
118
|
+
compiler.platform.web === null
|
|
119
|
+
? "module-import"
|
|
120
|
+
: "node-commonjs"
|
|
121
|
+
).apply(compiler);
|
|
113
122
|
|
|
114
123
|
// Handle external CSS `@import` and `url()`
|
|
115
124
|
if (options.experiments.css) {
|
|
@@ -126,7 +135,9 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
126
135
|
if (dependencyType === "url") {
|
|
127
136
|
return callback(null, `asset ${request}`);
|
|
128
137
|
} else if (
|
|
129
|
-
dependencyType === "css-import"
|
|
138
|
+
(dependencyType === "css-import" ||
|
|
139
|
+
dependencyType === "css-import-local-module" ||
|
|
140
|
+
dependencyType === "css-import-global-module") &&
|
|
130
141
|
options.experiments.css
|
|
131
142
|
) {
|
|
132
143
|
return callback(null, `css-import ${request}`);
|
|
@@ -149,7 +160,9 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
149
160
|
if (dependencyType === "url") {
|
|
150
161
|
return callback(null, `asset ${request}`);
|
|
151
162
|
} else if (
|
|
152
|
-
dependencyType === "css-import"
|
|
163
|
+
(dependencyType === "css-import" ||
|
|
164
|
+
dependencyType === "css-import-local-module" ||
|
|
165
|
+
dependencyType === "css-import-global-module") &&
|
|
153
166
|
options.experiments.css
|
|
154
167
|
) {
|
|
155
168
|
return callback(null, `css-import ${request}`);
|
|
@@ -294,6 +307,14 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
294
307
|
).apply(compiler);
|
|
295
308
|
}
|
|
296
309
|
|
|
310
|
+
if (options.dotenv) {
|
|
311
|
+
const DotenvPlugin = require("./DotenvPlugin");
|
|
312
|
+
|
|
313
|
+
new DotenvPlugin(
|
|
314
|
+
typeof options.dotenv === "boolean" ? {} : options.dotenv
|
|
315
|
+
).apply(compiler);
|
|
316
|
+
}
|
|
317
|
+
|
|
297
318
|
if (options.devtool) {
|
|
298
319
|
if (options.devtool.includes("source-map")) {
|
|
299
320
|
const hidden = options.devtool.includes("hidden");
|
|
@@ -444,11 +465,11 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
444
465
|
}
|
|
445
466
|
new CommonJsPlugin().apply(compiler);
|
|
446
467
|
new LoaderPlugin().apply(compiler);
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
}
|
|
468
|
+
new NodeStuffPlugin({
|
|
469
|
+
global: options.node ? options.node.global : false,
|
|
470
|
+
__dirname: options.node ? options.node.__dirname : false,
|
|
471
|
+
__filename: options.node ? options.node.__filename : false
|
|
472
|
+
}).apply(compiler);
|
|
452
473
|
new APIPlugin().apply(compiler);
|
|
453
474
|
new ExportsInfoApiPlugin().apply(compiler);
|
|
454
475
|
new WebpackIsIncludedPlugin().apply(compiler);
|
|
@@ -667,8 +688,11 @@ class WebpackOptionsApply extends OptionsApply {
|
|
|
667
688
|
if (options.optimization.nodeEnv) {
|
|
668
689
|
const DefinePlugin = require("./DefinePlugin");
|
|
669
690
|
|
|
691
|
+
const defValue = JSON.stringify(options.optimization.nodeEnv);
|
|
692
|
+
|
|
670
693
|
new DefinePlugin({
|
|
671
|
-
"process.env.NODE_ENV":
|
|
694
|
+
"process.env.NODE_ENV": defValue,
|
|
695
|
+
"import.meta.env.NODE_ENV": defValue
|
|
672
696
|
}).apply(compiler);
|
|
673
697
|
}
|
|
674
698
|
if (options.optimization.minimize) {
|
|
@@ -66,7 +66,7 @@ class AssetSourceGenerator extends Generator {
|
|
|
66
66
|
} = ${RuntimeGlobals.toBinary}(${JSON.stringify(encodedSource)});`;
|
|
67
67
|
} else {
|
|
68
68
|
runtimeRequirements.add(RuntimeGlobals.module);
|
|
69
|
-
sourceContent = `${
|
|
69
|
+
sourceContent = `${module.moduleArgument}.exports = ${RuntimeGlobals.toBinary}(${JSON.stringify(
|
|
70
70
|
encodedSource
|
|
71
71
|
)});`;
|
|
72
72
|
}
|
|
@@ -380,7 +380,6 @@ class AssetGenerator extends Generator {
|
|
|
380
380
|
}
|
|
381
381
|
|
|
382
382
|
return {
|
|
383
|
-
// eslint-disable-next-line object-shorthand
|
|
384
383
|
assetPath: /** @type {string} */ (assetPath),
|
|
385
384
|
assetInfo: { sourceFilename, ...assetInfo }
|
|
386
385
|
};
|
|
@@ -614,7 +613,7 @@ class AssetGenerator extends Generator {
|
|
|
614
613
|
|
|
615
614
|
runtimeRequirements.add(RuntimeGlobals.module);
|
|
616
615
|
|
|
617
|
-
return new RawSource(`${
|
|
616
|
+
return new RawSource(`${module.moduleArgument}.exports = ${content};`);
|
|
618
617
|
} else if (type === "css-url") {
|
|
619
618
|
return null;
|
|
620
619
|
}
|