webpack 5.39.0 → 5.41.1

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 (51) hide show
  1. package/README.md +13 -13
  2. package/bin/webpack.js +0 -0
  3. package/lib/Compilation.js +43 -28
  4. package/lib/ConditionalInitFragment.js +15 -12
  5. package/lib/DependencyTemplate.js +3 -2
  6. package/lib/ExternalModule.js +210 -35
  7. package/lib/ExternalModuleFactoryPlugin.js +2 -1
  8. package/lib/InitFragment.js +10 -7
  9. package/lib/MainTemplate.js +1 -1
  10. package/lib/ModuleTemplate.js +0 -9
  11. package/lib/RuntimeTemplate.js +8 -0
  12. package/lib/Template.js +3 -2
  13. package/lib/TemplatedPathPlugin.js +24 -26
  14. package/lib/Watching.js +2 -1
  15. package/lib/WebpackOptionsApply.js +10 -7
  16. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
  17. package/lib/cache/IdleFileCachePlugin.js +60 -13
  18. package/lib/cache/PackFileCacheStrategy.js +4 -1
  19. package/lib/cli.js +1 -1
  20. package/lib/config/defaults.js +53 -12
  21. package/lib/config/normalization.js +1 -0
  22. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  23. package/lib/dependencies/WorkerPlugin.js +25 -10
  24. package/lib/electron/ElectronTargetPlugin.js +3 -3
  25. package/lib/esm/ModuleChunkFormatPlugin.js +97 -0
  26. package/lib/esm/ModuleChunkLoadingPlugin.js +63 -0
  27. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +208 -0
  28. package/lib/hmr/lazyCompilationBackend.js +17 -1
  29. package/lib/javascript/EnableChunkLoadingPlugin.js +5 -3
  30. package/lib/javascript/JavascriptModulesPlugin.js +80 -17
  31. package/lib/javascript/JavascriptParser.js +12 -4
  32. package/lib/node/NodeTargetPlugin.js +2 -1
  33. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +44 -22
  34. package/lib/optimize/InnerGraphPlugin.js +33 -2
  35. package/lib/optimize/ModuleConcatenationPlugin.js +1 -1
  36. package/lib/runtime/AsyncModuleRuntimeModule.js +8 -4
  37. package/lib/serialization/BinaryMiddleware.js +24 -14
  38. package/lib/serialization/FileMiddleware.js +30 -6
  39. package/lib/serialization/PlainObjectSerializer.js +17 -8
  40. package/lib/serialization/Serializer.js +2 -2
  41. package/lib/serialization/SerializerMiddleware.js +26 -4
  42. package/lib/util/ArrayQueue.js +8 -0
  43. package/lib/util/AsyncQueue.js +9 -0
  44. package/lib/util/LazySet.js +26 -17
  45. package/lib/wasm/EnableWasmLoadingPlugin.js +10 -1
  46. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  47. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  48. package/package.json +17 -17
  49. package/schemas/WebpackOptions.check.js +1 -1
  50. package/schemas/WebpackOptions.json +16 -7
  51. package/types.d.ts +107 -158
package/README.md CHANGED
@@ -40,7 +40,7 @@
40
40
  </a>
41
41
  <h1>webpack</h1>
42
42
  <p>
43
- webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.
43
+ Webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.
44
44
  </p>
45
45
  </div>
46
46
 
@@ -77,7 +77,7 @@ yarn add webpack --dev
77
77
 
78
78
  <h2 align="center">Introduction</h2>
79
79
 
80
- webpack is a bundler for modules. The main purpose is to bundle JavaScript
80
+ Webpack is a bundler for modules. The main purpose is to bundle JavaScript
81
81
  files for usage in a browser, yet it is also capable of transforming, bundling,
82
82
  or packaging just about any resource or asset.
83
83
 
@@ -95,14 +95,14 @@ Check out webpack's quick [**Get Started**](https://webpack.js.org/guides/gettin
95
95
 
96
96
  ### Browser Compatibility
97
97
 
