webpack 5.101.0 → 5.101.2
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/lib/ChunkGraph.js +54 -0
- package/lib/Compilation.js +25 -8
- package/lib/Dependency.js +2 -1
- package/lib/Entrypoint.js +19 -0
- package/lib/GraphHelpers.js +11 -0
- package/lib/JavascriptMetaInfoPlugin.js +1 -2
- package/lib/Module.js +2 -1
- package/lib/ModuleGraph.js +22 -41
- package/lib/ModuleTemplate.js +3 -2
- package/lib/Watching.js +0 -2
- package/lib/dependencies/HarmonyAcceptDependency.js +54 -2
- package/lib/dependencies/JsonExportsDependency.js +6 -1
- package/lib/dependencies/ModuleDependency.js +2 -1
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +8 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +30 -64
- package/lib/esm/ModuleChunkLoadingPlugin.js +1 -4
- package/lib/index.js +8 -0
- package/lib/javascript/ChunkFormatHelpers.js +70 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +9 -20
- package/lib/javascript/JavascriptModulesPlugin.js +93 -39
- package/lib/javascript/JavascriptParser.js +160 -54
- package/lib/library/AbstractLibraryPlugin.js +27 -0
- package/lib/library/ModuleLibraryPlugin.js +46 -34
- package/lib/node/RequireChunkLoadingRuntimeModule.js +7 -2
- package/lib/optimize/ConcatenatedModule.js +27 -26
- package/lib/optimize/InnerGraph.js +7 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
- package/lib/serialization/FileMiddleware.js +1 -0
- package/lib/util/fs.js +1 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
- package/package.json +4 -4
- package/types.d.ts +187 -25
|
@@ -8,13 +8,16 @@
|
|
|
8
8
|
const { ConcatSource } = require("webpack-sources");
|
|
9
9
|
const { HotUpdateChunk, RuntimeGlobals } = require("..");
|
|
10
10
|
const Template = require("../Template");
|
|
11
|
+
const {
|
|
12
|
+
createChunkHashHandler,
|
|
13
|
+
getChunkInfo
|
|
14
|
+
} = require("../javascript/ChunkFormatHelpers");
|
|
11
15
|
const { getAllChunks } = require("../javascript/ChunkHelpers");
|
|
12
16
|
const {
|
|
13
17
|
chunkHasJs,
|
|
14
18
|
getChunkFilenameTemplate,
|
|
15
19
|
getCompilationHooks
|
|
16
20
|
} = require("../javascript/JavascriptModulesPlugin");
|
|
17
|
-
const { updateHashForEntryStartup } = require("../javascript/StartupHelpers");
|
|
18
21
|
const { getUndoPath } = require("../util/identifier");
|
|
19
22
|
|
|
20
23
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
@@ -27,28 +30,6 @@ const { getUndoPath } = require("../util/identifier");
|
|
|
27
30
|
/** @typedef {import("../Module")} Module */
|
|
28
31
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
|
|
29
32
|
|
|
30
|
-
/**
|
|
31
|
-
* Gets information about a chunk including its entries and runtime chunk
|
|
32
|
-
* @param {Chunk} chunk The chunk to get information for
|
|
33
|
-
* @param {ChunkGraph} chunkGraph The chunk graph containing the chunk
|
|
34
|
-
* @returns {{entries: Array<[Module, Entrypoint | undefined]>, runtimeChunk: Chunk|null}} Object containing chunk entries and runtime chunk
|
|
35
|
-
*/
|
|
36
|
-
function getChunkInfo(chunk, chunkGraph) {
|
|
37
|
-
const entries = [
|
|
38
|
-
...chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)
|
|
39
|
-
];
|
|
40
|
-
const runtimeChunk =
|
|
41
|
-
entries.length > 0
|
|
42
|
-
? /** @type {Entrypoint[][]} */
|
|
43
|
-
(entries)[0][1].getRuntimeChunk()
|
|
44
|
-
: null;
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
entries,
|
|
48
|
-
runtimeChunk
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
33
|
/**
|
|
53
34
|
* @param {Compilation} compilation the compilation instance
|
|
54
35
|
* @param {Chunk} chunk the chunk
|
|
@@ -97,7 +78,7 @@ const getRelativePath = (compilation, chunk, runtimeChunk) => {
|
|
|
97
78
|
* @returns {string} the import source
|
|
98
79
|
*/
|
|
99
80
|
function renderChunkImport(compilation, chunk, namedImport, runtimeChunk) {
|
|
100
|
-
return `import ${namedImport ? `* as ${namedImport}` : RuntimeGlobals.require} from ${JSON.stringify(
|
|
81
|
+
return `import ${namedImport ? `* as ${namedImport}` : `{ ${RuntimeGlobals.require} }`} from ${JSON.stringify(
|
|
101
82
|
getRelativePath(compilation, chunk, runtimeChunk || chunk)
|
|
102
83
|
)};\n`;
|
|
103
84
|
}
|
|
@@ -168,27 +149,30 @@ class ModuleChunkFormatPlugin {
|
|
|
168
149
|
PLUGIN_NAME,
|
|
169
150
|
(modules, _lastModule, renderContext) => {
|
|
170
151
|
const { chunk, chunkGraph } = renderContext;
|
|
171
|
-
if (
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
152
|
+
if (
|
|
153
|
+
chunkGraph.getNumberOfEntryModules(chunk) > 0 &&
|
|
154
|
+
chunk.hasRuntime()
|
|
155
|
+
) {
|
|
156
|
+
const entryDependentChunks =
|
|
157
|
+
chunkGraph.getChunkEntryDependentChunksIterable(chunk);
|
|
158
|
+
const sourceWithDependentChunks = withDependentChunks(
|
|
159
|
+
/** @type {Set<Chunk>} */ (entryDependentChunks),
|
|
160
|
+
chunkGraph,
|
|
161
|
+
chunk
|
|
162
|
+
);
|
|
163
|
+
if (!sourceWithDependentChunks) {
|
|
164
|
+
return modules;
|
|
165
|
+
}
|
|
166
|
+
if (modules.size() === 0) {
|
|
167
|
+
return sourceWithDependentChunks;
|
|
168
|
+
}
|
|
169
|
+
const source = new ConcatSource();
|
|
170
|
+
source.add(sourceWithDependentChunks);
|
|
171
|
+
source.add("\n");
|
|
172
|
+
source.add(modules);
|
|
173
|
+
return source;
|
|
186
174
|
}
|
|
187
|
-
|
|
188
|
-
source.add(sourceWithDependentChunks);
|
|
189
|
-
source.add("\n");
|
|
190
|
-
source.add(modules);
|
|
191
|
-
return source;
|
|
175
|
+
return modules;
|
|
192
176
|
}
|
|
193
177
|
);
|
|
194
178
|
hooks.renderChunk.tap(PLUGIN_NAME, (modules, renderContext) => {
|
|
@@ -238,9 +222,6 @@ class ModuleChunkFormatPlugin {
|
|
|
238
222
|
}
|
|
239
223
|
const final = i + 1 === entries.length;
|
|
240
224
|
const moduleId = chunkGraph.getModuleId(module);
|
|
241
|
-
const entryDependentChunks = /** @type {Set<Chunk>} */ (
|
|
242
|
-
chunkGraph.getChunkEntryDependentChunksIterable(chunk)
|
|
243
|
-
);
|
|
244
225
|
const chunks = getAllChunks(
|
|
245
226
|
/** @type {Entrypoint} */ (entrypoint),
|
|
246
227
|
/** @type {Chunk} */ (runtimeChunk),
|
|
@@ -248,10 +229,7 @@ class ModuleChunkFormatPlugin {
|
|
|
248
229
|
);
|
|
249
230
|
const processChunks = new Set();
|
|
250
231
|
for (const _chunk of chunks) {
|
|
251
|
-
if (
|
|
252
|
-
loadedChunks.has(_chunk) ||
|
|
253
|
-
entryDependentChunks.has(_chunk)
|
|
254
|
-
) {
|
|
232
|
+
if (loadedChunks.has(_chunk)) {
|
|
255
233
|
continue;
|
|
256
234
|
}
|
|
257
235
|
loadedChunks.add(_chunk);
|
|
@@ -287,19 +265,7 @@ class ModuleChunkFormatPlugin {
|
|
|
287
265
|
}
|
|
288
266
|
return source;
|
|
289
267
|
});
|
|
290
|
-
hooks.chunkHash.tap(PLUGIN_NAME, (
|
|
291
|
-
if (chunk.hasRuntime()) return;
|
|
292
|
-
const { entries, runtimeChunk } = getChunkInfo(chunk, chunkGraph);
|
|
293
|
-
hash.update(PLUGIN_NAME);
|
|
294
|
-
hash.update("1");
|
|
295
|
-
if (runtimeChunk && runtimeChunk.hash) {
|
|
296
|
-
// Any change to runtimeChunk should trigger a hash update,
|
|
297
|
-
// we shouldn't depend on or inspect its internal implementation.
|
|
298
|
-
// import __webpack_require__ from "./runtime-main.e9400aee33633a3973bd.js";
|
|
299
|
-
hash.update(runtimeChunk.hash);
|
|
300
|
-
}
|
|
301
|
-
updateHashForEntryStartup(hash, chunkGraph, entries, chunk);
|
|
302
|
-
});
|
|
268
|
+
hooks.chunkHash.tap(PLUGIN_NAME, createChunkHashHandler(PLUGIN_NAME));
|
|
303
269
|
});
|
|
304
270
|
}
|
|
305
271
|
}
|
|
@@ -71,11 +71,8 @@ class ModuleChunkLoadingPlugin {
|
|
|
71
71
|
.tap(PLUGIN_NAME, handler);
|
|
72
72
|
compilation.hooks.runtimeRequirementInTree
|
|
73
73
|
.for(RuntimeGlobals.externalInstallChunk)
|
|
74
|
-
.tap(PLUGIN_NAME, (chunk
|
|
74
|
+
.tap(PLUGIN_NAME, (chunk) => {
|
|
75
75
|
if (!isEnabledForChunk(chunk)) return;
|
|
76
|
-
// If a chunk contains an entryModule, all exports are determined by the entryModule.
|
|
77
|
-
// The ExportWebpackRequireRuntimeModule is for internal use only and not exposed to users.
|
|
78
|
-
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) return;
|
|
79
76
|
compilation.addRuntimeModule(
|
|
80
77
|
chunk,
|
|
81
78
|
new ExportWebpackRequireRuntimeModule()
|
package/lib/index.js
CHANGED
|
@@ -56,6 +56,9 @@ const memoize = require("./util/memoize");
|
|
|
56
56
|
/** @typedef {import("./Parser").ParserState} ParserState */
|
|
57
57
|
/** @typedef {import("./ResolverFactory").ResolvePluginInstance} ResolvePluginInstance */
|
|
58
58
|
/** @typedef {import("./ResolverFactory").Resolver} Resolver */
|
|
59
|
+
/** @typedef {import("./Template").RenderManifestEntry} RenderManifestEntry */
|
|
60
|
+
/** @typedef {import("./Template").RenderManifestOptions} RenderManifestOptions */
|
|
61
|
+
/** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
|
|
59
62
|
/** @typedef {import("./Watching")} Watching */
|
|
60
63
|
/** @typedef {import("./cli").Argument} Argument */
|
|
61
64
|
/** @typedef {import("./cli").Problem} Problem */
|
|
@@ -75,6 +78,8 @@ const memoize = require("./util/memoize");
|
|
|
75
78
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleTraceDependency} StatsModuleTraceDependency */
|
|
76
79
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModuleTraceItem} StatsModuleTraceItem */
|
|
77
80
|
/** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsProfile} StatsProfile */
|
|
81
|
+
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|
82
|
+
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
78
83
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
|
79
84
|
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
|
80
85
|
|
|
@@ -288,6 +293,9 @@ module.exports = mergeExports(fn, {
|
|
|
288
293
|
get Module() {
|
|
289
294
|
return require("./Module");
|
|
290
295
|
},
|
|
296
|
+
get ModuleFactory() {
|
|
297
|
+
return require("./ModuleFactory");
|
|
298
|
+
},
|
|
291
299
|
get ModuleFilenameHelpers() {
|
|
292
300
|
return require("./ModuleFilenameHelpers");
|
|
293
301
|
},
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Natsu @xiaoxiaojx
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const { updateHashForEntryStartup } = require("./StartupHelpers");
|
|
9
|
+
|
|
10
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
|
11
|
+
/** @typedef {import("../Module")} Module */
|
|
12
|
+
/** @typedef {import("../Chunk")} Chunk */
|
|
13
|
+
/** @typedef {import("../Entrypoint")} Entrypoint */
|
|
14
|
+
/** @typedef {import("../util/Hash")} Hash */
|
|
15
|
+
/** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Gets information about a chunk including its entries and runtime chunk
|
|
19
|
+
* @param {Chunk} chunk The chunk to get information for
|
|
20
|
+
* @param {ChunkGraph} chunkGraph The chunk graph containing the chunk
|
|
21
|
+
* @returns {{entries: Array<[Module, Entrypoint | undefined]>, runtimeChunk: Chunk|null}} Object containing chunk entries and runtime chunk
|
|
22
|
+
*/
|
|
23
|
+
function getChunkInfo(chunk, chunkGraph) {
|
|
24
|
+
const entries = [
|
|
25
|
+
...chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)
|
|
26
|
+
];
|
|
27
|
+
const runtimeChunk =
|
|
28
|
+
entries.length > 0
|
|
29
|
+
? /** @type {Entrypoint[][]} */
|
|
30
|
+
(entries)[0][1].getRuntimeChunk()
|
|
31
|
+
: null;
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
entries,
|
|
35
|
+
runtimeChunk
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Creates a chunk hash handler
|
|
41
|
+
* @param {string} name The name of the chunk
|
|
42
|
+
* @returns {(chunk: Chunk, hash: Hash, { chunkGraph }: ChunkHashContext) => void} The chunk hash handler
|
|
43
|
+
*/
|
|
44
|
+
function createChunkHashHandler(name) {
|
|
45
|
+
/**
|
|
46
|
+
* @param {Chunk} chunk The chunk to get information for
|
|
47
|
+
* @param {Hash} hash The hash to update
|
|
48
|
+
* @param {ChunkHashContext} chunkHashContext The chunk hash context
|
|
49
|
+
* @returns {void}
|
|
50
|
+
*/
|
|
51
|
+
return (chunk, hash, { chunkGraph }) => {
|
|
52
|
+
if (chunk.hasRuntime()) return;
|
|
53
|
+
const { entries, runtimeChunk } = getChunkInfo(chunk, chunkGraph);
|
|
54
|
+
hash.update(name);
|
|
55
|
+
hash.update("1");
|
|
56
|
+
if (runtimeChunk && runtimeChunk.hash) {
|
|
57
|
+
// https://github.com/webpack/webpack/issues/19439
|
|
58
|
+
// Any change to runtimeChunk should trigger a hash update,
|
|
59
|
+
// we shouldn't depend on or inspect its internal implementation.
|
|
60
|
+
// import __webpack_require__ from "./runtime-main.e9400aee33633a3973bd.js";
|
|
61
|
+
hash.update(runtimeChunk.hash);
|
|
62
|
+
}
|
|
63
|
+
updateHashForEntryStartup(hash, chunkGraph, entries, chunk);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = {
|
|
68
|
+
createChunkHashHandler,
|
|
69
|
+
getChunkInfo
|
|
70
|
+
};
|
|
@@ -9,14 +9,15 @@ const { ConcatSource, RawSource } = require("webpack-sources");
|
|
|
9
9
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
10
10
|
const Template = require("../Template");
|
|
11
11
|
const { getUndoPath } = require("../util/identifier");
|
|
12
|
+
const {
|
|
13
|
+
createChunkHashHandler,
|
|
14
|
+
getChunkInfo
|
|
15
|
+
} = require("./ChunkFormatHelpers");
|
|
12
16
|
const {
|
|
13
17
|
getChunkFilenameTemplate,
|
|
14
18
|
getCompilationHooks
|
|
15
19
|
} = require("./JavascriptModulesPlugin");
|
|
16
|
-
const {
|
|
17
|
-
generateEntryStartup,
|
|
18
|
-
updateHashForEntryStartup
|
|
19
|
-
} = require("./StartupHelpers");
|
|
20
|
+
const { generateEntryStartup } = require("./StartupHelpers");
|
|
20
21
|
|
|
21
22
|
/** @typedef {import("../Chunk")} Chunk */
|
|
22
23
|
/** @typedef {import("../Compiler")} Compiler */
|
|
@@ -59,13 +60,8 @@ class CommonJsChunkFormatPlugin {
|
|
|
59
60
|
Template.renderChunkRuntimeModules(runtimeModules, renderContext)
|
|
60
61
|
);
|
|
61
62
|
}
|
|
62
|
-
const entries =
|
|
63
|
-
|
|
64
|
-
];
|
|
65
|
-
if (entries.length > 0) {
|
|
66
|
-
const runtimeChunk =
|
|
67
|
-
/** @type {Entrypoint} */
|
|
68
|
-
(entries[0][1]).getRuntimeChunk();
|
|
63
|
+
const { entries, runtimeChunk } = getChunkInfo(chunk, chunkGraph);
|
|
64
|
+
if (runtimeChunk) {
|
|
69
65
|
const currentOutputName = compilation
|
|
70
66
|
.getPath(
|
|
71
67
|
getChunkFilenameTemplate(chunk, compilation.outputOptions),
|
|
@@ -144,15 +140,8 @@ class CommonJsChunkFormatPlugin {
|
|
|
144
140
|
}
|
|
145
141
|
return source;
|
|
146
142
|
});
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
hash.update(PLUGIN_NAME);
|
|
150
|
-
hash.update("1");
|
|
151
|
-
const entries = [
|
|
152
|
-
...chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)
|
|
153
|
-
];
|
|
154
|
-
updateHashForEntryStartup(hash, chunkGraph, entries, chunk);
|
|
155
|
-
});
|
|
143
|
+
|
|
144
|
+
hooks.chunkHash.tap(PLUGIN_NAME, createChunkHashHandler(PLUGIN_NAME));
|
|
156
145
|
});
|
|
157
146
|
}
|
|
158
147
|
}
|
|
@@ -173,13 +173,38 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
|
173
173
|
* @property {string} hash hash to be used for render call
|
|
174
174
|
*/
|
|
175
175
|
|
|
176
|
-
/**
|
|
176
|
+
/**
|
|
177
|
+
* @typedef {object} StartupRenderContext
|
|
178
|
+
* @property {Chunk} chunk the chunk
|
|
179
|
+
* @property {DependencyTemplates} dependencyTemplates the dependency templates
|
|
180
|
+
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
|
181
|
+
* @property {ModuleGraph} moduleGraph the module graph
|
|
182
|
+
* @property {ChunkGraph} chunkGraph the chunk graph
|
|
183
|
+
* @property {CodeGenerationResults} codeGenerationResults results of code generation
|
|
184
|
+
* @property {boolean | undefined} strictMode rendering in strict context
|
|
185
|
+
* @property {boolean } inlined inlined
|
|
186
|
+
* @property {boolean=} inlinedInIIFE the inlined entry module is wrapped in an IIFE
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* @typedef {object} ModuleRenderContext
|
|
191
|
+
* @property {Chunk} chunk the chunk
|
|
192
|
+
* @property {DependencyTemplates} dependencyTemplates the dependency templates
|
|
193
|
+
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
|
194
|
+
* @property {ModuleGraph} moduleGraph the module graph
|
|
195
|
+
* @property {ChunkGraph} chunkGraph the chunk graph
|
|
196
|
+
* @property {CodeGenerationResults} codeGenerationResults results of code generation
|
|
197
|
+
* @property {InitFragment<ChunkRenderContext>[]} chunkInitFragments init fragments for the chunk
|
|
198
|
+
* @property {boolean | undefined} strictMode rendering in strict context
|
|
199
|
+
* @property {boolean} factory true: renders as factory method, false: pure module content
|
|
200
|
+
* @property {boolean=} inlinedInIIFE the inlined entry module is wrapped in an IIFE, existing only when `factory` is set to false
|
|
201
|
+
*/
|
|
177
202
|
|
|
178
203
|
/**
|
|
179
204
|
* @typedef {object} CompilationHooks
|
|
180
|
-
* @property {SyncWaterfallHook<[Source, Module,
|
|
181
|
-
* @property {SyncWaterfallHook<[Source, Module,
|
|
182
|
-
* @property {SyncWaterfallHook<[Source, Module,
|
|
205
|
+
* @property {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>} renderModuleContent
|
|
206
|
+
* @property {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>} renderModuleContainer
|
|
207
|
+
* @property {SyncWaterfallHook<[Source, Module, ModuleRenderContext]>} renderModulePackage
|
|
183
208
|
* @property {SyncWaterfallHook<[Source, RenderContext]>} renderChunk
|
|
184
209
|
* @property {SyncWaterfallHook<[Source, RenderContext]>} renderMain
|
|
185
210
|
* @property {SyncWaterfallHook<[Source, RenderContext]>} renderContent
|
|
@@ -217,17 +242,17 @@ class JavascriptModulesPlugin {
|
|
|
217
242
|
renderModuleContent: new SyncWaterfallHook([
|
|
218
243
|
"source",
|
|
219
244
|
"module",
|
|
220
|
-
"
|
|
245
|
+
"moduleRenderContext"
|
|
221
246
|
]),
|
|
222
247
|
renderModuleContainer: new SyncWaterfallHook([
|
|
223
248
|
"source",
|
|
224
249
|
"module",
|
|
225
|
-
"
|
|
250
|
+
"moduleRenderContext"
|
|
226
251
|
]),
|
|
227
252
|
renderModulePackage: new SyncWaterfallHook([
|
|
228
253
|
"source",
|
|
229
254
|
"module",
|
|
230
|
-
"
|
|
255
|
+
"moduleRenderContext"
|
|
231
256
|
]),
|
|
232
257
|
render: new SyncWaterfallHook(["source", "renderContext"]),
|
|
233
258
|
renderContent: new SyncWaterfallHook(["source", "renderContext"]),
|
|
@@ -575,18 +600,18 @@ class JavascriptModulesPlugin {
|
|
|
575
600
|
|
|
576
601
|
/**
|
|
577
602
|
* @param {Module} module the rendered module
|
|
578
|
-
* @param {
|
|
603
|
+
* @param {ModuleRenderContext} renderContext options object
|
|
579
604
|
* @param {CompilationHooks} hooks hooks
|
|
580
|
-
* @param {boolean} factory true: renders as factory method, false: pure module content
|
|
581
605
|
* @returns {Source | null} the newly generated source from rendering
|
|
582
606
|
*/
|
|
583
|
-
renderModule(module, renderContext, hooks
|
|
607
|
+
renderModule(module, renderContext, hooks) {
|
|
584
608
|
const {
|
|
585
609
|
chunk,
|
|
586
610
|
chunkGraph,
|
|
587
611
|
runtimeTemplate,
|
|
588
612
|
codeGenerationResults,
|
|
589
|
-
strictMode
|
|
613
|
+
strictMode,
|
|
614
|
+
factory
|
|
590
615
|
} = renderContext;
|
|
591
616
|
try {
|
|
592
617
|
const codeGenResult = codeGenerationResults.get(module, chunk.runtime);
|
|
@@ -729,7 +754,11 @@ class JavascriptModulesPlugin {
|
|
|
729
754
|
};
|
|
730
755
|
const moduleSources =
|
|
731
756
|
Template.renderChunkModules(chunkRenderContext, allModules, (module) =>
|
|
732
|
-
this.renderModule(
|
|
757
|
+
this.renderModule(
|
|
758
|
+
module,
|
|
759
|
+
{ ...chunkRenderContext, factory: true },
|
|
760
|
+
hooks
|
|
761
|
+
)
|
|
733
762
|
) || new RawSource("{}");
|
|
734
763
|
let source = tryRunOrWebpackError(
|
|
735
764
|
() => hooks.renderChunk.call(moduleSources, chunkRenderContext),
|
|
@@ -841,7 +870,12 @@ class JavascriptModulesPlugin {
|
|
|
841
870
|
(m) => !(/** @type {Set<Module>} */ (inlinedModules).has(m))
|
|
842
871
|
)
|
|
843
872
|
: allModules,
|
|
844
|
-
(module) =>
|
|
873
|
+
(module) =>
|
|
874
|
+
this.renderModule(
|
|
875
|
+
module,
|
|
876
|
+
{ ...chunkRenderContext, factory: true },
|
|
877
|
+
hooks
|
|
878
|
+
),
|
|
845
879
|
prefix
|
|
846
880
|
);
|
|
847
881
|
if (
|
|
@@ -913,6 +947,8 @@ class JavascriptModulesPlugin {
|
|
|
913
947
|
const avoidEntryIife = compilation.options.optimization.avoidEntryIife;
|
|
914
948
|
/** @type {Map<Module, Source> | false} */
|
|
915
949
|
let renamedInlinedModule = false;
|
|
950
|
+
let inlinedInIIFE = false;
|
|
951
|
+
|
|
916
952
|
if (avoidEntryIife) {
|
|
917
953
|
renamedInlinedModule = this.getRenamedInlineModule(
|
|
918
954
|
allModules,
|
|
@@ -926,31 +962,46 @@ class JavascriptModulesPlugin {
|
|
|
926
962
|
}
|
|
927
963
|
|
|
928
964
|
for (const m of inlinedModules) {
|
|
965
|
+
const runtimeRequirements = chunkGraph.getModuleRuntimeRequirements(
|
|
966
|
+
m,
|
|
967
|
+
chunk.runtime
|
|
968
|
+
);
|
|
969
|
+
const exports = runtimeRequirements.has(RuntimeGlobals.exports);
|
|
970
|
+
const webpackExports =
|
|
971
|
+
exports && m.exportsArgument === RuntimeGlobals.exports;
|
|
972
|
+
|
|
973
|
+
const innerStrict =
|
|
974
|
+
!allStrict && /** @type {BuildInfo} */ (m.buildInfo).strict;
|
|
975
|
+
|
|
976
|
+
const iife = innerStrict
|
|
977
|
+
? "it needs to be in strict mode."
|
|
978
|
+
: inlinedModules.size > 1
|
|
979
|
+
? // TODO check globals and top-level declarations of other entries and chunk modules
|
|
980
|
+
// to make a better decision
|
|
981
|
+
"it needs to be isolated against other entry modules."
|
|
982
|
+
: chunkModules && !renamedInlinedModule
|
|
983
|
+
? "it needs to be isolated against other modules in the chunk."
|
|
984
|
+
: exports && !webpackExports
|
|
985
|
+
? `it uses a non-standard name for the exports (${m.exportsArgument}).`
|
|
986
|
+
: hooks.embedInRuntimeBailout.call(m, renderContext);
|
|
987
|
+
|
|
988
|
+
if (iife) {
|
|
989
|
+
inlinedInIIFE = true;
|
|
990
|
+
}
|
|
991
|
+
|
|
929
992
|
const renderedModule = renamedInlinedModule
|
|
930
993
|
? renamedInlinedModule.get(m)
|
|
931
|
-
: this.renderModule(
|
|
994
|
+
: this.renderModule(
|
|
995
|
+
m,
|
|
996
|
+
{
|
|
997
|
+
...chunkRenderContext,
|
|
998
|
+
factory: false,
|
|
999
|
+
inlinedInIIFE
|
|
1000
|
+
},
|
|
1001
|
+
hooks
|
|
1002
|
+
);
|
|
932
1003
|
|
|
933
1004
|
if (renderedModule) {
|
|
934
|
-
const innerStrict =
|
|
935
|
-
!allStrict && /** @type {BuildInfo} */ (m.buildInfo).strict;
|
|
936
|
-
const runtimeRequirements = chunkGraph.getModuleRuntimeRequirements(
|
|
937
|
-
m,
|
|
938
|
-
chunk.runtime
|
|
939
|
-
);
|
|
940
|
-
const exports = runtimeRequirements.has(RuntimeGlobals.exports);
|
|
941
|
-
const webpackExports =
|
|
942
|
-
exports && m.exportsArgument === RuntimeGlobals.exports;
|
|
943
|
-
const iife = innerStrict
|
|
944
|
-
? "it needs to be in strict mode."
|
|
945
|
-
: inlinedModules.size > 1
|
|
946
|
-
? // TODO check globals and top-level declarations of other entries and chunk modules
|
|
947
|
-
// to make a better decision
|
|
948
|
-
"it needs to be isolated against other entry modules."
|
|
949
|
-
: chunkModules && !renamedInlinedModule
|
|
950
|
-
? "it needs to be isolated against other modules in the chunk."
|
|
951
|
-
: exports && !webpackExports
|
|
952
|
-
? `it uses a non-standard name for the exports (${m.exportsArgument}).`
|
|
953
|
-
: hooks.embedInRuntimeBailout.call(m, renderContext);
|
|
954
1005
|
let footer;
|
|
955
1006
|
if (iife !== undefined) {
|
|
956
1007
|
startupSource.add(
|
|
@@ -989,7 +1040,8 @@ class JavascriptModulesPlugin {
|
|
|
989
1040
|
source.add(
|
|
990
1041
|
hooks.renderStartup.call(startupSource, lastInlinedModule, {
|
|
991
1042
|
...renderContext,
|
|
992
|
-
inlined: true
|
|
1043
|
+
inlined: true,
|
|
1044
|
+
inlinedInIIFE
|
|
993
1045
|
})
|
|
994
1046
|
);
|
|
995
1047
|
if (bootstrap.afterStartup.length > 0) {
|
|
@@ -1557,7 +1609,6 @@ class JavascriptModulesPlugin {
|
|
|
1557
1609
|
allModules.every((m) => /** @type {BuildInfo} */ (m.buildInfo).strict);
|
|
1558
1610
|
const isMultipleEntries = inlinedModules.size > 1;
|
|
1559
1611
|
const singleEntryWithModules = inlinedModules.size === 1 && hasChunkModules;
|
|
1560
|
-
|
|
1561
1612
|
// TODO:
|
|
1562
1613
|
// This step is before the IIFE reason calculation. Ideally, it should only be executed when this function can optimize the
|
|
1563
1614
|
// IIFE reason. Otherwise, it should directly return false. There are four reasons now, we have skipped two already, the left
|
|
@@ -1581,9 +1632,12 @@ class JavascriptModulesPlugin {
|
|
|
1581
1632
|
const isInlinedModule = inlinedModules && inlinedModules.has(m);
|
|
1582
1633
|
const moduleSource = this.renderModule(
|
|
1583
1634
|
m,
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1635
|
+
{
|
|
1636
|
+
...chunkRenderContext,
|
|
1637
|
+
factory: !isInlinedModule,
|
|
1638
|
+
inlinedInIIFE: false
|
|
1639
|
+
},
|
|
1640
|
+
hooks
|
|
1587
1641
|
);
|
|
1588
1642
|
|
|
1589
1643
|
if (!moduleSource) continue;
|