webpack 5.102.1 → 5.104.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/hot/dev-server.js +18 -3
- package/hot/emitter-event-target.js +7 -0
- package/hot/lazy-compilation-node.js +45 -29
- package/hot/lazy-compilation-universal.js +18 -0
- package/hot/lazy-compilation-web.js +15 -5
- package/hot/load-http.js +7 -0
- package/hot/only-dev-server.js +19 -4
- package/lib/APIPlugin.js +6 -0
- package/lib/Chunk.js +1 -1
- package/lib/ChunkGraph.js +9 -7
- package/lib/ChunkGroup.js +8 -5
- package/lib/CleanPlugin.js +6 -3
- package/lib/CodeGenerationResults.js +2 -1
- package/lib/CompatibilityPlugin.js +28 -2
- package/lib/Compilation.js +58 -21
- package/lib/Compiler.js +3 -3
- package/lib/ConcatenationScope.js +0 -15
- package/lib/ContextModule.js +6 -3
- package/lib/ContextModuleFactory.js +6 -4
- package/lib/CssModule.js +6 -1
- package/lib/DefinePlugin.js +45 -14
- package/lib/DelegatedModule.js +7 -4
- package/lib/Dependency.js +8 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllModule.js +6 -3
- package/lib/DotenvPlugin.js +462 -0
- package/lib/EnvironmentPlugin.js +19 -16
- package/lib/EvalSourceMapDevToolPlugin.js +16 -0
- package/lib/ExportsInfo.js +6 -2
- package/lib/ExternalModule.js +28 -35
- package/lib/ExternalModuleFactoryPlugin.js +11 -9
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +10 -7
- package/lib/HookWebpackError.js +33 -4
- package/lib/HotModuleReplacementPlugin.js +22 -0
- package/lib/ManifestPlugin.js +235 -0
- package/lib/Module.js +27 -15
- package/lib/ModuleBuildError.js +1 -1
- package/lib/ModuleError.js +1 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +29 -13
- package/lib/ModuleGraphConnection.js +2 -2
- package/lib/ModuleSourceTypeConstants.js +189 -0
- package/lib/ModuleTypeConstants.js +1 -4
- package/lib/ModuleWarning.js +1 -1
- package/lib/MultiCompiler.js +1 -1
- package/lib/NodeStuffPlugin.js +424 -116
- package/lib/NormalModule.js +23 -20
- package/lib/NormalModuleFactory.js +7 -10
- package/lib/Parser.js +1 -1
- package/lib/RawModule.js +7 -4
- package/lib/RuntimeGlobals.js +22 -4
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +27 -6
- package/lib/RuntimeTemplate.js +120 -57
- package/lib/SourceMapDevToolPlugin.js +26 -1
- package/lib/Template.js +17 -6
- package/lib/TemplatedPathPlugin.js +5 -6
- package/lib/WebpackError.js +0 -1
- package/lib/WebpackOptionsApply.js +67 -15
- package/lib/asset/AssetBytesGenerator.js +16 -12
- package/lib/asset/AssetGenerator.js +31 -26
- package/lib/asset/AssetSourceGenerator.js +16 -12
- package/lib/asset/RawDataUrlModule.js +6 -3
- package/lib/buildChunkGraph.js +4 -2
- package/lib/cache/PackFileCacheStrategy.js +6 -5
- package/lib/cli.js +2 -43
- package/lib/config/browserslistTargetHandler.js +24 -0
- package/lib/config/defaults.js +226 -61
- package/lib/config/normalization.js +4 -3
- package/lib/config/target.js +11 -0
- package/lib/container/ContainerEntryModule.js +6 -3
- package/lib/container/FallbackModule.js +6 -3
- package/lib/container/RemoteModule.js +1 -3
- package/lib/css/CssGenerator.js +304 -76
- package/lib/css/CssLoadingRuntimeModule.js +14 -4
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
- package/lib/css/CssModulesPlugin.js +72 -67
- package/lib/css/CssParser.js +1726 -732
- package/lib/css/walkCssTokens.js +128 -11
- package/lib/dependencies/CachedConstDependency.js +24 -10
- package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
- package/lib/dependencies/CommonJsPlugin.js +12 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +2 -2
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
- package/lib/dependencies/CssIcssExportDependency.js +389 -12
- package/lib/dependencies/CssIcssImportDependency.js +114 -51
- package/lib/dependencies/CssIcssSymbolDependency.js +31 -33
- package/lib/dependencies/CssImportDependency.js +17 -6
- package/lib/dependencies/CssUrlDependency.js +3 -2
- package/lib/dependencies/DynamicExports.js +7 -7
- package/lib/dependencies/ExternalModuleDependency.js +7 -4
- package/lib/dependencies/ExternalModuleInitFragment.js +3 -2
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +96 -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 +35 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -9
- package/lib/dependencies/HarmonyExports.js +4 -4
- package/lib/dependencies/HarmonyImportDependency.js +28 -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/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaPlugin.js +154 -9
- package/lib/dependencies/ImportParserPlugin.js +21 -23
- package/lib/dependencies/ImportPhase.js +121 -0
- package/lib/dependencies/ImportWeakDependency.js +6 -3
- package/lib/dependencies/LocalModulesHelpers.js +3 -3
- package/lib/dependencies/ModuleDependency.js +5 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/dependencies/getFunctionExpression.js +1 -1
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
- package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.js +5 -3
- package/lib/ids/IdHelpers.js +20 -8
- package/lib/index.js +6 -0
- package/lib/javascript/ChunkHelpers.js +16 -5
- package/lib/javascript/JavascriptGenerator.js +105 -104
- package/lib/javascript/JavascriptModulesPlugin.js +80 -37
- package/lib/javascript/JavascriptParser.js +161 -44
- package/lib/json/JsonGenerator.js +5 -4
- package/lib/json/JsonParser.js +9 -2
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/AmdLibraryPlugin.js +4 -1
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +41 -23
- package/lib/library/SystemLibraryPlugin.js +8 -1
- package/lib/library/UmdLibraryPlugin.js +2 -2
- package/lib/logging/Logger.js +5 -4
- package/lib/logging/createConsoleLogger.js +2 -2
- package/lib/node/NodeTargetPlugin.js +9 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
- package/lib/optimize/ConcatenatedModule.js +208 -167
- package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +60 -46
- package/lib/rules/RuleSetCompiler.js +1 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
- package/lib/schemes/HttpUriPlugin.js +78 -7
- package/lib/serialization/AggregateErrorSerializer.js +1 -2
- package/lib/serialization/ObjectMiddleware.js +0 -2
- package/lib/serialization/SingleItemMiddleware.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +5 -3
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +15 -9
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/util/StringXor.js +1 -1
- package/lib/util/URLAbsoluteSpecifier.js +2 -2
- package/lib/util/binarySearchBounds.js +2 -2
- package/lib/util/comparators.js +54 -76
- package/lib/util/compileBooleanMatcher.js +78 -6
- package/lib/util/createHash.js +20 -199
- package/lib/util/deprecation.js +1 -1
- package/lib/util/deterministicGrouping.js +6 -3
- package/lib/util/fs.js +75 -75
- package/lib/util/hash/BatchedHash.js +10 -9
- package/lib/util/hash/BulkUpdateHash.js +138 -0
- package/lib/util/hash/DebugHash.js +75 -0
- package/lib/util/hash/hash-digest.js +216 -0
- package/lib/util/identifier.js +82 -17
- package/lib/util/internalSerializables.js +2 -6
- package/lib/util/runtime.js +3 -3
- package/lib/util/source.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +11 -7
- package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +11 -6
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
- package/lib/web/FetchCompileWasmPlugin.js +0 -2
- package/lib/webpack.js +85 -82
- package/module.d.ts +5 -0
- package/package.json +34 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +160 -101
- package/schemas/plugins/{css/CssAutoParserOptions.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
- 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/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 +771 -436
- package/lib/ModuleSourceTypesConstants.js +0 -123
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +0 -112
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
|
@@ -9,7 +9,7 @@ const { RawSource } = require("webpack-sources");
|
|
|
9
9
|
const ConcatenationScope = require("../ConcatenationScope");
|
|
10
10
|
const { UsageState } = require("../ExportsInfo");
|
|
11
11
|
const Generator = require("../Generator");
|
|
12
|
-
const {
|
|
12
|
+
const { JAVASCRIPT_TYPES } = require("../ModuleSourceTypeConstants");
|
|
13
13
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
14
14
|
|
|
15
15
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
@@ -17,6 +17,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
|
17
17
|
/** @typedef {import("../ExportsInfo")} ExportsInfo */
|
|
18
18
|
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
|
19
19
|
/** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
|
20
|
+
/** @typedef {import("../Module").SourceType} SourceType */
|
|
20
21
|
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
|
21
22
|
/** @typedef {import("../NormalModule")} NormalModule */
|
|
22
23
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
@@ -26,7 +27,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* @param {JsonValue} data Raw JSON data
|
|
29
|
-
* @returns {undefined|string} stringified data
|
|
30
|
+
* @returns {undefined | string} stringified data
|
|
30
31
|
*/
|
|
31
32
|
const stringifySafe = (data) => {
|
|
32
33
|
const stringified = JSON.stringify(data);
|
|
@@ -132,12 +133,12 @@ class JsonGenerator extends Generator {
|
|
|
132
133
|
* @returns {SourceTypes} available types (do not mutate)
|
|
133
134
|
*/
|
|
134
135
|
getTypes(module) {
|
|
135
|
-
return
|
|
136
|
+
return JAVASCRIPT_TYPES;
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
/**
|
|
139
140
|
* @param {NormalModule} module the module
|
|
140
|
-
* @param {
|
|
141
|
+
* @param {SourceType=} type source type
|
|
141
142
|
* @returns {number} estimate size of the module
|
|
142
143
|
*/
|
|
143
144
|
getSize(module, type) {
|
package/lib/json/JsonParser.js
CHANGED
|
@@ -54,7 +54,8 @@ class JsonParser extends Parser {
|
|
|
54
54
|
: parseFn(source[0] === "\uFEFF" ? source.slice(1) : source);
|
|
55
55
|
} catch (err) {
|
|
56
56
|
throw new Error(
|
|
57
|
-
`Cannot parse JSON: ${/** @type {Error} */ (err).message}
|
|
57
|
+
`Cannot parse JSON: ${/** @type {Error} */ (err).message}`,
|
|
58
|
+
{ cause: err }
|
|
58
59
|
);
|
|
59
60
|
}
|
|
60
61
|
const jsonData = new JsonData(/** @type {Buffer | JsonValue} */ (data));
|
|
@@ -64,7 +65,13 @@ class JsonParser extends Parser {
|
|
|
64
65
|
const buildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
|
|
65
66
|
buildMeta.exportsType = "default";
|
|
66
67
|
buildMeta.defaultObject =
|
|
67
|
-
typeof data === "object"
|
|
68
|
+
typeof data === "object"
|
|
69
|
+
? this.options.namedExports === false
|
|
70
|
+
? false
|
|
71
|
+
: this.options.namedExports === true
|
|
72
|
+
? "redirect"
|
|
73
|
+
: "redirect-warn"
|
|
74
|
+
: false;
|
|
68
75
|
state.module.addDependency(
|
|
69
76
|
new JsonExportsDependency(
|
|
70
77
|
jsonData,
|
|
@@ -308,7 +308,7 @@ class AbstractLibraryPlugin {
|
|
|
308
308
|
* @param {Source} source source
|
|
309
309
|
* @param {Module} module module
|
|
310
310
|
* @param {ModuleRenderContext} renderContext render context
|
|
311
|
-
* @param {Omit<LibraryContext<T>,
|
|
311
|
+
* @param {Omit<LibraryContext<T>, "options">} libraryContext context
|
|
312
312
|
* @returns {Source} source with library export
|
|
313
313
|
*/
|
|
314
314
|
renderModuleContent(source, module, renderContext, libraryContext) {
|
|
@@ -17,7 +17,10 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
17
17
|
/** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
|
|
18
18
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
|
|
19
19
|
/** @typedef {import("../util/Hash")} Hash */
|
|
20
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* @template T
|
|
22
|
+
* @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T>
|
|
23
|
+
*/
|
|
21
24
|
|
|
22
25
|
/**
|
|
23
26
|
* @typedef {object} AmdLibraryPluginOptions
|
|
@@ -20,7 +20,10 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
20
20
|
/** @typedef {import("../Module")} Module */
|
|
21
21
|
/** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
|
|
22
22
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").StartupRenderContext} StartupRenderContext */
|
|
23
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* @template T
|
|
25
|
+
* @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T>
|
|
26
|
+
*/
|
|
24
27
|
|
|
25
28
|
/**
|
|
26
29
|
* @typedef {object} ExportPropertyLibraryPluginParsed
|
|
@@ -21,6 +21,7 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
21
21
|
/** @typedef {import("../Chunk")} Chunk */
|
|
22
22
|
/** @typedef {import("../Compiler")} Compiler */
|
|
23
23
|
/** @typedef {import("../Module")} Module */
|
|
24
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
24
25
|
/** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
|
|
25
26
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").StartupRenderContext} StartupRenderContext */
|
|
26
27
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").ModuleRenderContext} ModuleRenderContext */
|
|
@@ -69,7 +70,28 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
69
70
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
70
71
|
const { onDemandExportsGeneration } =
|
|
71
72
|
ConcatenatedModule.getCompilationHooks(compilation);
|
|
72
|
-
onDemandExportsGeneration.tap(
|
|
73
|
+
onDemandExportsGeneration.tap(
|
|
74
|
+
PLUGIN_NAME,
|
|
75
|
+
(module, runtimes, source, finalName) => {
|
|
76
|
+
/** @type {BuildMeta} */
|
|
77
|
+
const buildMeta = module.buildMeta || (module.buildMeta = {});
|
|
78
|
+
|
|
79
|
+
const exportsSourceByRuntime =
|
|
80
|
+
buildMeta.exportsSourceByRuntime ||
|
|
81
|
+
(buildMeta.exportsSourceByRuntime = new Map());
|
|
82
|
+
|
|
83
|
+
const exportsFinalNameByRuntime =
|
|
84
|
+
buildMeta.exportsFinalNameByRuntime ||
|
|
85
|
+
(buildMeta.exportsFinalNameByRuntime = new Map());
|
|
86
|
+
|
|
87
|
+
for (const runtime of runtimes) {
|
|
88
|
+
exportsSourceByRuntime.set(runtime, source);
|
|
89
|
+
exportsFinalNameByRuntime.set(runtime, finalName);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
);
|
|
73
95
|
});
|
|
74
96
|
}
|
|
75
97
|
|
|
@@ -104,16 +126,6 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
104
126
|
moduleGraph.addExtraReason(module, "used as library export");
|
|
105
127
|
}
|
|
106
128
|
|
|
107
|
-
/**
|
|
108
|
-
* @param {Chunk} chunk the chunk
|
|
109
|
-
* @param {RuntimeRequirements} set runtime requirements
|
|
110
|
-
* @param {LibraryContext<T>} libraryContext context
|
|
111
|
-
* @returns {void}
|
|
112
|
-
*/
|
|
113
|
-
runtimeRequirements(chunk, set, libraryContext) {
|
|
114
|
-
set.add(RuntimeGlobals.exports);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
129
|
/**
|
|
118
130
|
* @param {LibraryOptions} library normalized library option
|
|
119
131
|
* @returns {T | false} preprocess as needed by overriding
|
|
@@ -162,10 +174,16 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
162
174
|
)
|
|
163
175
|
]
|
|
164
176
|
: moduleGraph.getExportsInfo(module).orderedExports;
|
|
177
|
+
|
|
178
|
+
const exportsFinalNameByRuntime =
|
|
179
|
+
(module.buildMeta &&
|
|
180
|
+
module.buildMeta.exportsFinalNameByRuntime &&
|
|
181
|
+
module.buildMeta.exportsFinalNameByRuntime.get(chunk.runtime)) ||
|
|
182
|
+
{};
|
|
183
|
+
|
|
165
184
|
const definitions =
|
|
166
|
-
inlined && !inlinedInIIFE
|
|
167
|
-
|
|
168
|
-
: {};
|
|
185
|
+
inlined && !inlinedInIIFE ? exportsFinalNameByRuntime : {};
|
|
186
|
+
|
|
169
187
|
/** @type {string[]} */
|
|
170
188
|
const shortHandedExports = [];
|
|
171
189
|
/** @type {[string, string][]} */
|
|
@@ -278,23 +296,23 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
278
296
|
* @param {Source} source source
|
|
279
297
|
* @param {Module} module module
|
|
280
298
|
* @param {ModuleRenderContext} renderContext render context
|
|
281
|
-
* @param {Omit<LibraryContext<T>,
|
|
299
|
+
* @param {Omit<LibraryContext<T>, "options">} libraryContext context
|
|
282
300
|
* @returns {Source} source with library export
|
|
283
301
|
*/
|
|
284
302
|
renderModuleContent(
|
|
285
303
|
source,
|
|
286
304
|
module,
|
|
287
|
-
{ factory, inlinedInIIFE },
|
|
305
|
+
{ factory, inlinedInIIFE, chunk },
|
|
288
306
|
libraryContext
|
|
289
307
|
) {
|
|
290
|
-
|
|
291
|
-
// when the module is rendered as a factory or treated as an inlined (startup) module but wrapped in an IIFE
|
|
292
|
-
if (
|
|
293
|
-
(inlinedInIIFE || factory) &&
|
|
308
|
+
const exportsSource =
|
|
294
309
|
module.buildMeta &&
|
|
295
|
-
module.buildMeta.
|
|
296
|
-
|
|
297
|
-
|
|
310
|
+
module.buildMeta.exportsSourceByRuntime &&
|
|
311
|
+
module.buildMeta.exportsSourceByRuntime.get(chunk.runtime);
|
|
312
|
+
|
|
313
|
+
// Re-add the module's exports source when rendered in factory or as an inlined startup module wrapped in an IIFE
|
|
314
|
+
if ((inlinedInIIFE || factory) && exportsSource) {
|
|
315
|
+
return new ConcatSource(exportsSource, source);
|
|
298
316
|
}
|
|
299
317
|
return source;
|
|
300
318
|
}
|
|
@@ -19,7 +19,10 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
19
19
|
/** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
|
|
20
20
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
|
|
21
21
|
/** @typedef {import("../util/Hash")} Hash */
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* @template T
|
|
24
|
+
* @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T>
|
|
25
|
+
*/
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
* @typedef {object} SystemLibraryPluginOptions
|
|
@@ -164,6 +167,10 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
164
167
|
`Object.defineProperty(${external}, "__esModule", { value: true });`
|
|
165
168
|
);
|
|
166
169
|
}
|
|
170
|
+
// See comment above
|
|
171
|
+
instructions.push(
|
|
172
|
+
`${external}["default"] = module["default"] || module;`
|
|
173
|
+
);
|
|
167
174
|
if (handledNames.length > 0) {
|
|
168
175
|
const name = `${external}handledNames`;
|
|
169
176
|
externalVarInitialization.push(
|
|
@@ -34,7 +34,7 @@ const accessorToObjectAccess = (accessor) =>
|
|
|
34
34
|
/** @typedef {string | string[]} Accessor */
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* @param {string|undefined} base the path prefix
|
|
37
|
+
* @param {string | undefined} base the path prefix
|
|
38
38
|
* @param {Accessor} accessor the accessor
|
|
39
39
|
* @param {string=} joinWith the element separator
|
|
40
40
|
* @returns {string} the path
|
|
@@ -338,7 +338,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
338
338
|
: " var a = factory();\n"
|
|
339
339
|
} for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n` +
|
|
340
340
|
" }\n"
|
|
341
|
-
}})(${runtimeTemplate.
|
|
341
|
+
}})(${runtimeTemplate.globalObject}, ${
|
|
342
342
|
runtimeTemplate.supportsArrowFunction()
|
|
343
343
|
? `(${externalsArguments(externals)}) =>`
|
|
344
344
|
: `function(${externalsArguments(externals)})`
|
package/lib/logging/Logger.js
CHANGED
|
@@ -30,6 +30,7 @@ const LogType = Object.freeze({
|
|
|
30
30
|
module.exports.LogType = LogType;
|
|
31
31
|
|
|
32
32
|
/** @typedef {typeof LogType[keyof typeof LogType]} LogTypeEnum */
|
|
33
|
+
/** @typedef {Map<string | undefined, [number, number]>} TimersMap */
|
|
33
34
|
|
|
34
35
|
const LOG_SYMBOL = Symbol("webpack logger raw log method");
|
|
35
36
|
const TIMERS_SYMBOL = Symbol("webpack logger times");
|
|
@@ -143,7 +144,7 @@ class WebpackLogger {
|
|
|
143
144
|
* @param {string} label label
|
|
144
145
|
*/
|
|
145
146
|
time(label) {
|
|
146
|
-
/** @type {
|
|
147
|
+
/** @type {TimersMap} */
|
|
147
148
|
this[TIMERS_SYMBOL] = this[TIMERS_SYMBOL] || new Map();
|
|
148
149
|
this[TIMERS_SYMBOL].set(label, process.hrtime());
|
|
149
150
|
}
|
|
@@ -169,7 +170,7 @@ class WebpackLogger {
|
|
|
169
170
|
throw new Error(`No such label '${label}' for WebpackLogger.timeEnd()`);
|
|
170
171
|
}
|
|
171
172
|
const time = process.hrtime(prev);
|
|
172
|
-
/** @type {
|
|
173
|
+
/** @type {TimersMap} */
|
|
173
174
|
(this[TIMERS_SYMBOL]).delete(label);
|
|
174
175
|
this[LOG_SYMBOL](LogType.time, [label, ...time]);
|
|
175
176
|
}
|
|
@@ -185,9 +186,9 @@ class WebpackLogger {
|
|
|
185
186
|
);
|
|
186
187
|
}
|
|
187
188
|
const time = process.hrtime(prev);
|
|
188
|
-
/** @type {
|
|
189
|
+
/** @type {TimersMap} */
|
|
189
190
|
(this[TIMERS_SYMBOL]).delete(label);
|
|
190
|
-
/** @type {
|
|
191
|
+
/** @type {TimersMap} */
|
|
191
192
|
this[TIMERS_AGGREGATES_SYMBOL] =
|
|
192
193
|
this[TIMERS_AGGREGATES_SYMBOL] || new Map();
|
|
193
194
|
const current = this[TIMERS_AGGREGATES_SYMBOL].get(label);
|
|
@@ -35,8 +35,8 @@ const { LogType } = require("./Logger");
|
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* @typedef {object} LoggerOptions
|
|
38
|
-
* @property {false|true|"none"|"error"|"warn"|"info"|"log"|"verbose"} level loglevel
|
|
39
|
-
* @property {FilterTypes|boolean} debug filter for debug logging
|
|
38
|
+
* @property {false | true | "none" | "error" | "warn" | "info" | "log" | "verbose"} level loglevel
|
|
39
|
+
* @property {FilterTypes | boolean} debug filter for debug logging
|
|
40
40
|
* @property {LoggerConsole} console the console to log to
|
|
41
41
|
*/
|
|
42
42
|
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
const ExternalsPlugin = require("../ExternalsPlugin");
|
|
9
9
|
|
|
10
|
+
/** @typedef {import("../../declarations/WebpackOptions").ExternalsType} ExternalsType */
|
|
10
11
|
/** @typedef {import("../Compiler")} Compiler */
|
|
11
12
|
|
|
12
13
|
const builtins = [
|
|
@@ -72,13 +73,20 @@ const builtins = [
|
|
|
72
73
|
];
|
|
73
74
|
|
|
74
75
|
class NodeTargetPlugin {
|
|
76
|
+
/**
|
|
77
|
+
* @param {ExternalsType} type default external type
|
|
78
|
+
*/
|
|
79
|
+
constructor(type = "node-commonjs") {
|
|
80
|
+
this.type = type;
|
|
81
|
+
}
|
|
82
|
+
|
|
75
83
|
/**
|
|
76
84
|
* Apply the plugin
|
|
77
85
|
* @param {Compiler} compiler the compiler instance
|
|
78
86
|
* @returns {void}
|
|
79
87
|
*/
|
|
80
88
|
apply(compiler) {
|
|
81
|
-
new ExternalsPlugin(
|
|
89
|
+
new ExternalsPlugin(this.type, builtins).apply(compiler);
|
|
82
90
|
}
|
|
83
91
|
}
|
|
84
92
|
|