webpack 5.110.0 → 5.110.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.
Files changed (52) hide show
  1. package/README.md +10 -17
  2. package/lib/ExportsInfo.js +10 -0
  3. package/lib/FileSystemInfo.js +17 -2
  4. package/lib/Generator.js +17 -0
  5. package/lib/NormalModule.js +3 -3
  6. package/lib/RuntimeTemplate.js +423 -430
  7. package/lib/asset/AssetBytesGenerator.js +1 -3
  8. package/lib/asset/AssetGenerator.js +1 -3
  9. package/lib/asset/AssetSourceGenerator.js +1 -3
  10. package/lib/config/defaults.js +6 -0
  11. package/lib/css/CssGenerator.js +1 -3
  12. package/lib/css/CssLoadingRuntimeModule.js +32 -13
  13. package/lib/css/CssModulesPlugin.js +9 -17
  14. package/lib/css/data.js +13 -3
  15. package/lib/css/syntax.js +78 -10
  16. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +10 -4
  17. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
  18. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +48 -3
  19. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +83 -14
  20. package/lib/dependencies/HarmonyImportSideEffectDependency.js +114 -0
  21. package/lib/dependencies/WorkerAndWorkletPlugin.js +1 -0
  22. package/lib/dependencies/WorkerDependency.js +6 -12
  23. package/lib/dependencies/WorkletDependency.js +7 -11
  24. package/lib/esm/ModuleChunkLoadingPlugin.js +6 -9
  25. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -1
  26. package/lib/html/HtmlGenerator.js +1 -1
  27. package/lib/html/HtmlModulesPlugin.js +55 -16
  28. package/lib/html/syntax.js +113 -26
  29. package/lib/javascript/JavascriptGenerator.js +1 -1
  30. package/lib/javascript/JavascriptModulesPlugin.js +3 -10
  31. package/lib/json/JsonGenerator.js +1 -1
  32. package/lib/loaders/LoaderRunner.js +33 -5
  33. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -15
  34. package/lib/optimize/ConcatenatedModule.js +8 -0
  35. package/lib/optimize/ConstExportsPlugin.js +5 -0
  36. package/lib/optimize/InlineExports.js +121 -0
  37. package/lib/optimize/RealContentHashPlugin.js +111 -35
  38. package/lib/prefetch/ResourceHintPlugin.js +6 -12
  39. package/lib/serialization/ObjectMiddleware.js +128 -108
  40. package/lib/typescript/TypeScriptPlugin.js +8 -10
  41. package/lib/util/SourceProcessor.js +24 -8
  42. package/lib/util/createMappings.js +25 -3
  43. package/lib/util/removeBOM.js +82 -1
  44. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +5 -3
  45. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -3
  46. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +3 -1
  47. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +7 -12
  48. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -1
  49. package/lib/web/FetchCompileAsyncWasmPlugin.js +10 -6
  50. package/lib/web/FetchCompileWasmPlugin.js +4 -2
  51. package/package.json +1 -1
  52. package/types.d.ts +77 -10
