webpack 5.59.0 → 5.71.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (209) hide show
  1. package/README.md +1 -7
  2. package/hot/lazy-compilation-node.js +3 -1
  3. package/hot/poll.js +1 -1
  4. package/hot/signal.js +1 -1
  5. package/lib/APIPlugin.js +33 -0
  6. package/lib/BannerPlugin.js +10 -4
  7. package/lib/Cache.js +1 -1
  8. package/lib/CacheFacade.js +4 -11
  9. package/lib/Chunk.js +6 -3
  10. package/lib/ChunkGraph.js +1 -2
  11. package/lib/ChunkGroup.js +1 -1
  12. package/lib/CleanPlugin.js +81 -20
  13. package/lib/Compilation.js +179 -91
  14. package/lib/Compiler.js +86 -17
  15. package/lib/ConstPlugin.js +2 -2
  16. package/lib/ContextModule.js +142 -51
  17. package/lib/ContextModuleFactory.js +65 -25
  18. package/lib/DelegatedModule.js +1 -1
  19. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  20. package/lib/Dependency.js +17 -0
  21. package/lib/DependencyTemplate.js +9 -0
  22. package/lib/DependencyTemplates.js +1 -1
  23. package/lib/DllModule.js +1 -1
  24. package/lib/EntryOptionPlugin.js +2 -0
  25. package/lib/ErrorHelpers.js +2 -2
  26. package/lib/EvalDevToolModulePlugin.js +16 -1
  27. package/lib/EvalSourceMapDevToolPlugin.js +18 -1
  28. package/lib/ExportsInfo.js +4 -4
  29. package/lib/ExternalModule.js +94 -54
  30. package/lib/ExternalModuleFactoryPlugin.js +5 -5
  31. package/lib/FileSystemInfo.js +89 -44
  32. package/lib/Generator.js +3 -0
  33. package/lib/HookWebpackError.js +1 -1
  34. package/lib/HotModuleReplacementPlugin.js +3 -1
  35. package/lib/LoaderOptionsPlugin.js +1 -1
  36. package/lib/Module.js +27 -4
  37. package/lib/ModuleFilenameHelpers.js +8 -4
  38. package/lib/ModuleHashingError.js +29 -0
  39. package/lib/MultiCompiler.js +1 -1
  40. package/lib/MultiWatching.js +1 -1
  41. package/lib/NodeStuffPlugin.js +10 -0
  42. package/lib/NormalModule.js +41 -26
  43. package/lib/NormalModuleFactory.js +42 -37
  44. package/lib/ProgressPlugin.js +4 -5
  45. package/lib/RawModule.js +1 -1
  46. package/lib/RuntimeGlobals.js +29 -1
  47. package/lib/RuntimeModule.js +1 -1
  48. package/lib/RuntimePlugin.js +77 -1
  49. package/lib/RuntimeTemplate.js +114 -2
  50. package/lib/Template.js +2 -1
  51. package/lib/TemplatedPathPlugin.js +48 -23
  52. package/lib/WatchIgnorePlugin.js +19 -7
  53. package/lib/Watching.js +33 -19
  54. package/lib/WebpackOptionsApply.js +57 -11
  55. package/lib/asset/AssetGenerator.js +193 -63
  56. package/lib/asset/AssetModulesPlugin.js +3 -0
  57. package/lib/asset/RawDataUrlModule.js +148 -0
  58. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  59. package/lib/buildChunkGraph.js +36 -6
  60. package/lib/cache/PackFileCacheStrategy.js +7 -4
  61. package/lib/cache/ResolverCachePlugin.js +90 -29
  62. package/lib/cli.js +44 -3
  63. package/lib/config/browserslistTargetHandler.js +41 -6
  64. package/lib/config/defaults.js +115 -19
  65. package/lib/config/normalization.js +9 -0
  66. package/lib/config/target.js +10 -0
  67. package/lib/container/ContainerEntryModule.js +8 -5
  68. package/lib/container/FallbackModule.js +4 -4
  69. package/lib/container/RemoteModule.js +4 -2
  70. package/lib/css/CssExportsGenerator.js +139 -0
  71. package/lib/css/CssGenerator.js +109 -0
  72. package/lib/css/CssLoadingRuntimeModule.js +440 -0
  73. package/lib/css/CssModulesPlugin.js +462 -0
  74. package/lib/css/CssParser.js +618 -0
  75. package/lib/css/walkCssTokens.js +659 -0
  76. package/lib/debug/ProfilingPlugin.js +24 -21
  77. package/lib/dependencies/AMDRequireDependency.js +6 -6
  78. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  79. package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
  80. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -3
  81. package/lib/dependencies/CommonJsRequireContextDependency.js +5 -1
  82. package/lib/dependencies/ContextDependency.js +1 -0
  83. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  84. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  85. package/lib/dependencies/ContextElementDependency.js +41 -3
  86. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  87. package/lib/dependencies/CssExportDependency.js +85 -0
  88. package/lib/dependencies/CssImportDependency.js +75 -0
  89. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  90. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  91. package/lib/dependencies/CssUrlDependency.js +132 -0
  92. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  93. package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
  94. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  95. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +95 -0
  96. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
  97. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
  98. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  99. package/lib/dependencies/HarmonyImportDependency.js +23 -0
  100. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
  101. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
  102. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  103. package/lib/dependencies/ImportContextDependency.js +0 -2
  104. package/lib/dependencies/ImportMetaContextDependency.js +35 -0
  105. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
  106. package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
  107. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  108. package/lib/dependencies/LoaderPlugin.js +4 -2
  109. package/lib/dependencies/RequireContextDependency.js +0 -16
  110. package/lib/dependencies/RequireEnsureDependency.js +2 -2
  111. package/lib/dependencies/URLDependency.js +3 -8
  112. package/lib/dependencies/URLPlugin.js +1 -1
  113. package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
  114. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  115. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
  116. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  117. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  118. package/lib/hmr/LazyCompilationPlugin.js +54 -26
  119. package/lib/hmr/lazyCompilationBackend.js +51 -12
  120. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  121. package/lib/ids/HashedModuleIdsPlugin.js +11 -14
  122. package/lib/ids/IdHelpers.js +25 -11
  123. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  124. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  125. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  126. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  127. package/lib/index.js +13 -0
  128. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  129. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  130. package/lib/javascript/ChunkHelpers.js +33 -0
  131. package/lib/javascript/JavascriptGenerator.js +1 -0
  132. package/lib/javascript/JavascriptModulesPlugin.js +27 -2
  133. package/lib/javascript/JavascriptParser.js +82 -48
  134. package/lib/javascript/StartupHelpers.js +7 -30
  135. package/lib/library/AssignLibraryPlugin.js +39 -15
  136. package/lib/library/EnableLibraryPlugin.js +11 -0
  137. package/lib/library/UmdLibraryPlugin.js +5 -3
  138. package/lib/node/NodeTargetPlugin.js +3 -0
  139. package/lib/node/NodeWatchFileSystem.js +85 -31
  140. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
  141. package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
  142. package/lib/optimize/ConcatenatedModule.js +21 -9
  143. package/lib/optimize/ModuleConcatenationPlugin.js +5 -2
  144. package/lib/optimize/SplitChunksPlugin.js +8 -1
  145. package/lib/runtime/AsyncModuleRuntimeModule.js +27 -17
  146. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  147. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  148. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  149. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  150. package/lib/schemes/HttpUriPlugin.js +77 -14
  151. package/lib/serialization/FileMiddleware.js +44 -9
  152. package/lib/sharing/ConsumeSharedModule.js +8 -2
  153. package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
  154. package/lib/sharing/ProvideSharedModule.js +4 -2
  155. package/lib/sharing/ShareRuntimeModule.js +1 -1
  156. package/lib/sharing/utils.js +1 -1
  157. package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
  158. package/lib/stats/DefaultStatsPrinterPlugin.js +89 -24
  159. package/lib/util/ArrayHelpers.js +30 -0
  160. package/lib/util/AsyncQueue.js +1 -1
  161. package/lib/util/compileBooleanMatcher.js +1 -1
  162. package/lib/util/create-schema-validation.js +9 -2
  163. package/lib/util/createHash.js +12 -0
  164. package/lib/util/deprecation.js +10 -2
  165. package/lib/util/deterministicGrouping.js +1 -1
  166. package/lib/util/extractUrlAndGlobal.js +3 -0
  167. package/lib/util/fs.js +11 -0
  168. package/lib/util/hash/BatchedHash.js +7 -4
  169. package/lib/util/hash/md4.js +20 -0
  170. package/lib/util/hash/wasm-hash.js +163 -0
  171. package/lib/util/hash/xxhash64.js +5 -139
  172. package/lib/util/identifier.js +65 -44
  173. package/lib/util/internalSerializables.js +15 -0
  174. package/lib/util/nonNumericOnlyHash.js +22 -0
  175. package/lib/util/semver.js +17 -10
  176. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  177. package/lib/web/JsonpChunkLoadingRuntimeModule.js +20 -9
  178. package/lib/webpack.js +10 -3
  179. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  180. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
  181. package/module.d.ts +215 -0
  182. package/package.json +23 -28
  183. package/schemas/WebpackOptions.check.js +1 -1
  184. package/schemas/WebpackOptions.json +254 -29
  185. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  186. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  187. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  188. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  189. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  190. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  191. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  192. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  193. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  194. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  195. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  196. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  197. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  198. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  199. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  200. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  201. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  202. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  203. package/schemas/plugins/css/CssParserOptions.json +3 -0
  204. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  205. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  206. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  207. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  208. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  209. package/types.d.ts +628 -179