98
- webpack supports all browsers that are [ES5-compliant](https://kangax.github.io/compat-table/es5/) (IE8 and below are not supported).
99
- webpack also needs `Promise` for `import()` and `require.ensure()`. If you want to support older browsers, you will need to [load a polyfill](https://webpack.js.org/guides/shimming/) before using these expressions.
98
+ Webpack supports all browsers that are [ES5-compliant](https://kangax.github.io/compat-table/es5/) (IE8 and below are not supported).
99
+ Webpack also needs `Promise` for `import()` and `require.ensure()`. If you want to support older browsers, you will need to [load a polyfill](https://webpack.js.org/guides/shimming/) before using these expressions.
100
100
 
101
101
  <h2 align="center">Concepts</h2>
102
102
 
103
103
  ### [Plugins](https://webpack.js.org/plugins/)
104
104
 
105
- webpack has a [rich plugin
105
+ Webpack has a [rich plugin
106
106
  interface](https://webpack.js.org/plugins/). Most of the features
107
107
  within webpack itself use this plugin interface. This makes webpack very
108
108
  **flexible**.
@@ -129,7 +129,7 @@ within webpack itself use this plugin interface. This makes webpack very
129
129
 
130
130
  ### [Loaders](https://webpack.js.org/loaders/)
131
131
 
132
- webpack enables the use of loaders to preprocess files. This allows you to bundle
132
+ Webpack enables the use of loaders to preprocess files. This allows you to bundle
133
133
  **any static resource** way beyond JavaScript. You can easily [write your own
134
134
  loaders](https://webpack.js.org/api/loaders/) using Node.js.
135
135
 
@@ -249,23 +249,23 @@ or are automatically applied via regex from your webpack configuration.
249
249
 
250
250
  ### Performance
251
251
 
252
- webpack uses async I/O and has multiple caching levels. This makes webpack fast
252
+ Webpack uses async I/O and has multiple caching levels. This makes webpack fast
253
253
  and incredibly **fast** on incremental compilations.
254
254
 
255
255
  ### Module Formats
256
256
 
257
- webpack supports ES2015+, CommonJS and AMD modules **out of the box**. It performs clever static
257
+ Webpack supports ES2015+, CommonJS and AMD modules **out of the box**. It performs clever static
258
258
  analysis on the AST of your code. It even has an evaluation engine to evaluate
259
259
  simple expressions. This allows you to **support most existing libraries** out of the box.
260
260
 
261
261
  ### [Code Splitting](https://webpack.js.org/guides/code-splitting/)
262
262
 
263
- webpack allows you to split your codebase into multiple chunks. Chunks are
263
+ Webpack allows you to split your codebase into multiple chunks. Chunks are
264
264
  loaded asynchronously at runtime. This reduces the initial loading time.
265
265
 
266
266
  ### [Optimizations](https://webpack.js.org/guides/production-build/)
267
267
 
268
- webpack can do many optimizations to **reduce the output size of your
268
+ Webpack can do many optimizations to **reduce the output size of your
269
269
  JavaScript** by deduplicating frequently used modules, minifying, and giving
270
270
  you full control of what is loaded initially and what is loaded at runtime
271
271
  through code splitting. It can also make your code chunks **cache
@@ -287,7 +287,7 @@ Contributions go far beyond pull requests and commits. Although we love giving y
287
287
  - [Blogging, speaking about, or creating tutorials](https://github.com/webpack-contrib/awesome-webpack) about one of webpack's many features.
288
288
  - Helping others in our webpack [gitter channel](https://gitter.im/webpack/webpack).
289
289
 
290
- To get started have a look at our [documentation on contributing](https://github.com/webpack/webpack/blob/master/CONTRIBUTING.md).
290
+ To get started have a look at our [documentation on contributing](https://github.com/webpack/webpack/blob/main/CONTRIBUTING.md).
291
291
 
292
292
  If you are worried or don't know where to start, you can **always** reach out to [Sean Larkin (@TheLarkInn) on Twitter](https://twitter.com/thelarkinn) or simply submit an issue and a maintainer can help give you guidance!
293
293
 
@@ -715,11 +715,11 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
715
715
  [node-url]: https://nodejs.org
716
716
  [deps]: https://img.shields.io/david/webpack/webpack.svg
717
717
  [deps-url]: https://david-dm.org/webpack/webpack
718
- [tests]: https://img.shields.io/travis/webpack/webpack/master.svg
718
+ [tests]: https://img.shields.io/travis/webpack/webpack/main.svg
719
719
  [tests-url]: https://travis-ci.org/webpack/webpack
720
720
  [prs]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
721
721
  [prs-url]: https://webpack.js.org/contribute/
722
- [builds-url]: https://ci.appveyor.com/project/sokra/webpack/branch/master
722
+ [builds-url]: https://ci.appveyor.com/project/sokra/webpack/branch/main
723
723
  [builds]: https://ci.appveyor.com/api/projects/status/github/webpack/webpack?svg=true
724
724
  [builds2]: https://dev.azure.com/webpack/webpack/_apis/build/status/webpack.webpack
725
725
  [builds2-url]: https://dev.azure.com/webpack/webpack/_build/latest?definitionId=3
package/bin/webpack.js CHANGED
File without changes
@@ -337,6 +337,31 @@ const deprecatedNormalModuleLoaderHook = util.deprecate(
337
337
  "DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK"
338
338
  );
339
339
 
340
+ // TODO webpack 6: remove
341
+ const defineRemovedModuleTemplates = moduleTemplates => {
342
+ Object.defineProperties(moduleTemplates, {
343
+ asset: {
344
+ enumerable: false,
345
+ configurable: false,
346
+ get: () => {
347
+ throw new WebpackError(
348
+ "Compilation.moduleTemplates.asset has been removed"
349
+ );
350
+ }
351
+ },
352
+ webassembly: {
353
+ enumerable: false,
354
+ configurable: false,
355
+ get: () => {
356
+ throw new WebpackError(
357
+ "Compilation.moduleTemplates.webassembly has been removed"
358
+ );
359
+ }
360
+ }
361
+ });
362
+ moduleTemplates = undefined;
363
+ };
364
+
340
365
  const byId = compareSelect(
341
366
  /**
342
367
  * @param {Chunk} c chunk
@@ -861,26 +886,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
861
886
  this.moduleTemplates = {
862
887
  javascript: new ModuleTemplate(this.runtimeTemplate, this)
863
888
  };
864
- Object.defineProperties(this.moduleTemplates, {
865
- asset: {
866
- enumerable: false,
867
- configurable: false,
868
- get() {
869
- throw new WebpackError(
870
- "Compilation.moduleTemplates.asset has been removed"
871
- );
872
- }
873
- },
874
- webassembly: {
875
- enumerable: false,
876
- configurable: false,
877
- get() {
878
- throw new WebpackError(
879
- "Compilation.moduleTemplates.webassembly has been removed"
880
- );
881
- }
882
- }
883
- });
889
+ defineRemovedModuleTemplates(this.moduleTemplates);
884
890
 
885
891
  this.moduleGraph = new ModuleGraph();
886
892
  /** @type {ChunkGraph} */
@@ -1999,6 +2005,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1999
2005
  }
2000
2006
 
2001
2007
  finish(callback) {
2008
+ this.factorizeQueue.clear();
2002
2009
  if (this.profile) {
2003
2010
  this.logger.time("finish module profiles");
2004
2011
  const ParallelismFactorCalculator = require("./util/ParallelismFactorCalculator");
@@ -2233,6 +2240,14 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2233
2240
  * @returns {void}
2234
2241
  */
2235
2242
  seal(callback) {
2243
+ const finalCallback = err => {
2244
+ this.factorizeQueue.clear();
2245
+ this.buildQueue.clear();
2246
+ this.rebuildQueue.clear();
2247
+ this.processDependenciesQueue.clear();
2248
+ this.addModuleQueue.clear();
2249
+ return callback(err);
2250
+ };
2236
2251
  const chunkGraph = new ChunkGraph(this.moduleGraph);
2237
2252
  this.chunkGraph = chunkGraph;
2238
2253
 
@@ -2397,7 +2412,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2397
2412
 
2398
2413
  this.hooks.optimizeTree.callAsync(this.chunks, this.modules, err => {
2399
2414
  if (err) {
2400
- return callback(
2415
+ return finalCallback(
2401
2416
  makeWebpackError(err, "Compilation.hooks.optimizeTree")
2402
2417
  );
2403
2418
  }
@@ -2409,7 +2424,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2409
2424
  this.modules,
2410
2425
  err => {
2411
2426
  if (err) {
2412
- return callback(
2427
+ return finalCallback(
2413
2428
  makeWebpackError(err, "Compilation.hooks.optimizeChunkModules")
2414
2429
  );
2415
2430
  }
@@ -2452,7 +2467,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2452
2467
  this.hooks.beforeCodeGeneration.call();
2453
2468
  this.codeGeneration(err => {
2454
2469
  if (err) {
2455
- return callback(err);
2470
+ return finalCallback(err);
2456
2471
  }
2457
2472
  this.hooks.afterCodeGeneration.call();
2458
2473
  this.logger.timeEnd("code generation");
@@ -2471,7 +2486,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2471
2486
 
2472
2487
  this._runCodeGenerationJobs(codeGenerationJobs, err => {
2473
2488
  if (err) {
2474
- return callback(err);
2489
+ return finalCallback(err);
2475
2490
  }
2476
2491
 
2477
2492
  if (shouldRecord) {
@@ -2491,7 +2506,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2491
2506
  this.logger.time("process assets");
2492
2507
  this.hooks.processAssets.callAsync(this.assets, err => {
2493
2508
  if (err) {
2494
- return callback(
2509
+ return finalCallback(
2495
2510
  makeWebpackError(err, "Compilation.hooks.processAssets")
2496
2511
  );
2497
2512
  }
@@ -2517,12 +2532,12 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2517
2532
  }
2518
2533
  return this.hooks.afterSeal.callAsync(err => {
2519
2534
  if (err) {
2520
- return callback(
2535
+ return finalCallback(
2521
2536
  makeWebpackError(err, "Compilation.hooks.afterSeal")
2522
2537
  );
2523
2538
  }
2524
2539
  this.fileSystemInfo.logStatistics();
2525
- callback();
2540
+ finalCallback();
2526
2541
  });
2527
2542
  });
2528
2543
  };
@@ -2533,7 +2548,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2533
2548
  this.createChunkAssets(err => {
2534
2549
  this.logger.timeEnd("create chunk assets");
2535
2550
  if (err) {
2536
- return callback(err);
2551
+ return finalCallback(err);
2537
2552
  }
2538
2553
  cont();
2539
2554
  });
@@ -31,6 +31,9 @@ const wrapInCondition = (condition, source) => {
31
31
  }
32
32
  };
33
33
 
34
+ /**
35
+ * @typedef {GenerateContext} Context
36
+ */
34
37
  class ConditionalInitFragment extends InitFragment {
35
38
  /**
36
39
  * @param {string|Source} content the source code that will be included as initialization code
@@ -53,16 +56,16 @@ class ConditionalInitFragment extends InitFragment {
53
56
  }
54
57
 
55
58
  /**
56
- * @param {GenerateContext} generateContext context for generate
59
+ * @param {Context} context context
57
60
  * @returns {string|Source} the source code that will be included as initialization code
58
61
  */
59
- getContent(generateContext) {
62
+ getContent(context) {
60
63
  if (this.runtimeCondition === false || !this.content) return "";
61
64
  if (this.runtimeCondition === true) return this.content;
62
- const expr = generateContext.runtimeTemplate.runtimeConditionExpression({
63
- chunkGraph: generateContext.chunkGraph,
64
- runtimeRequirements: generateContext.runtimeRequirements,
65
- runtime: generateContext.runtime,
65
+ const expr = context.runtimeTemplate.runtimeConditionExpression({
66
+ chunkGraph: context.chunkGraph,
67
+ runtimeRequirements: context.runtimeRequirements,
68
+ runtime: context.runtime,
66
69
  runtimeCondition: this.runtimeCondition
67
70
  });
68
71
  if (expr === "true") return this.content;
@@ -70,16 +73,16 @@ class ConditionalInitFragment extends InitFragment {
70
73
  }
71
74
 
72
75
  /**
73
- * @param {GenerateContext} generateContext context for generate
76
+ * @param {Context} context context
74
77
  * @returns {string|Source=} the source code that will be included at the end of the module
75
78
  */
76
- getEndContent(generateContext) {
79
+ getEndContent(context) {
77
80
  if (this.runtimeCondition === false || !this.endContent) return "";
78
81
  if (this.runtimeCondition === true) return this.endContent;
79
- const expr = generateContext.runtimeTemplate.runtimeConditionExpression({
80
- chunkGraph: generateContext.chunkGraph,
81
- runtimeRequirements: generateContext.runtimeRequirements,
82
- runtime: generateContext.runtime,
82
+ const expr = context.runtimeTemplate.runtimeConditionExpression({
83
+ chunkGraph: context.chunkGraph,
84
+ runtimeRequirements: context.runtimeRequirements,
85
+ runtime: context.runtime,
83
86
  runtimeCondition: this.runtimeCondition
84
87
  });
85
88
  if (expr === "true") return this.endContent;
@@ -11,7 +11,8 @@
11
11
  /** @typedef {import("./Dependency")} Dependency */
12
12
  /** @typedef {import("./Dependency").RuntimeSpec} RuntimeSpec */
13
13
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
14
- /** @typedef {import("./InitFragment")} InitFragment */
14
+ /** @typedef {import("./Generator").GenerateContext} GenerateContext */
15
+ /** @template T @typedef {import("./InitFragment")<T>} InitFragment */
15
16
  /** @typedef {import("./Module")} Module */
16
17
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
17
18
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
@@ -25,7 +26,7 @@
25
26
  * @property {Set<string>} runtimeRequirements the requirements for runtime
26
27
  * @property {Module} module current module
27
28
  * @property {RuntimeSpec} runtime current runtimes, for which code is generated
28
- * @property {InitFragment[]} initFragments mutable array of init fragments for the current module
29
+ * @property {InitFragment<GenerateContext>[]} initFragments mutable array of init fragments for the current module
29
30
  * @property {ConcatenationScope=} concatenationScope when in a concatenated module, information about other concatenated modules
30
31
  */
31
32