package/README.md CHANGED
@@ -98,18 +98,18 @@ interface](https://webpack.js.org/plugins/). Most of the features
98
98
  within webpack itself use this plugin interface. This makes webpack very
99
99
  **flexible**.
100
100
 
101
+ Webpack can generate HTML pages and extract CSS files itself, both experimental —
102
+ see what that covers, and what still needs a plugin, for
103
+ [CSS](https://webpack.js.org/guides/native-css/#whats-built-in) and
104
+ [HTML](https://webpack.js.org/guides/native-html/#whats-built-in).
105
+
101
106
  | Name | Status | Install Size | Description |
102
107
  | :---------------------------------------: | :----------------: | :-----------------: | :-------------------------------------------------------------------------------------- |
103
- | [mini-css-extract-plugin][mini-css] | ![mini-css-npm] | ![mini-css-size] | Extracts CSS into separate files. It creates a CSS file per JS file which contains CSS. |
104
108
  | [compression-webpack-plugin][compression] | ![compression-npm] | ![compression-size] | Prepares compressed versions of assets to serve them with Content-Encoding |
105
109
  | [html-bundler-webpack-plugin][bundler] | ![bundler-npm] | ![bundler-size] | Renders a template (EJS, Handlebars, Pug) with referenced source asset files into HTML. |
106
- | [html-webpack-plugin][html-plugin] | ![html-plugin-npm] | ![html-plugin-size] | Simplifies creation of HTML files (`index.html`) to serve your bundles |
107
110
  | [pug-plugin][pug-plugin] | ![pug-plugin-npm] | ![pug-plugin-size] | Renders Pug files to HTML, extracts JS and CSS from sources specified directly in Pug. |
108
111
 
109
112
  [common-npm]: https://img.shields.io/npm/v/webpack.svg
110
- [mini-css]: https://github.com/webpack-contrib/mini-css-extract-plugin
111
- [mini-css-npm]: https://img.shields.io/npm/v/mini-css-extract-plugin.svg
112
- [mini-css-size]: https://packagephobia.com/badge?p=mini-css-extract-plugin
113
113
  [component]: https://github.com/webpack-contrib/component-webpack-plugin
114
114
  [component-npm]: https://img.shields.io/npm/v/component-webpack-plugin.svg
115
115
  [component-size]: https://packagephobia.com/badge?p=component-webpack-plugin
@@ -119,9 +119,6 @@ within webpack itself use this plugin interface. This makes webpack very
119
119
  [bundler]: https://github.com/webdiscus/html-bundler-webpack-plugin
120
120
  [bundler-npm]: https://img.shields.io/npm/v/html-bundler-webpack-plugin.svg
121
121
  [bundler-size]: https://packagephobia.com/badge?p=html-bundler-webpack-plugin
122
- [html-plugin]: https://github.com/jantimon/html-webpack-plugin
123
- [html-plugin-npm]: https://img.shields.io/npm/v/html-webpack-plugin.svg
124
- [html-plugin-size]: https://packagephobia.com/badge?p=html-webpack-plugin
125
122
  [pug-plugin]: https://github.com/webdiscus/pug-plugin
126
123
  [pug-plugin-npm]: https://img.shields.io/npm/v/pug-plugin.svg
127
124
  [pug-plugin-size]: https://packagephobia.com/badge?p=pug-plugin
@@ -135,6 +132,11 @@ loaders](https://webpack.js.org/api/loaders/) using Node.js.
135
132
  Loaders are activated by using `loadername!` prefixes in `require()` statements,
136
133
  or are automatically applied via regex from your webpack configuration.
137
134
 
135
+ JavaScript, JSON and [assets](https://webpack.js.org/guides/asset-modules/) need no
136
+ loader, and [CSS](https://webpack.js.org/guides/native-css/#whats-built-in) and
137
+ [HTML](https://webpack.js.org/guides/native-html/#whats-built-in) have experimental
138
+ built-in support — but preprocessors and template engines keep their loaders.
139
+
138
140
  #### JSON
139
141
 
140
142
  | Name | Status | Install Size | Description |
@@ -163,14 +165,11 @@ or are automatically applied via regex from your webpack configuration.
163
165
 
164
166
  | Name | Status | Install Size | Description |
165
167
  | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------: | :--------------: | :-------------------------------------------------------------------------------------- |
166
- | <a href="https://github.com/webpack-contrib/html-loader"><img width="48" height="48" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/html5/html5-original.svg"></a> | ![html-npm] | ![html-size] | Exports HTML as string, requires references to static resources |
167
168
  | <a href="https://github.com/webdiscus/pug-loader"><img width="48" height="48" src="https://cdn.rawgit.com/pugjs/pug-logo/master/SVG/pug-final-logo-_-colour-128.svg"></a> | ![pug-npm] | ![pug-size] | Compiles Pug to a function or HTML string, useful for use with Vue, React, Angular |
168
169
  | <a href="https://github.com/peerigon/markdown-loader"><img width="48" height="48" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/markdown/markdown-original.svg"></a> | ![md-npm] | ![md-size] | Compiles Markdown to HTML |
169
170
  | <a href="https://github.com/posthtml/posthtml-loader"><img width="48" height="48" src="https://posthtml.github.io/posthtml/logo.svg"></a> | ![posthtml-npm] | ![posthtml-size] | Loads and transforms a HTML file using [PostHTML](https://github.com/posthtml/posthtml) |
170
171
  | <a href="https://github.com/pcardune/handlebars-loader"><img width="48" height="48" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/handlebars/handlebars-original.svg"></a> | ![hbs-npm] | ![hbs-size] | Compiles Handlebars to HTML |
171
172
 
172
- [html-npm]: https://img.shields.io/npm/v/html-loader.svg
173
- [html-size]: https://packagephobia.com/badge?p=html-loader
174
173
  [pug-npm]: https://img.shields.io/npm/v/@webdiscus/pug-loader.svg
175
174
  [pug-size]: https://packagephobia.com/badge?p=@webdiscus/pug-loader
176
175
  [jade-npm]: https://img.shields.io/npm/v/jade-loader.svg
@@ -186,17 +185,11 @@ or are automatically applied via regex from your webpack configuration.
186
185
 
187
186
  | Name | Status | Install Size | Description |
188
187
  | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------: | :-------------: | :----------------------------------------------------------------------- |
189
- | <a href="https://github.com/webpack-contrib/style-loader">`<style>`</a> | ![style-npm] | ![style-size] | Add exports of a module as style to DOM |
190
- | <a href="https://github.com/webpack-contrib/css-loader"><img width="48" height="48" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/css3/css3-original.svg"></a> | ![css-npm] | ![css-size] | Loads CSS file with resolved imports and returns CSS code |
191
188
  | <a href="https://github.com/webpack-contrib/less-loader"><img width="48" height="48" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/less/less-plain-wordmark.svg"></a> | ![less-npm] | ![less-size] | Loads and compiles a LESS file |
192
189
  | <a href="https://github.com/webpack-contrib/sass-loader"><img width="48" height="48" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/sass/sass-original.svg"></a> | ![sass-npm] | ![sass-size] | Loads and compiles a Sass/SCSS file |
193
190
  | <a href="https://github.com/shama/stylus-loader"><img width="48" height="48" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/stylus/stylus-original.svg"></a> | ![stylus-npm] | ![stylus-size] | Loads and compiles a Stylus file |
194
191
  | <a href="https://github.com/postcss/postcss-loader"><img width="48" height="48" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/postcss/postcss-original.svg"></a> | ![postcss-npm] | ![postcss-size] | Loads and transforms a CSS/SSS file using [PostCSS](https://postcss.org) |
195
192
 
196
- [style-npm]: https://img.shields.io/npm/v/style-loader.svg
197
- [style-size]: https://packagephobia.com/badge?p=style-loader
198
- [css-npm]: https://img.shields.io/npm/v/css-loader.svg
199
- [css-size]: https://packagephobia.com/badge?p=css-loader
200
193
  [less-npm]: https://img.shields.io/npm/v/less-loader.svg
201
194
  [less-size]: https://packagephobia.com/badge?p=less-loader
202
195
  [sass-npm]: https://img.shields.io/npm/v/sass-loader.svg
@@ -1747,6 +1747,16 @@ class ExportInfo {
1747
1747
  return result;
1748
1748
  }
1749
1749
 
1750
+ /**
1751
+ * Returns whether resolving the target leads back to this export, which
1752
+ * `getTarget` cannot express as it reports a cycle as "no target".
1753
+ * @param {ModuleGraph} moduleGraph the module graph
1754
+ * @returns {boolean} true, when the reexport chain is circular
1755
+ */
1756
+ hasCircularTarget(moduleGraph) {
1757
+ return this._getTarget(moduleGraph, RETURNS_TRUE, undefined) === CIRCULAR;
1758
+ }
1759
+
1750
1760
  /**
1751
1761
  * Returns the target.
1752
1762
  * @param {ModuleGraph} moduleGraph the module graph
@@ -1207,6 +1207,15 @@ const getManagedItem = (managedPath, path) => {
1207
1207
  return path.slice(0, i);
1208
1208
  };
1209
1209
 
1210
+ /**
1211
+ * The managed directory a `snapshot.managedPaths` RegExp matched. The schema
1212
+ * documents it as matching that directory, so a capture-less pattern is it.
1213
+ * @param {RegExpExecArray} match a match of a managed path RegExp
1214
+ * @returns {string} the managed directory
1215
+ */
1216
+ const getManagedPathFromMatch = (match) =>
1217
+ match[1] === undefined ? match[0] : match[1];
1218
+
1210
1219
  /**
1211
1220
  * Gets resolved timestamp.
1212
1221
  * @template {ContextFileSystemInfoEntry | ContextTimestampAndHash} T
@@ -2663,7 +2672,10 @@ class FileSystemInfo {
2663
2672
  for (const managedPath of this.managedPathsRegExps) {
2664
2673
  const match = managedPath.exec(path);
2665
2674
  if (match) {
2666
- const managedItem = getManagedItem(match[1], path);
2675
+ const managedItem = getManagedItem(
2676
+ getManagedPathFromMatch(match),
2677
+ path
2678
+ );
2667
2679
  if (managedItem) {
2668
2680
  classificationCache.set(path, managedItem);
2669
2681
  managedItems.add(managedItem);
@@ -3921,7 +3933,10 @@ class FileSystemInfo {
3921
3933
  for (const managedPath of this.managedPathsRegExps) {
3922
3934
  const match = managedPath.exec(path);
3923
3935
  if (match) {
3924
- const managedItem = getManagedItem(match[1], path);
3936
+ const managedItem = getManagedItem(
3937
+ getManagedPathFromMatch(match),
3938
+ path
3939
+ );
3925
3940
  if (managedItem) {
3926
3941
  // construct timestampHash from managed info
3927
3942
  return this.managedItemQueue.add(managedItem, (err, info) => {
package/lib/Generator.js CHANGED
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const { JAVASCRIPT_TYPE } = require("./ModuleSourceTypeConstants");
9
+ const memoize = require("./util/memoize");
9
10
 
10
11
  /** @import { Source } from "webpack-sources" */
11
12
  /** @import ChunkGraph from "./ChunkGraph" */
@@ -60,6 +61,8 @@ const { JAVASCRIPT_TYPE } = require("./ModuleSourceTypeConstants");
60
61
  * @property {RuntimeTemplate=} runtimeTemplate
61
62
  */
62
63
 
64
+ const getModuleParseError = memoize(() => require("./errors/ModuleParseError"));
65
+
63
66
  class Generator {
64
67
  /**
65
68
  * Returns generator by type.
@@ -70,6 +73,20 @@ class Generator {
70
73
  return new ByTypeGenerator(map);
71
74
  }
72
75
 
76
+ /**
77
+ * Returns the statement a module that failed to build throws when executed.
78
+ * @param {Error} error the build error
79
+ * @param {string=} parseErrorConstructor constructor for a rejected source, defaults to `SyntaxError` (WebAssembly rejects with `WebAssembly.CompileError` instead)
80
+ * @returns {string} javascript statement
81
+ */
82
+ static throwBuildErrorCode(error, parseErrorConstructor = "SyntaxError") {
83
+ // A source the parser rejected throws what a native load of it would.
84
+ const name =
85
+ error instanceof getModuleParseError() ? parseErrorConstructor : "Error";
86
+
87
+ return `throw new ${name}(${JSON.stringify(error.message)});`;
88
+ }
89
+
73
90
  /* istanbul ignore next */
74
91
  /**
75
92
  * Returns the source types available for this module.
@@ -55,6 +55,8 @@ const parseJson = require("./util/parseJson");
55
55
 
56
56
  const getValidate = memoize(() => require("schema-utils").validate);
57
57
 
58
+ const getGenerator = memoize(() => require("./Generator"));
59
+
58
60
  const getExtractSourceMap = memoize(() => require("./util/extractSourceMap"));
59
61
 
60
62
  const getInvalidDependenciesModuleWarning = memoize(() =>
@@ -1913,9 +1915,7 @@ class NormalModule extends Module {
1913
1915
  getData,
1914
1916
  type
1915
1917
  })
1916
- : new RawSource(
1917
- `throw new Error(${JSON.stringify(this.error.message)});`
1918
- )
1918
+ : new RawSource(getGenerator().throwBuildErrorCode(this.error))
1919
1919
  : generator.generate(this, {
1920
1920
  dependencyTemplates,
1921
1921
  runtimeTemplate,