@@ -8,7 +8,10 @@
8
8
  const {
9
9
  compareModulesByPreOrderIndexOrIdentifier
10
10
  } = require("../util/comparators");
11
- const { assignAscendingModuleIds } = require("./IdHelpers");
11
+ const {
12
+ assignAscendingModuleIds,
13
+ getUsedModuleIdsAndModules
14
+ } = require("./IdHelpers");
12
15
 
13
16
  /** @typedef {import("../Compiler")} Compiler */
14
17
  /** @typedef {import("../Module")} Module */
@@ -22,18 +25,12 @@ class NaturalModuleIdsPlugin {
22
25
  apply(compiler) {
23
26
  compiler.hooks.compilation.tap("NaturalModuleIdsPlugin", compilation => {
24
27
  compilation.hooks.moduleIds.tap("NaturalModuleIdsPlugin", modules => {
25
- const chunkGraph = compilation.chunkGraph;
26
- const modulesInNaturalOrder = Array.from(modules)
27
- .filter(
28
- m =>
29
- m.needId &&
30
- chunkGraph.getNumberOfModuleChunks(m) > 0 &&
31
- chunkGraph.getModuleId(m) === null
32
- )
33
- .sort(
34
- compareModulesByPreOrderIndexOrIdentifier(compilation.moduleGraph)
35
- );
36
- assignAscendingModuleIds(modulesInNaturalOrder, compilation);
28
+ const [usedIds, modulesInNaturalOrder] =
29
+ getUsedModuleIdsAndModules(compilation);
30
+ modulesInNaturalOrder.sort(
31
+ compareModulesByPreOrderIndexOrIdentifier(compilation.moduleGraph)
32
+ );
33
+ assignAscendingModuleIds(usedIds, modulesInNaturalOrder, compilation);
37
34
  });
38
35
  });
39
36
  }
@@ -9,7 +9,10 @@ const {
9
9
  compareModulesByPreOrderIndexOrIdentifier
10
10
  } = require("../util/comparators");
11
11
  const createSchemaValidation = require("../util/create-schema-validation");
12
- const { assignAscendingModuleIds } = require("./IdHelpers");
12
+ const {
13
+ assignAscendingModuleIds,
14
+ getUsedModuleIdsAndModules
15
+ } = require("./IdHelpers");
13
16
 
14
17
  /** @typedef {import("../../declarations/plugins/ids/OccurrenceModuleIdsPlugin").OccurrenceModuleIdsPluginOptions} OccurrenceModuleIdsPluginOptions */
15
18
  /** @typedef {import("../Compiler")} Compiler */
@@ -44,15 +47,11 @@ class OccurrenceModuleIdsPlugin {
44
47
  compiler.hooks.compilation.tap("OccurrenceModuleIdsPlugin", compilation => {
45
48
  const moduleGraph = compilation.moduleGraph;
46
49
 
47
- compilation.hooks.moduleIds.tap("OccurrenceModuleIdsPlugin", modules => {
50
+ compilation.hooks.moduleIds.tap("OccurrenceModuleIdsPlugin", () => {
48
51
  const chunkGraph = compilation.chunkGraph;
49
52
 
50
- const modulesInOccurrenceOrder = Array.from(modules).filter(
51
- m =>
52
- m.needId &&
53
- chunkGraph.getNumberOfModuleChunks(m) > 0 &&
54
- chunkGraph.getModuleId(m) === null
55
- );
53
+ const [usedIds, modulesInOccurrenceOrder] =
54
+ getUsedModuleIdsAndModules(compilation);
56
55
 
57
56
  const occursInInitialChunksMap = new Map();
58
57
  const occursInAllChunksMap = new Map();
@@ -121,7 +120,7 @@ class OccurrenceModuleIdsPlugin {
121
120
  }
122
121
  }
123
122
 
124
- for (const m of modules) {
123
+ for (const m of modulesInOccurrenceOrder) {
125
124
  const result =
126
125
  countOccurs(m) +
127
126
  chunkGraph.getNumberOfModuleChunks(m) +
@@ -147,7 +146,11 @@ class OccurrenceModuleIdsPlugin {
147
146
  return naturalCompare(a, b);
148
147
  });
149
148
 
150
- assignAscendingModuleIds(modulesInOccurrenceOrder, compilation);
149
+ assignAscendingModuleIds(
150
+ usedIds,
151
+ modulesInOccurrenceOrder,
152
+ compilation
153
+ );
151
154
  });
152
155
  });
153
156
  }
@@ -0,0 +1,140 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const { WebpackError } = require("..");
9
+ const { getUsedModuleIdsAndModules } = require("./IdHelpers");
10
+
11
+ /** @typedef {import("../Compiler")} Compiler */
12
+ /** @typedef {import("../Module")} Module */
13
+
14
+ const plugin = "SyncModuleIdsPlugin";
15
+
16
+ class SyncModuleIdsPlugin {
17
+ /**
18
+ * @param {Object} options options
19
+ * @param {string} options.path path to file
20
+ * @param {string=} options.context context for module names
21
+ * @param {function(Module): boolean} options.test selector for modules
22
+ * @param {"read" | "create" | "merge" | "update"=} options.mode operation mode (defaults to merge)
23
+ */
24
+ constructor({ path, context, test, mode }) {
25
+ this._path = path;
26
+ this._context = context;
27
+ this._test = test || (() => true);
28
+ const readAndWrite = !mode || mode === "merge" || mode === "update";
29
+ this._read = readAndWrite || mode === "read";
30
+ this._write = readAndWrite || mode === "create";
31
+ this._prune = mode === "update";
32
+ }
33
+
34
+ /**
35
+ * Apply the plugin
36
+ * @param {Compiler} compiler the compiler instance
37
+ * @returns {void}
38
+ */
39
+ apply(compiler) {
40
+ /** @type {Map<string, string | number>} */
41
+ let data;
42
+ let dataChanged = false;
43
+ if (this._read) {
44
+ compiler.hooks.readRecords.tapAsync(plugin, callback => {
45
+ const fs = compiler.intermediateFileSystem;
46
+ fs.readFile(this._path, (err, buffer) => {
47
+ if (err) {
48
+ if (err.code !== "ENOENT") {
49
+ return callback(err);
50
+ }
51
+ return callback();
52
+ }
53
+ const json = JSON.parse(buffer.toString());
54
+ data = new Map();
55
+ for (const key of Object.keys(json)) {
56
+ data.set(key, json[key]);
57
+ }
58
+ dataChanged = false;
59
+ return callback();
60
+ });
61
+ });
62
+ }
63
+ if (this._write) {
64
+ compiler.hooks.emitRecords.tapAsync(plugin, callback => {
65
+ if (!data || !dataChanged) return callback();
66
+ const json = {};
67
+ const sorted = Array.from(data).sort(([a], [b]) => (a < b ? -1 : 1));
68
+ for (const [key, value] of sorted) {
69
+ json[key] = value;
70
+ }
71
+ const fs = compiler.intermediateFileSystem;
72
+ fs.writeFile(this._path, JSON.stringify(json), callback);
73
+ });
74
+ }
75
+ compiler.hooks.thisCompilation.tap(plugin, compilation => {
76
+ const associatedObjectForCache = compiler.root;
77
+ const context = this._context || compiler.context;
78
+ if (this._read) {
79
+ compilation.hooks.reviveModules.tap(plugin, (_1, _2) => {
80
+ if (!data) return;
81
+ const { chunkGraph } = compilation;
82
+ const [usedIds, modules] = getUsedModuleIdsAndModules(
83
+ compilation,
84
+ this._test
85
+ );
86
+ for (const module of modules) {
87
+ const name = module.libIdent({
88
+ context,
89
+ associatedObjectForCache
90
+ });
91
+ if (!name) continue;
92
+ const id = data.get(name);
93
+ const idAsString = `${id}`;
94
+ if (usedIds.has(idAsString)) {
95
+ const err = new WebpackError(
96
+ `SyncModuleIdsPlugin: Unable to restore id '${id}' from '${this._path}' as it's already used.`
97
+ );
98
+ err.module = module;
99
+ compilation.errors.push(err);
100
+ }
101
+ chunkGraph.setModuleId(module, id);
102
+ usedIds.add(idAsString);
103
+ }
104
+ });
105
+ }
106
+ if (this._write) {
107
+ compilation.hooks.recordModules.tap(plugin, modules => {
108
+ const { chunkGraph } = compilation;
109
+ let oldData = data;
110
+ if (!oldData) {
111
+ oldData = data = new Map();
112
+ } else if (this._prune) {
113
+ data = new Map();
114
+ }
115
+ for (const module of modules) {
116
+ if (this._test(module)) {
117
+ const name = module.libIdent({
118
+ context,
119
+ associatedObjectForCache
120
+ });
121
+ if (!name) continue;
122
+ const id = chunkGraph.getModuleId(module);
123
+ if (id === null) continue;
124
+ const oldId = oldData.get(name);
125
+ if (oldId !== id) {
126
+ dataChanged = true;
127
+ } else if (data === oldData) {
128
+ continue;
129
+ }
130
+ data.set(name, id);
131
+ }
132
+ }
133
+ if (data.size !== oldData.size) dataChanged = true;
134
+ });
135
+ }
136
+ });
137
+ }
138
+ }
139
+
140
+ module.exports = SyncModuleIdsPlugin;
package/lib/index.js CHANGED
@@ -11,6 +11,7 @@ const memoize = require("./util/memoize");
11
11
  /** @typedef {import("../declarations/WebpackOptions").Entry} Entry */
12
12
  /** @typedef {import("../declarations/WebpackOptions").EntryNormalized} EntryNormalized */
13
13
  /** @typedef {import("../declarations/WebpackOptions").EntryObject} EntryObject */
14
+ /** @typedef {import("../declarations/WebpackOptions").FileCacheOptions} FileCacheOptions */
14
15
  /** @typedef {import("../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
15
16
  /** @typedef {import("../declarations/WebpackOptions").ModuleOptions} ModuleOptions */
16
17
  /** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
@@ -19,15 +20,22 @@ const memoize = require("./util/memoize");
19
20
  /** @typedef {import("../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
20
21
  /** @typedef {import("../declarations/WebpackOptions").RuleSetUse} RuleSetUse */
21
22
  /** @typedef {import("../declarations/WebpackOptions").RuleSetUseItem} RuleSetUseItem */
23
+ /** @typedef {import("../declarations/WebpackOptions").StatsOptions} StatsOptions */
22
24
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptions} Configuration */
23
25
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */
24
26
  /** @typedef {import("../declarations/WebpackOptions").WebpackPluginFunction} WebpackPluginFunction */
25
27
  /** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
26
28
  /** @typedef {import("./Compilation").Asset} Asset */
27
29
  /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
30
+ /** @typedef {import("./Compilation").EntryOptions} EntryOptions */
31
+ /** @typedef {import("./Compiler").AssetEmittedInfo} AssetEmittedInfo */
28
32
  /** @typedef {import("./MultiStats")} MultiStats */
29
33
  /** @typedef {import("./Parser").ParserState} ParserState */
34
+ /** @typedef {import("./ResolverFactory").ResolvePluginInstance} ResolvePluginInstance */
35
+ /** @typedef {import("./ResolverFactory").Resolver} Resolver */
30
36
  /** @typedef {import("./Watching")} Watching */
37
+ /** @typedef {import("./cli").Argument} Argument */
38
+ /** @typedef {import("./cli").Problem} Problem */
31
39
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsAsset} StatsAsset */
32
40
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsChunk} StatsChunk */
33
41
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsChunkGroup} StatsChunkGroup */
@@ -561,6 +569,11 @@ module.exports = mergeExports(fn, {
561
569
  get HttpUriPlugin() {
562
570
  return require("./schemes/HttpUriPlugin");
563
571
  }
572
+ },
573
+ ids: {
574
+ get SyncModuleIdsPlugin() {
575
+ return require("./ids/SyncModuleIdsPlugin");
576
+ }
564
577
  }
565
578
  }
