webpack 5.102.0 → 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/ChunkGraph.js +2 -2
- package/lib/CodeGenerationResults.js +1 -1
- package/lib/CompatibilityPlugin.js +25 -2
- package/lib/Compilation.js +30 -13
- package/lib/ConcatenationScope.js +0 -15
- package/lib/ContextModule.js +3 -1
- package/lib/CssModule.js +6 -1
- package/lib/DefinePlugin.js +12 -12
- package/lib/Dependency.js +8 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DependencyTemplates.js +1 -1
- 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/FileSystemInfo.js +9 -12
- package/lib/ManifestPlugin.js +235 -0
- package/lib/Module.js +3 -0
- package/lib/ModuleFilenameHelpers.js +1 -1
- 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 +18 -17
- package/lib/NormalModuleFactory.js +75 -4
- package/lib/RuntimeGlobals.js +22 -4
- package/lib/RuntimePlugin.js +27 -6
- package/lib/RuntimeTemplate.js +125 -57
- package/lib/SourceMapDevToolPlugin.js +26 -8
- package/lib/WebpackOptionsApply.js +33 -9
- package/lib/asset/AssetBytesGenerator.js +2 -1
- package/lib/asset/AssetGenerator.js +3 -5
- package/lib/asset/AssetSourceGenerator.js +1 -1
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/browserslistTargetHandler.js +82 -76
- package/lib/config/defaults.js +105 -20
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +7 -1
- 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 +86 -40
- package/lib/css/CssParser.js +1174 -667
- package/lib/css/walkCssTokens.js +98 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
- package/lib/dependencies/CommonJsPlugin.js +12 -0
- package/lib/dependencies/ContextElementDependency.js +2 -2
- 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 +27 -28
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
- package/lib/dependencies/ImportContextDependency.js +13 -0
- package/lib/dependencies/ImportDependency.js +10 -4
- package/lib/dependencies/ImportEagerDependency.js +6 -3
- package/lib/dependencies/ImportMetaPlugin.js +98 -10
- 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/dependencies/WorkerPlugin.js +1 -3
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
- package/lib/hmr/LazyCompilationPlugin.js +1 -0
- package/lib/ids/HashedModuleIdsPlugin.js +5 -7
- package/lib/ids/IdHelpers.js +5 -2
- 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 +25 -16
- package/lib/javascript/JavascriptParser.js +143 -39
- package/lib/json/JsonParser.js +7 -1
- package/lib/library/ModuleLibraryPlugin.js +0 -10
- package/lib/library/SystemLibraryPlugin.js +19 -5
- 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/optimize/RealContentHashPlugin.js +5 -3
- package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
- package/lib/serialization/FileMiddleware.js +1 -1
- package/lib/serialization/ObjectMiddleware.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +1 -1
- package/lib/util/Hash.js +35 -5
- package/lib/util/comparators.js +4 -3
- package/lib/util/create-schema-validation.js +1 -1
- package/lib/util/createHash.js +85 -15
- package/lib/util/hash/BatchedHash.js +47 -8
- package/lib/util/hash/wasm-hash.js +53 -13
- 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-async/AsyncWebAssemblyParser.js +0 -9
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +8 -4
- package/lib/wasm-sync/WebAssemblyParser.js +0 -9
- package/lib/web/FetchCompileWasmPlugin.js +0 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webpack.js +85 -82
- package/module.d.ts +5 -0
- package/package.json +28 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +110 -15
- package/schemas/plugins/{HashedModuleIdsPlugin.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/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/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
- package/schemas/plugins/{HashedModuleIdsPlugin.json → ids/HashedModuleIdsPlugin.json} +15 -2
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
- package/types.d.ts +788 -127
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -252
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +0 -6
|
@@ -16,12 +16,12 @@ const {
|
|
|
16
16
|
getUsedModuleIdsAndModules
|
|
17
17
|
} = require("./IdHelpers");
|
|
18
18
|
|
|
19
|
-
/** @typedef {import("../../declarations/plugins/HashedModuleIdsPlugin").HashedModuleIdsPluginOptions} HashedModuleIdsPluginOptions */
|
|
19
|
+
/** @typedef {import("../../declarations/plugins/ids/HashedModuleIdsPlugin").HashedModuleIdsPluginOptions} HashedModuleIdsPluginOptions */
|
|
20
20
|
/** @typedef {import("../Compiler")} Compiler */
|
|
21
21
|
|
|
22
22
|
const validate = createSchemaValidation(
|
|
23
|
-
require("../../schemas/plugins/HashedModuleIdsPlugin.check"),
|
|
24
|
-
() => require("../../schemas/plugins/HashedModuleIdsPlugin.json"),
|
|
23
|
+
require("../../schemas/plugins/ids/HashedModuleIdsPlugin.check"),
|
|
24
|
+
() => require("../../schemas/plugins/ids/HashedModuleIdsPlugin.json"),
|
|
25
25
|
{
|
|
26
26
|
name: "Hashed Module Ids Plugin",
|
|
27
27
|
baseDataPath: "options"
|
|
@@ -37,7 +37,7 @@ class HashedModuleIdsPlugin {
|
|
|
37
37
|
constructor(options = {}) {
|
|
38
38
|
validate(options);
|
|
39
39
|
|
|
40
|
-
/** @type {HashedModuleIdsPluginOptions} */
|
|
40
|
+
/** @type {Required<Omit<HashedModuleIdsPluginOptions, "context">> & { context?: string | undefined }} */
|
|
41
41
|
this.options = {
|
|
42
42
|
context: undefined,
|
|
43
43
|
hashFunction: DEFAULTS.HASH_FUNCTION,
|
|
@@ -73,9 +73,7 @@ class HashedModuleIdsPlugin {
|
|
|
73
73
|
)
|
|
74
74
|
);
|
|
75
75
|
hash.update(ident || "");
|
|
76
|
-
const hashId =
|
|
77
|
-
hash.digest(options.hashDigest)
|
|
78
|
-
);
|
|
76
|
+
const hashId = hash.digest(options.hashDigest);
|
|
79
77
|
let len = options.hashDigestLength;
|
|
80
78
|
while (usedIds.has(hashId.slice(0, len))) {
|
|
81
79
|
/** @type {number} */ (len)++;
|
package/lib/ids/IdHelpers.js
CHANGED
|
@@ -15,6 +15,7 @@ const numberHash = require("../util/numberHash");
|
|
|
15
15
|
/** @typedef {import("../Module")} Module */
|
|
16
16
|
/** @typedef {typeof import("../util/Hash")} Hash */
|
|
17
17
|
/** @typedef {import("../util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
|
|
18
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* @param {string} str string to hash
|
|
@@ -25,7 +26,7 @@ const numberHash = require("../util/numberHash");
|
|
|
25
26
|
const getHash = (str, len, hashFunction) => {
|
|
26
27
|
const hash = createHash(hashFunction);
|
|
27
28
|
hash.update(str);
|
|
28
|
-
const digest =
|
|
29
|
+
const digest = hash.digest("hex");
|
|
29
30
|
return digest.slice(0, len);
|
|
30
31
|
};
|
|
31
32
|
|
|
@@ -246,7 +247,9 @@ const getUsedModuleIdsAndModules = (compilation, filter) => {
|
|
|
246
247
|
usedIds.add(String(moduleId));
|
|
247
248
|
} else if (
|
|
248
249
|
(!filter || filter(module)) &&
|
|
249
|
-
chunkGraph.getNumberOfModuleChunks(module) !== 0
|
|
250
|
+
(chunkGraph.getNumberOfModuleChunks(module) !== 0 ||
|
|
251
|
+
// CSS modules need IDs even when not in chunks, for generating CSS class names(i.e. [id]-[local])
|
|
252
|
+
/** @type {BuildMeta} */ (module.buildMeta).isCSSModule)
|
|
250
253
|
) {
|
|
251
254
|
modules.push(module);
|
|
252
255
|
}
|
package/lib/index.js
CHANGED
|
@@ -232,6 +232,9 @@ module.exports = mergeExports(fn, {
|
|
|
232
232
|
get DynamicEntryPlugin() {
|
|
233
233
|
return require("./DynamicEntryPlugin");
|
|
234
234
|
},
|
|
235
|
+
get DotenvPlugin() {
|
|
236
|
+
return require("./DotenvPlugin");
|
|
237
|
+
},
|
|
235
238
|
get EntryOptionPlugin() {
|
|
236
239
|
return require("./EntryOptionPlugin");
|
|
237
240
|
},
|
|
@@ -355,6 +358,9 @@ module.exports = mergeExports(fn, {
|
|
|
355
358
|
get Stats() {
|
|
356
359
|
return require("./Stats");
|
|
357
360
|
},
|
|
361
|
+
get ManifestPlugin() {
|
|
362
|
+
return require("./ManifestPlugin");
|
|
363
|
+
},
|
|
358
364
|
get Template() {
|
|
359
365
|
return require("./Template");
|
|
360
366
|
},
|
|
@@ -16,17 +16,28 @@ const Entrypoint = require("../Entrypoint");
|
|
|
16
16
|
* @returns {Set<Chunk>} chunks
|
|
17
17
|
*/
|
|
18
18
|
const getAllChunks = (entrypoint, excludedChunk1, excludedChunk2) => {
|
|
19
|
+
/** @type {Set<Entrypoint>} */
|
|
19
20
|
const queue = new Set([entrypoint]);
|
|
21
|
+
/** @type {Set<Entrypoint>} */
|
|
22
|
+
const groups = new Set([]);
|
|
23
|
+
for (const group of queue) {
|
|
24
|
+
if (group !== entrypoint) {
|
|
25
|
+
groups.add(group);
|
|
26
|
+
}
|
|
27
|
+
for (const parent of group.parentsIterable) {
|
|
28
|
+
if (parent instanceof Entrypoint) queue.add(parent);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
groups.add(entrypoint);
|
|
32
|
+
|
|
33
|
+
/** @type {Set<Chunk>} */
|
|
20
34
|
const chunks = new Set();
|
|
21
|
-
for (const
|
|
22
|
-
for (const chunk of
|
|
35
|
+
for (const group of groups) {
|
|
36
|
+
for (const chunk of group.chunks) {
|
|
23
37
|
if (chunk === excludedChunk1) continue;
|
|
24
38
|
if (chunk === excludedChunk2) continue;
|
|
25
39
|
chunks.add(chunk);
|
|
26
40
|
}
|
|
27
|
-
for (const parent of entrypoint.parentsIterable) {
|
|
28
|
-
if (parent instanceof Entrypoint) queue.add(parent);
|
|
29
|
-
}
|
|
30
41
|
}
|
|
31
42
|
return chunks;
|
|
32
43
|
};
|
|
@@ -101,107 +101,6 @@ class JavascriptGenerator extends Generator {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
/**
|
|
105
|
-
* @param {NormalModule} module module for which the code should be generated
|
|
106
|
-
* @param {GenerateContext} generateContext context for generate
|
|
107
|
-
* @returns {Source | null} generated code
|
|
108
|
-
*/
|
|
109
|
-
generate(module, generateContext) {
|
|
110
|
-
const originalSource = module.originalSource();
|
|
111
|
-
if (!originalSource) {
|
|
112
|
-
return DEFAULT_SOURCE.source();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const source = new ReplaceSource(originalSource);
|
|
116
|
-
/** @type {InitFragment<GenerateContext>[]} */
|
|
117
|
-
const initFragments = [];
|
|
118
|
-
|
|
119
|
-
this.sourceModule(module, initFragments, source, generateContext);
|
|
120
|
-
|
|
121
|
-
return InitFragment.addToSource(source, initFragments, generateContext);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* @param {Error} error the error
|
|
126
|
-
* @param {NormalModule} module module for which the code should be generated
|
|
127
|
-
* @param {GenerateContext} generateContext context for generate
|
|
128
|
-
* @returns {Source | null} generated code
|
|
129
|
-
*/
|
|
130
|
-
generateError(error, module, generateContext) {
|
|
131
|
-
return new RawSource(`throw new Error(${JSON.stringify(error.message)});`);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* @param {Module} module the module to generate
|
|
136
|
-
* @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
|
|
137
|
-
* @param {ReplaceSource} source the current replace source which can be modified
|
|
138
|
-
* @param {GenerateContext} generateContext the generateContext
|
|
139
|
-
* @returns {void}
|
|
140
|
-
*/
|
|
141
|
-
sourceModule(module, initFragments, source, generateContext) {
|
|
142
|
-
for (const dependency of module.dependencies) {
|
|
143
|
-
this.sourceDependency(
|
|
144
|
-
module,
|
|
145
|
-
dependency,
|
|
146
|
-
initFragments,
|
|
147
|
-
source,
|
|
148
|
-
generateContext
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (module.presentationalDependencies !== undefined) {
|
|
153
|
-
for (const dependency of module.presentationalDependencies) {
|
|
154
|
-
this.sourceDependency(
|
|
155
|
-
module,
|
|
156
|
-
dependency,
|
|
157
|
-
initFragments,
|
|
158
|
-
source,
|
|
159
|
-
generateContext
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
for (const childBlock of module.blocks) {
|
|
165
|
-
this.sourceBlock(
|
|
166
|
-
module,
|
|
167
|
-
childBlock,
|
|
168
|
-
initFragments,
|
|
169
|
-
source,
|
|
170
|
-
generateContext
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* @param {Module} module the module to generate
|
|
177
|
-
* @param {DependenciesBlock} block the dependencies block which will be processed
|
|
178
|
-
* @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
|
|
179
|
-
* @param {ReplaceSource} source the current replace source which can be modified
|
|
180
|
-
* @param {GenerateContext} generateContext the generateContext
|
|
181
|
-
* @returns {void}
|
|
182
|
-
*/
|
|
183
|
-
sourceBlock(module, block, initFragments, source, generateContext) {
|
|
184
|
-
for (const dependency of block.dependencies) {
|
|
185
|
-
this.sourceDependency(
|
|
186
|
-
module,
|
|
187
|
-
dependency,
|
|
188
|
-
initFragments,
|
|
189
|
-
source,
|
|
190
|
-
generateContext
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
for (const childBlock of block.blocks) {
|
|
195
|
-
this.sourceBlock(
|
|
196
|
-
module,
|
|
197
|
-
childBlock,
|
|
198
|
-
initFragments,
|
|
199
|
-
source,
|
|
200
|
-
generateContext
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
104
|
/**
|
|
206
105
|
* @param {Module} module the current module
|
|
207
106
|
* @param {Dependency} dependency the dependency to generate
|
|
@@ -271,6 +170,107 @@ class JavascriptGenerator extends Generator {
|
|
|
271
170
|
}
|
|
272
171
|
}
|
|
273
172
|
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @param {Module} module the module to generate
|
|
176
|
+
* @param {DependenciesBlock} block the dependencies block which will be processed
|
|
177
|
+
* @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
|
|
178
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
|
179
|
+
* @param {GenerateContext} generateContext the generateContext
|
|
180
|
+
* @returns {void}
|
|
181
|
+
*/
|
|
182
|
+
sourceBlock(module, block, initFragments, source, generateContext) {
|
|
183
|
+
for (const dependency of block.dependencies) {
|
|
184
|
+
this.sourceDependency(
|
|
185
|
+
module,
|
|
186
|
+
dependency,
|
|
187
|
+
initFragments,
|
|
188
|
+
source,
|
|
189
|
+
generateContext
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
for (const childBlock of block.blocks) {
|
|
194
|
+
this.sourceBlock(
|
|
195
|
+
module,
|
|
196
|
+
childBlock,
|
|
197
|
+
initFragments,
|
|
198
|
+
source,
|
|
199
|
+
generateContext
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @param {Module} module the module to generate
|
|
206
|
+
* @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments
|
|
207
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
|
208
|
+
* @param {GenerateContext} generateContext the generateContext
|
|
209
|
+
* @returns {void}
|
|
210
|
+
*/
|
|
211
|
+
sourceModule(module, initFragments, source, generateContext) {
|
|
212
|
+
for (const dependency of module.dependencies) {
|
|
213
|
+
this.sourceDependency(
|
|
214
|
+
module,
|
|
215
|
+
dependency,
|
|
216
|
+
initFragments,
|
|
217
|
+
source,
|
|
218
|
+
generateContext
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (module.presentationalDependencies !== undefined) {
|
|
223
|
+
for (const dependency of module.presentationalDependencies) {
|
|
224
|
+
this.sourceDependency(
|
|
225
|
+
module,
|
|
226
|
+
dependency,
|
|
227
|
+
initFragments,
|
|
228
|
+
source,
|
|
229
|
+
generateContext
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
for (const childBlock of module.blocks) {
|
|
235
|
+
this.sourceBlock(
|
|
236
|
+
module,
|
|
237
|
+
childBlock,
|
|
238
|
+
initFragments,
|
|
239
|
+
source,
|
|
240
|
+
generateContext
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* @param {NormalModule} module module for which the code should be generated
|
|
247
|
+
* @param {GenerateContext} generateContext context for generate
|
|
248
|
+
* @returns {Source | null} generated code
|
|
249
|
+
*/
|
|
250
|
+
generate(module, generateContext) {
|
|
251
|
+
const originalSource = module.originalSource();
|
|
252
|
+
if (!originalSource) {
|
|
253
|
+
return DEFAULT_SOURCE.source();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const source = new ReplaceSource(originalSource);
|
|
257
|
+
/** @type {InitFragment<GenerateContext>[]} */
|
|
258
|
+
const initFragments = [];
|
|
259
|
+
|
|
260
|
+
this.sourceModule(module, initFragments, source, generateContext);
|
|
261
|
+
|
|
262
|
+
return InitFragment.addToSource(source, initFragments, generateContext);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* @param {Error} error the error
|
|
267
|
+
* @param {NormalModule} module module for which the code should be generated
|
|
268
|
+
* @param {GenerateContext} generateContext context for generate
|
|
269
|
+
* @returns {Source | null} generated code
|
|
270
|
+
*/
|
|
271
|
+
generateError(error, module, generateContext) {
|
|
272
|
+
return new RawSource(`throw new Error(${JSON.stringify(error.message)});`);
|
|
273
|
+
}
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
module.exports = JavascriptGenerator;
|
|
@@ -298,16 +298,20 @@ class JavascriptModulesPlugin {
|
|
|
298
298
|
]) {
|
|
299
299
|
normalModuleFactory.hooks.createParser
|
|
300
300
|
.for(type)
|
|
301
|
-
.tap(PLUGIN_NAME, (
|
|
301
|
+
.tap(PLUGIN_NAME, (options) => {
|
|
302
302
|
switch (type) {
|
|
303
303
|
case JAVASCRIPT_MODULE_TYPE_AUTO: {
|
|
304
|
-
return new JavascriptParser("auto");
|
|
304
|
+
return new JavascriptParser("auto", { parse: options.parse });
|
|
305
305
|
}
|
|
306
306
|
case JAVASCRIPT_MODULE_TYPE_DYNAMIC: {
|
|
307
|
-
return new JavascriptParser("script"
|
|
307
|
+
return new JavascriptParser("script", {
|
|
308
|
+
parse: options.parse
|
|
309
|
+
});
|
|
308
310
|
}
|
|
309
311
|
case JAVASCRIPT_MODULE_TYPE_ESM: {
|
|
310
|
-
return new JavascriptParser("module"
|
|
312
|
+
return new JavascriptParser("module", {
|
|
313
|
+
parse: options.parse
|
|
314
|
+
});
|
|
311
315
|
}
|
|
312
316
|
}
|
|
313
317
|
});
|
|
@@ -503,11 +507,10 @@ class JavascriptModulesPlugin {
|
|
|
503
507
|
}
|
|
504
508
|
xor.updateHash(hash);
|
|
505
509
|
}
|
|
506
|
-
const digest =
|
|
510
|
+
const digest = hash.digest(hashDigest);
|
|
507
511
|
chunk.contentHash.javascript = nonNumericOnlyHash(
|
|
508
512
|
digest,
|
|
509
|
-
|
|
510
|
-
(hashDigestLength)
|
|
513
|
+
hashDigestLength
|
|
511
514
|
);
|
|
512
515
|
});
|
|
513
516
|
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
|
@@ -951,7 +954,8 @@ class JavascriptModulesPlugin {
|
|
|
951
954
|
let inlinedInIIFE = false;
|
|
952
955
|
|
|
953
956
|
if (avoidEntryIife) {
|
|
954
|
-
renamedInlinedModule = this.
|
|
957
|
+
renamedInlinedModule = this._getRenamedInlineModule(
|
|
958
|
+
compilation,
|
|
955
959
|
allModules,
|
|
956
960
|
renderContext,
|
|
957
961
|
inlinedModules,
|
|
@@ -1585,10 +1589,7 @@ class JavascriptModulesPlugin {
|
|
|
1585
1589
|
"// Execute the module function",
|
|
1586
1590
|
moduleExecution,
|
|
1587
1591
|
...(needModuleDefer
|
|
1588
|
-
? [
|
|
1589
|
-
"// delete __webpack_module_deferred_exports__[module];",
|
|
1590
|
-
"// skipped because strictModuleErrorHandling is not enabled."
|
|
1591
|
-
]
|
|
1592
|
+
? ["delete __webpack_module_deferred_exports__[moduleId];"]
|
|
1592
1593
|
: [])
|
|
1593
1594
|
]),
|
|
1594
1595
|
needModuleLoaded
|
|
@@ -1609,6 +1610,7 @@ class JavascriptModulesPlugin {
|
|
|
1609
1610
|
}
|
|
1610
1611
|
|
|
1611
1612
|
/**
|
|
1613
|
+
* @param {Compilation} compilation compilation
|
|
1612
1614
|
* @param {Module[]} allModules allModules
|
|
1613
1615
|
* @param {MainRenderContext} renderContext renderContext
|
|
1614
1616
|
* @param {Set<Module>} inlinedModules inlinedModules
|
|
@@ -1618,7 +1620,8 @@ class JavascriptModulesPlugin {
|
|
|
1618
1620
|
* @param {boolean} hasChunkModules hasChunkModules
|
|
1619
1621
|
* @returns {Map<Module, Source> | false} renamed inlined modules
|
|
1620
1622
|
*/
|
|
1621
|
-
|
|
1623
|
+
_getRenamedInlineModule(
|
|
1624
|
+
compilation,
|
|
1622
1625
|
allModules,
|
|
1623
1626
|
renderContext,
|
|
1624
1627
|
inlinedModules,
|
|
@@ -1665,9 +1668,15 @@ class JavascriptModulesPlugin {
|
|
|
1665
1668
|
|
|
1666
1669
|
if (!moduleSource) continue;
|
|
1667
1670
|
const code = /** @type {string} */ (moduleSource.source());
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
+
|
|
1672
|
+
const { ast } = JavascriptParser._parse(
|
|
1673
|
+
code,
|
|
1674
|
+
{
|
|
1675
|
+
sourceType: "auto",
|
|
1676
|
+
ranges: true
|
|
1677
|
+
},
|
|
1678
|
+
JavascriptParser._getModuleParseFunction(compilation, m)
|
|
1679
|
+
);
|
|
1671
1680
|
|
|
1672
1681
|
const scopeManager = eslintScope.analyze(ast, {
|
|
1673
1682
|
ecmaVersion: 6,
|