566
579
  });
@@ -45,7 +45,7 @@ class ArrayPushCallbackChunkFormatPlugin {
45
45
  const { chunk, chunkGraph, runtimeTemplate } = renderContext;
46
46
  const hotUpdateChunk =
47
47
  chunk instanceof HotUpdateChunk ? chunk : null;
48
- const globalObject = runtimeTemplate.outputOptions.globalObject;
48
+ const globalObject = runtimeTemplate.globalObject;
49
49
  const source = new ConcatSource();
50
50
  const runtimeModules =
51
51
  chunkGraph.getChunkRuntimeModulesInOrder(chunk);
@@ -138,7 +138,7 @@ class ArrayPushCallbackChunkFormatPlugin {
138
138
  (chunk, hash, { chunkGraph, runtimeTemplate }) => {
139
139
  if (chunk.hasRuntime()) return;
140
140
  hash.update(
141
- `ArrayPushCallbackChunkFormatPlugin1${runtimeTemplate.outputOptions.chunkLoadingGlobal}${runtimeTemplate.outputOptions.hotUpdateGlobal}${runtimeTemplate.outputOptions.globalObject}`
141
+ `ArrayPushCallbackChunkFormatPlugin1${runtimeTemplate.outputOptions.chunkLoadingGlobal}${runtimeTemplate.outputOptions.hotUpdateGlobal}${runtimeTemplate.globalObject}`
142
142
  );
143
143
  const entries = Array.from(
144
144
  chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)
@@ -61,12 +61,14 @@ class BasicEvaluatedExpression {
61
61
  /** @type {BasicEvaluatedExpression | undefined} */
62
62
  this.postfix = undefined;
63
63
  this.wrappedInnerExpressions = undefined;
64
- /** @type {string | undefined} */
64
+ /** @type {string | VariableInfoInterface | undefined} */
65
65
  this.identifier = undefined;
66
66
  /** @type {VariableInfoInterface} */
67
67
  this.rootInfo = undefined;
68
68
  /** @type {() => string[]} */
69
69
  this.getMembers = undefined;
70
+ /** @type {() => boolean[]} */
71
+ this.getMembersOptionals = undefined;
70
72
  /** @type {EsTreeNode} */
71
73
  this.expression = undefined;
72
74
  }
@@ -342,11 +344,12 @@ class BasicEvaluatedExpression {
342
344
  return this;
343
345
  }
344
346
 
345
- setIdentifier(identifier, rootInfo, getMembers) {
347
+ setIdentifier(identifier, rootInfo, getMembers, getMembersOptionals) {
346
348
  this.type = TypeIdentifier;
347
349
  this.identifier = identifier;
348
350
  this.rootInfo = rootInfo;
349
351
  this.getMembers = getMembers;
352
+ this.getMembersOptionals = getMembersOptionals;
350
353
  this.sideEffects = true;
351
354
  return this;
352
355
  }
@@ -0,0 +1,33 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const Entrypoint = require("../Entrypoint");
9
+
10
+ /** @typedef {import("../Chunk")} Chunk */
11
+
12
+ /**
13
+ * @param {Entrypoint} entrypoint a chunk group
14
+ * @param {Chunk} excludedChunk1 current chunk which is excluded
15
+ * @param {Chunk} excludedChunk2 runtime chunk which is excluded
16
+ * @returns {Set<Chunk>} chunks
17
+ */
18
+ const getAllChunks = (entrypoint, excludedChunk1, excludedChunk2) => {
19
+ const queue = new Set([entrypoint]);
20
+ const chunks = new Set();
21
+ for (const entrypoint of queue) {
22
+ for (const chunk of entrypoint.chunks) {
23
+ if (chunk === excludedChunk1) continue;
24
+ if (chunk === excludedChunk2) continue;
25
+ chunks.add(chunk);
26
+ }
27
+ for (const parent of entrypoint.parentsIterable) {
28
+ if (parent instanceof Entrypoint) queue.add(parent);
29
+ }
30
+ }
31
+ return chunks;
32
+ };
33
+ exports.getAllChunks = getAllChunks;
@@ -199,6 +199,7 @@ class JavascriptGenerator extends Generator {
199
199
  runtime: generateContext.runtime,
200
200
  runtimeRequirements: generateContext.runtimeRequirements,
201
201
  concatenationScope: generateContext.concatenationScope,
202
+ codeGenerationResults: generateContext.codeGenerationResults,
202
203
  initFragments
203
204
  };
204
205
 
@@ -24,6 +24,7 @@ const { last, someInIterable } = require("../util/IterableHelpers");
24
24
  const StringXor = require("../util/StringXor");
25
25
  const { compareModulesByIdentifier } = require("../util/comparators");
26
26
  const createHash = require("../util/createHash");
27
+ const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
27
28
  const { intersectRuntime } = require("../util/runtime");
28
29
  const JavascriptGenerator = require("./JavascriptGenerator");
29
30
  const JavascriptParser = require("./JavascriptParser");
@@ -102,6 +103,7 @@ const printGeneratedCodeForStack = (module, code) => {
102
103
  /**
103
104
  * @typedef {Object} RenderBootstrapContext
104
105
  * @property {Chunk} chunk the chunk
106
+ * @property {CodeGenerationResults} codeGenerationResults results of code generation
105
107
  * @property {RuntimeTemplate} runtimeTemplate the runtime template
106
108
  * @property {ModuleGraph} moduleGraph the module graph
107
109
  * @property {ChunkGraph} chunkGraph the chunk graph
@@ -331,6 +333,7 @@ class JavascriptModulesPlugin {
331
333
  {
332
334
  hash: "0000",
333
335
  chunk,
336
+ codeGenerationResults: context.codeGenerationResults,
334
337
  chunkGraph: context.chunkGraph,
335
338
  moduleGraph: context.moduleGraph,
336
339
  runtimeTemplate: context.runtimeTemplate
@@ -343,6 +346,7 @@ class JavascriptModulesPlugin {
343
346
  compilation.hooks.contentHash.tap("JavascriptModulesPlugin", chunk => {
344
347
  const {
345
348
  chunkGraph,
349
+ codeGenerationResults,
346
350
  moduleGraph,
347
351
  runtimeTemplate,
348
352
  outputOptions: {
@@ -360,6 +364,7 @@ class JavascriptModulesPlugin {
360
364
  {
361
365
  hash: "0000",
362
366
  chunk,
367
+ codeGenerationResults,
363
368
  chunkGraph: compilation.chunkGraph,
364
369
  moduleGraph: compilation.moduleGraph,
365
370
  runtimeTemplate: compilation.runtimeTemplate
@@ -372,6 +377,7 @@ class JavascriptModulesPlugin {
372
377
  }
373
378
  hooks.chunkHash.call(chunk, hash, {
374
379
  chunkGraph,
380
+ codeGenerationResults,
375
381
  moduleGraph,
376
382
  runtimeTemplate
377
383
  });
@@ -398,7 +404,10 @@ class JavascriptModulesPlugin {
398
404
  xor.updateHash(hash);
399
405
  }
400
406
  const digest = /** @type {string} */ (hash.digest(hashDigest));
401
- chunk.contentHash.javascript = digest.substr(0, hashDigestLength);
407
+ chunk.contentHash.javascript = nonNumericOnlyHash(
408
+ digest,
409
+ hashDigestLength
410
+ );
402
411
  });
403
412
  compilation.hooks.additionalTreeRuntimeRequirements.tap(
404
413
  "JavascriptModulesPlugin",
@@ -974,7 +983,13 @@ class JavascriptModulesPlugin {
974
983
  * @returns {{ header: string[], beforeStartup: string[], startup: string[], afterStartup: string[], allowInlineStartup: boolean }} the generated source of the bootstrap code
975
984
  */
976
985
  renderBootstrap(renderContext, hooks) {
977
- const { chunkGraph, moduleGraph, chunk, runtimeTemplate } = renderContext;
986
+ const {
987
+ chunkGraph,
988
+ codeGenerationResults,
989
+ moduleGraph,
990
+ chunk,
991
+ runtimeTemplate
992
+ } = renderContext;
978
993
 
979
994
  const runtimeRequirements = chunkGraph.getTreeRuntimeRequirements(chunk);
980
995
 
@@ -1098,8 +1113,18 @@ class JavascriptModulesPlugin {
1098
1113
  );
1099
1114
  result.allowInlineStartup = false;
1100
1115
  }
1116
+
1117
+ let data;
1118
+ if (codeGenerationResults.has(entryModule, chunk.runtime)) {
1119
+ const result = codeGenerationResults.get(
1120
+ entryModule,
1121
+ chunk.runtime
1122
+ );
1123
+ data = result.data;
1124
+ }
1101
1125
  if (
1102
1126
  result.allowInlineStartup &&
1127
+ (!data || !data.get("topLevelDeclarations")) &&
1103
1128
  (!entryModule.buildInfo ||
1104
1129
  !entryModule.buildInfo.topLevelDeclarations)
1105
1130
  ) {