webpack 5.59.0 → 5.76.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 (236) hide show
  1. package/README.md +22 -24
  2. package/bin/webpack.js +0 -0
  3. package/hot/dev-server.js +17 -4
  4. package/hot/lazy-compilation-node.js +3 -1
  5. package/hot/poll.js +1 -1
  6. package/hot/signal.js +1 -1
  7. package/lib/APIPlugin.js +33 -0
  8. package/lib/BannerPlugin.js +13 -5
  9. package/lib/Cache.js +1 -1
  10. package/lib/CacheFacade.js +4 -11
  11. package/lib/Chunk.js +6 -3
  12. package/lib/ChunkGraph.js +94 -8
  13. package/lib/ChunkGroup.js +1 -1
  14. package/lib/CleanPlugin.js +81 -20
  15. package/lib/Compilation.js +188 -93
  16. package/lib/Compiler.js +87 -18
  17. package/lib/ConstPlugin.js +2 -2
  18. package/lib/ContextModule.js +142 -51
  19. package/lib/ContextModuleFactory.js +65 -25
  20. package/lib/DelegatedModule.js +1 -1
  21. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  22. package/lib/Dependency.js +17 -0
  23. package/lib/DependencyTemplate.js +9 -0
  24. package/lib/DependencyTemplates.js +1 -1
  25. package/lib/DllModule.js +1 -1
  26. package/lib/DllReferencePlugin.js +1 -1
  27. package/lib/EntryOptionPlugin.js +2 -0
  28. package/lib/ErrorHelpers.js +2 -2
  29. package/lib/EvalDevToolModulePlugin.js +16 -1
  30. package/lib/EvalSourceMapDevToolPlugin.js +25 -4
  31. package/lib/ExportsInfo.js +5 -5
  32. package/lib/ExternalModule.js +94 -54
  33. package/lib/ExternalModuleFactoryPlugin.js +5 -5
  34. package/lib/FileSystemInfo.js +124 -58
  35. package/lib/Generator.js +3 -0
  36. package/lib/HookWebpackError.js +1 -1
  37. package/lib/HotModuleReplacementPlugin.js +3 -1
  38. package/lib/LoaderOptionsPlugin.js +1 -1
  39. package/lib/Module.js +28 -4
  40. package/lib/ModuleFilenameHelpers.js +8 -4
  41. package/lib/ModuleHashingError.js +29 -0
  42. package/lib/MultiCompiler.js +1 -1
  43. package/lib/MultiWatching.js +1 -1
  44. package/lib/NodeStuffPlugin.js +13 -3
  45. package/lib/NormalModule.js +51 -33
  46. package/lib/NormalModuleFactory.js +42 -37
  47. package/lib/ProgressPlugin.js +4 -5
  48. package/lib/RawModule.js +1 -1
  49. package/lib/RuntimeGlobals.js +29 -1
  50. package/lib/RuntimeModule.js +1 -1
  51. package/lib/RuntimePlugin.js +84 -1
  52. package/lib/RuntimeTemplate.js +114 -2
  53. package/lib/Template.js +3 -2
  54. package/lib/TemplatedPathPlugin.js +48 -23
  55. package/lib/WatchIgnorePlugin.js +19 -7
  56. package/lib/Watching.js +33 -19
  57. package/lib/WebpackOptionsApply.js +79 -11
  58. package/lib/asset/AssetGenerator.js +228 -71
  59. package/lib/asset/AssetModulesPlugin.js +3 -0
  60. package/lib/asset/AssetParser.js +1 -0
  61. package/lib/asset/AssetSourceGenerator.js +31 -6
  62. package/lib/asset/AssetSourceParser.js +1 -0
  63. package/lib/asset/RawDataUrlModule.js +148 -0
  64. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  65. package/lib/buildChunkGraph.js +38 -7
  66. package/lib/cache/PackFileCacheStrategy.js +15 -8
  67. package/lib/cache/ResolverCachePlugin.js +90 -29
  68. package/lib/cli.js +44 -3
  69. package/lib/config/browserslistTargetHandler.js +41 -6
  70. package/lib/config/defaults.js +123 -19
  71. package/lib/config/normalization.js +10 -2
  72. package/lib/config/target.js +10 -0
  73. package/lib/container/ContainerEntryModule.js +8 -5
  74. package/lib/container/FallbackModule.js +4 -4
  75. package/lib/container/ModuleFederationPlugin.js +2 -0
  76. package/lib/container/RemoteModule.js +4 -2
  77. package/lib/container/RemoteRuntimeModule.js +8 -7
  78. package/lib/css/CssExportsGenerator.js +139 -0
  79. package/lib/css/CssGenerator.js +109 -0
  80. package/lib/css/CssLoadingRuntimeModule.js +442 -0
  81. package/lib/css/CssModulesPlugin.js +462 -0
  82. package/lib/css/CssParser.js +618 -0
  83. package/lib/css/walkCssTokens.js +659 -0
  84. package/lib/debug/ProfilingPlugin.js +24 -21
  85. package/lib/dependencies/AMDRequireDependency.js +6 -6
  86. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  87. package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
  88. package/lib/dependencies/CommonJsImportsParserPlugin.js +344 -61
  89. package/lib/dependencies/CommonJsRequireContextDependency.js +6 -2
  90. package/lib/dependencies/CommonJsRequireDependency.js +2 -1
  91. package/lib/dependencies/ContextDependency.js +16 -2
  92. package/lib/dependencies/ContextDependencyHelpers.js +21 -8
  93. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  94. package/lib/dependencies/ContextElementDependency.js +25 -3
  95. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  96. package/lib/dependencies/CssExportDependency.js +85 -0
  97. package/lib/dependencies/CssImportDependency.js +75 -0
  98. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  99. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  100. package/lib/dependencies/CssUrlDependency.js +132 -0
  101. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  102. package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
  103. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  104. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +127 -0
  105. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
  106. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
  107. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  108. package/lib/dependencies/HarmonyImportDependency.js +23 -0
  109. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
  110. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
  111. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  112. package/lib/dependencies/ImportContextDependency.js +0 -2
  113. package/lib/dependencies/ImportMetaContextDependency.js +35 -0
  114. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
  115. package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
  116. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  117. package/lib/dependencies/ImportParserPlugin.js +35 -29
  118. package/lib/dependencies/JsonExportsDependency.js +17 -21
  119. package/lib/dependencies/LoaderDependency.js +13 -0
  120. package/lib/dependencies/LoaderImportDependency.js +13 -0
  121. package/lib/dependencies/LoaderPlugin.js +4 -2
  122. package/lib/dependencies/ModuleDependency.js +11 -1
  123. package/lib/dependencies/ProvidedDependency.js +31 -8
  124. package/lib/dependencies/RequireContextDependency.js +0 -16
  125. package/lib/dependencies/RequireEnsureDependency.js +2 -2
  126. package/lib/dependencies/RequireResolveContextDependency.js +2 -2
  127. package/lib/dependencies/RequireResolveDependency.js +2 -1
  128. package/lib/dependencies/URLDependency.js +3 -8
  129. package/lib/dependencies/URLPlugin.js +22 -1
  130. package/lib/dependencies/WorkerPlugin.js +2 -0
  131. package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
  132. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  133. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
  134. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  135. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  136. package/lib/hmr/LazyCompilationPlugin.js +54 -26
  137. package/lib/hmr/lazyCompilationBackend.js +51 -12
  138. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  139. package/lib/ids/HashedModuleIdsPlugin.js +11 -14
  140. package/lib/ids/IdHelpers.js +26 -12
  141. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  142. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  143. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  144. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  145. package/lib/index.js +20 -0
  146. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  147. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  148. package/lib/javascript/ChunkHelpers.js +33 -0
  149. package/lib/javascript/JavascriptGenerator.js +1 -0
  150. package/lib/javascript/JavascriptModulesPlugin.js +27 -2
  151. package/lib/javascript/JavascriptParser.js +143 -73
  152. package/lib/javascript/StartupHelpers.js +7 -30
  153. package/lib/json/JsonData.js +8 -0
  154. package/lib/json/JsonParser.js +4 -6
  155. package/lib/library/AssignLibraryPlugin.js +39 -15
  156. package/lib/library/EnableLibraryPlugin.js +11 -0
  157. package/lib/library/UmdLibraryPlugin.js +5 -3
  158. package/lib/node/NodeTargetPlugin.js +3 -0
  159. package/lib/node/NodeWatchFileSystem.js +85 -31
  160. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
  161. package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
  162. package/lib/optimize/ConcatenatedModule.js +62 -26
  163. package/lib/optimize/ModuleConcatenationPlugin.js +26 -4
  164. package/lib/optimize/RealContentHashPlugin.js +45 -15
  165. package/lib/optimize/SplitChunksPlugin.js +8 -1
  166. package/lib/runtime/AsyncModuleRuntimeModule.js +50 -66
  167. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  168. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  169. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  170. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  171. package/lib/runtime/LoadScriptRuntimeModule.js +11 -9
  172. package/lib/runtime/NonceRuntimeModule.js +24 -0
  173. package/lib/schemes/HttpUriPlugin.js +77 -14
  174. package/lib/serialization/FileMiddleware.js +44 -9
  175. package/lib/sharing/ConsumeSharedModule.js +8 -2
  176. package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
  177. package/lib/sharing/ProvideSharedModule.js +4 -2
  178. package/lib/sharing/ProvideSharedPlugin.js +1 -2
  179. package/lib/sharing/ShareRuntimeModule.js +1 -1
  180. package/lib/sharing/utils.js +1 -1
  181. package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
  182. package/lib/stats/DefaultStatsPrinterPlugin.js +90 -25
  183. package/lib/util/ArrayHelpers.js +30 -0
  184. package/lib/util/AsyncQueue.js +1 -1
  185. package/lib/util/compileBooleanMatcher.js +1 -1
  186. package/lib/util/create-schema-validation.js +9 -2
  187. package/lib/util/createHash.js +12 -0
  188. package/lib/util/deprecation.js +10 -2
  189. package/lib/util/deterministicGrouping.js +1 -1
  190. package/lib/util/extractUrlAndGlobal.js +3 -0
  191. package/lib/util/fs.js +11 -0
  192. package/lib/util/hash/BatchedHash.js +7 -4
  193. package/lib/util/hash/md4.js +20 -0
  194. package/lib/util/hash/wasm-hash.js +163 -0
  195. package/lib/util/hash/xxhash64.js +5 -139
  196. package/lib/util/identifier.js +65 -44
  197. package/lib/util/internalSerializables.js +15 -0
  198. package/lib/util/nonNumericOnlyHash.js +22 -0
  199. package/lib/util/semver.js +17 -10
  200. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  201. package/lib/wasm-sync/WebAssemblyParser.js +1 -1
  202. package/lib/web/JsonpChunkLoadingRuntimeModule.js +31 -18
  203. package/lib/webpack.js +10 -3
  204. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  205. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
  206. package/module.d.ts +215 -0
  207. package/package.json +28 -32
  208. package/schemas/WebpackOptions.check.js +1 -1
  209. package/schemas/WebpackOptions.json +321 -30
  210. package/schemas/plugins/BannerPlugin.check.js +1 -1
  211. package/schemas/plugins/BannerPlugin.json +4 -0
  212. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  213. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  214. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  215. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  216. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  217. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  218. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  219. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  220. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  221. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  222. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  223. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  224. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  225. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  226. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  227. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  228. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  229. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  230. package/schemas/plugins/css/CssParserOptions.json +3 -0
  231. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  232. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  233. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  234. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  235. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  236. package/types.d.ts +869 -296
package/README.md CHANGED
@@ -8,17 +8,14 @@
8
8
  [![npm][npm]][npm-url]
9
9
 
10
10
  [![node][node]][node-url]
11
- [![deps][deps]][deps-url]
12
- [![tests][tests]][tests-url]
13
- [![builds][builds]][builds-url]
14
11
  [![builds2][builds2]][builds2-url]
15
12
  [![coverage][cover]][cover-url]
16
13
  [![licenses][licenses]][licenses-url]
17
14
  [![PR's welcome][prs]][prs-url]
18
15
 
19
16
  <br>
20
- <a href="https://dependabot.com/compatibility-score.html?dependency-name=webpack&package-manager=npm_and_yarn&new-version=latest">
21
- <img src="https://api.dependabot.com/badges/compatibility_score?dependency-name=webpack&package-manager=npm_and_yarn&version-scheme=semver&target-version=latest">
17
+ <a href="https://docs.github.com/en/code-security/dependabot/dependabot-security-updates/about-dependabot-security-updates#about-compatibility-scores">
18
+ <img src="https://api.dependabot.com/badges/compatibility_score?dependency-name=webpack&package-manager=npm_and_yarn&previous-version=5.72.1&new-version=5.73.0">
22
19
  </a>
23
20
  <a href="https://npmcharts.com/compare/webpack?minimal=true">
24
21
  <img src="https://img.shields.io/npm/dm/webpack.svg">
@@ -112,6 +109,7 @@ within webpack itself use this plugin interface. This makes webpack very
112
109
  | [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. |
113
110
  | [compression-webpack-plugin][compression] | ![compression-npm] | ![compression-size] | Prepares compressed versions of assets to serve them with Content-Encoding |
114
111
  | [html-webpack-plugin][html-plugin] | ![html-plugin-npm] | ![html-plugin-size] | Simplifies creation of HTML files (`index.html`) to serve your bundles |
112
+ | [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. |
115
113
 
116
114
  [common-npm]: https://img.shields.io/npm/v/webpack.svg
117
115
  [mini-css]: https://github.com/webpack-contrib/mini-css-extract-plugin
@@ -126,6 +124,9 @@ within webpack itself use this plugin interface. This makes webpack very
126
124
  [html-plugin]: https://github.com/jantimon/html-webpack-plugin
127
125
  [html-plugin-npm]: https://img.shields.io/npm/v/html-webpack-plugin.svg
128
126
  [html-plugin-size]: https://packagephobia.com/badge?p=html-webpack-plugin
127
+ [pug-plugin]: https://github.com/webdiscus/pug-plugin
128
+ [pug-plugin-npm]: https://img.shields.io/npm/v/pug-plugin.svg
129
+ [pug-plugin-size]: https://packagephobia.com/badge?p=pug-plugin
129
130
 
130
131
  ### [Loaders](https://webpack.js.org/loaders/)
131
132
 
@@ -157,11 +158,11 @@ or are automatically applied via regex from your webpack configuration.
157
158
 
158
159
  #### Transpiling
159
160
 
160
- | Name | Status | Install Size | Description |
161
- | :--------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------: | :------------: | :------------------------------------------------------------------------------------------------ |
162
- | <a href="https://github.com/babel/babel-loader"><img width="48" height="48" title="babel-loader" src="https://worldvectorlogo.com/logos/babel-10.svg"></a> | ![babel-npm] | ![babel-size] | Loads ES2015+ code and transpiles to ES5 using <a href="https://github.com/babel/babel">Babel</a> |
163
- | <a href="https://github.com/TypeStrong/ts-loader"><img width="48" height="48" src="https://cdn.rawgit.com/Microsoft/TypeScript/master/doc/logo.svg"></a> | ![type-npm] | ![type-size] | Loads TypeScript like JavaScript |
164
- | <a href="https://github.com/webpack-contrib/coffee-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/coffeescript.svg"></a> | ![coffee-npm] | ![coffee-size] | Loads CoffeeScript like JavaScript |
161
+ | Name | Status | Install Size | Description |
162
+ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------: | :------------: | :------------------------------------------------------------------------------------------------ |
163
+ | <a href="https://github.com/babel/babel-loader"><img width="48" height="48" title="babel-loader" src="https://worldvectorlogo.com/logos/babel-10.svg"></a> | ![babel-npm] | ![babel-size] | Loads ES2015+ code and transpiles to ES5 using <a href="https://github.com/babel/babel">Babel</a> |
164
+ | <a href="https://github.com/TypeStrong/ts-loader"><img width="48" height="48" src="https://raw.githubusercontent.com/microsoft/TypeScript-Website/f407e1ae19e5e990d9901ac8064a32a8cc60edf0/packages/typescriptlang-org/static/branding/ts-logo-128.svg"></a> | ![type-npm] | ![type-size] | Loads TypeScript like JavaScript |
165
+ | <a href="https://github.com/webpack-contrib/coffee-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/coffeescript.svg"></a> | ![coffee-npm] | ![coffee-size] | Loads CoffeeScript like JavaScript |
165
166
 
166
167
  [babel-npm]: https://img.shields.io/npm/v/babel-loader.svg
167
168
  [babel-size]: https://packagephobia.com/badge?p=babel-loader
@@ -172,18 +173,21 @@ or are automatically applied via regex from your webpack configuration.
172
173
 
173
174
  #### Templating
174
175
 
175
- | Name | Status | Install Size | Description |
176
- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------: | :--------------: | :-------------------------------------------------------------------------------------- |
177
- | <a href="https://github.com/webpack-contrib/html-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/html5.svg"></a> | ![html-npm] | ![html-size] | Exports HTML as string, requires references to static resources |
178
- | <a href="https://github.com/pugjs/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] | Loads Pug templates and returns a function |
179
- | <a href="https://github.com/peerigon/markdown-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/markdown.svg"></a> | ![md-npm] | ![md-size] | Compiles Markdown to HTML |
180
- | <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) |
181
- | <a href="https://github.com/pcardune/handlebars-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/handlebars-1.svg"></a> | ![hbs-npm] | ![hbs-size] | Compiles Handlebars to HTML |
176
+ | Name | Status | Install Size | Description |
177
+ | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------: | :--------------: | :-------------------------------------------------------------------------------------- |
178
+ | <a href="https://github.com/webpack-contrib/html-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/html5-2.svg"></a> | ![html-npm] | ![html-size] | Exports HTML as string, requires references to static resources |
179
+ | <a href="https://github.com/pugjs/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] | Loads Pug templates and returns a function |
180
+ | <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> | ![pug3-npm] | ![pug3-size] | Compiles Pug to a function or HTML string, useful for use with Vue, React, Angular |
181
+ | <a href="https://github.com/peerigon/markdown-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/markdown.svg"></a> | ![md-npm] | ![md-size] | Compiles Markdown to HTML |
182
+ | <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) |
183
+ | <a href="https://github.com/pcardune/handlebars-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/handlebars-1.svg"></a> | ![hbs-npm] | ![hbs-size] | Compiles Handlebars to HTML |
182
184
 
183
185
  [html-npm]: https://img.shields.io/npm/v/html-loader.svg
184
186
  [html-size]: https://packagephobia.com/badge?p=html-loader
185
187
  [pug-npm]: https://img.shields.io/npm/v/pug-loader.svg
186
188
  [pug-size]: https://packagephobia.com/badge?p=pug-loader
189
+ [pug3-npm]: https://img.shields.io/npm/v/@webdiscus/pug-loader.svg
190
+ [pug3-size]: https://packagephobia.com/badge?p=@webdiscus/pug-loader
187
191
  [jade-npm]: https://img.shields.io/npm/v/jade-loader.svg
188
192
  [jade-size]: https://packagephobia.com/badge?p=jade-loader
189
193
  [md-npm]: https://img.shields.io/npm/v/markdown-loader.svg
@@ -689,7 +693,7 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
689
693
 
690
694
  - [@google](https://github.com/google) for [Google Web Toolkit (GWT)](http://www.gwtproject.org/), which aims to compile Java to JavaScript. It features a similar [Code Splitting](http://www.gwtproject.org/doc/latest/DevGuideCodeSplitting.html) as webpack.
691
695
  - [@medikoo](https://github.com/medikoo) for [modules-webmake](https://github.com/medikoo/modules-webmake), which is a similar project. webpack was born because I wanted Code Splitting for modules-webmake. Interestingly the [Code Splitting issue is still open](https://github.com/medikoo/modules-webmake/issues/7) (thanks also to @Phoscur for the discussion).
692
- - [@substack](https://github.com/substack) for [browserify](http://browserify.org/), which is a similar project and source for many ideas.
696
+ - [@substack](https://github.com/substack) for [browserify](https://browserify.org/), which is a similar project and source for many ideas.
693
697
  - [@jrburke](https://github.com/jrburke) for [require.js](https://requirejs.org/), which is a similar project and source for many ideas.
694
698
  - [@defunctzombie](https://github.com/defunctzombie) for the [browser-field spec](https://github.com/defunctzombie/package-browser-field-spec), which makes modules available for node.js, browserify and webpack.
695
699
  - Every early webpack user, which contributed to webpack by writing issues or PRs. You influenced the direction...
@@ -701,14 +705,8 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
701
705
  [npm-url]: https://npmjs.com/package/webpack
702
706
  [node]: https://img.shields.io/node/v/webpack.svg
703
707
  [node-url]: https://nodejs.org
704
- [deps]: https://img.shields.io/david/webpack/webpack.svg
705
- [deps-url]: https://david-dm.org/webpack/webpack
706
- [tests]: https://img.shields.io/travis/webpack/webpack/main.svg
707
- [tests-url]: https://travis-ci.org/webpack/webpack
708
708
  [prs]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
709
709
  [prs-url]: https://webpack.js.org/contribute/
710
- [builds-url]: https://ci.appveyor.com/project/sokra/webpack/branch/main
711
- [builds]: https://ci.appveyor.com/api/projects/status/github/webpack/webpack?svg=true
712
710
  [builds2]: https://dev.azure.com/webpack/webpack/_apis/build/status/webpack.webpack
713
711
  [builds2-url]: https://dev.azure.com/webpack/webpack/_build/latest?definitionId=3
714
712
  [licenses-url]: https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fwebpack%2Fwebpack?ref=badge_shield
package/bin/webpack.js CHANGED
File without changes
package/hot/dev-server.js CHANGED
@@ -14,12 +14,20 @@ if (module.hot) {
14
14
  .check(true)
15
15
  .then(function (updatedModules) {
16
16
  if (!updatedModules) {
17
- log("warning", "[HMR] Cannot find update. Need to do a full reload!");
17
+ log(
18
+ "warning",
19
+ "[HMR] Cannot find update. " +
20
+ (typeof window !== "undefined"
21
+ ? "Need to do a full reload!"
22
+ : "Please reload manually!")
23
+ );
18
24
  log(
19
25
  "warning",
20
26
  "[HMR] (Probably because of restarting the webpack-dev-server)"
21
27
  );
22
- window.location.reload();
28
+ if (typeof window !== "undefined") {
29
+ window.location.reload();
30
+ }
23
31
  return;
24
32
  }
25
33
 
@@ -38,10 +46,15 @@ if (module.hot) {
38
46
  if (["abort", "fail"].indexOf(status) >= 0) {
39
47
  log(
40
48
  "warning",
41
- "[HMR] Cannot apply update. Need to do a full reload!"
49
+ "[HMR] Cannot apply update. " +
50
+ (typeof window !== "undefined"
51
+ ? "Need to do a full reload!"
52
+ : "Please reload manually!")
42
53
  );
43
54
  log("warning", "[HMR] " + log.formatError(err));
44
- window.location.reload();
55
+ if (typeof window !== "undefined") {
56
+ window.location.reload();
57
+ }
45
58
  } else {
46
59
  log("warning", "[HMR] Update failed: " + log.formatError(err));
47
60
  }
@@ -9,7 +9,9 @@ exports.keepAlive = function (options) {
9
9
  var active = options.active;
10
10
  var module = options.module;
11
11
  var response;
12
- var request = require("http").request(
12
+ var request = (
13
+ urlBase.startsWith("https") ? require("https") : require("http")
14
+ ).request(
13
15
  urlBase + data,
14
16
  {
15
17
  agent: false,
package/hot/poll.js CHANGED
@@ -4,7 +4,7 @@
4
4
  */
5
5
  /*globals __resourceQuery */
6
6
  if (module.hot) {
7
- var hotPollInterval = +__resourceQuery.substr(1) || 10 * 60 * 1000;
7
+ var hotPollInterval = +__resourceQuery.slice(1) || 10 * 60 * 1000;
8
8
  var log = require("./log");
9
9
 
10
10
  var checkForUpdate = function checkForUpdate(fromUpdate) {
package/hot/signal.js CHANGED
@@ -45,7 +45,7 @@ if (module.hot) {
45
45
  });
46
46
  };
47
47
 
48
- process.on(__resourceQuery.substr(1) || "SIGUSR2", function () {
48
+ process.on(__resourceQuery.slice(1) || "SIGUSR2", function () {
49
49
  if (module.hot.status() !== "idle") {
50
50
  log(
51
51
  "warning",
package/lib/APIPlugin.js CHANGED
@@ -201,6 +201,39 @@ class APIPlugin {
201
201
  )
202
202
  .setRange(expr.range)
203
203
  );
204
+
205
+ parser.hooks.expression
206
+ .for("__webpack_module__.id")
207
+ .tap("APIPlugin", expr => {
208
+ parser.state.module.buildInfo.moduleConcatenationBailout =
209
+ "__webpack_module__.id";
210
+ const dep = new ConstDependency(
211
+ parser.state.module.moduleArgument + ".id",
212
+ expr.range,
213
+ [RuntimeGlobals.moduleId]
214
+ );
215
+ dep.loc = expr.loc;
216
+ parser.state.module.addPresentationalDependency(dep);
217
+ return true;
218
+ });
219
+
220
+ parser.hooks.expression
221
+ .for("__webpack_module__")
222
+ .tap("APIPlugin", expr => {
223
+ parser.state.module.buildInfo.moduleConcatenationBailout =
224
+ "__webpack_module__";
225
+ const dep = new ConstDependency(
226
+ parser.state.module.moduleArgument,
227
+ expr.range,
228
+ [RuntimeGlobals.module]
229
+ );
230
+ dep.loc = expr.loc;
231
+ parser.state.module.addPresentationalDependency(dep);
232
+ return true;
233
+ });
234
+ parser.hooks.evaluateTypeof
235
+ .for("__webpack_module__")
236
+ .tap("APIPlugin", evaluateToString("object"));
204
237
  };
205
238
 
206
239
  normalModuleFactory.hooks.parser
@@ -33,7 +33,7 @@ const wrapComment = str => {
33
33
  .split("\n")
34
34
  .join("\n * ")
35
35
  .replace(/\s+\n/g, "\n")
36
- .trimRight()}\n */`;
36
+ .trimEnd()}\n */`;
37
37
  };
38
38
 
39
39
  class BannerPlugin {
@@ -77,6 +77,7 @@ class BannerPlugin {
77
77
  undefined,
78
78
  options
79
79
  );
80
+ const cache = new WeakMap();
80
81
 
81
82
  compiler.hooks.compilation.tap("BannerPlugin", compilation => {
82
83
  compilation.hooks.processAssets.tap(
@@ -102,10 +103,17 @@ class BannerPlugin {
102
103
 
103
104
  const comment = compilation.getPath(banner, data);
104
105
 
105
- compilation.updateAsset(
106
- file,
107
- old => new ConcatSource(comment, "\n", old)
108
- );
106
+ compilation.updateAsset(file, old => {
107
+ let cached = cache.get(old);
108
+ if (!cached || cached.comment !== comment) {
109
+ const source = options.footer
110
+ ? new ConcatSource(old, "\n", comment)
111
+ : new ConcatSource(comment, "\n", old);
112
+ cache.set(old, { source, comment });
113
+ return source;
114
+ }
115
+ return cached.source;
116
+ });
109
117
  }
110
118
  }
111
119
  }
package/lib/Cache.js CHANGED
@@ -21,7 +21,7 @@ const {
21
21
  /**
22
22
  * @template T
23
23
  * @callback CallbackCache
24
- * @param {WebpackError=} err
24
+ * @param {(WebpackError | null)=} err
25
25
  * @param {T=} result
26
26
  * @returns {void}
27
27
  */
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { forEachBail } = require("enhanced-resolve");
8
9
  const asyncLib = require("neo-async");
9
10
  const getLazyHashedEtag = require("./cache/getLazyHashedEtag");
10
11
  const mergeEtags = require("./cache/mergeEtags");
@@ -18,7 +19,7 @@ const mergeEtags = require("./cache/mergeEtags");
18
19
  /**
19
20
  * @template T
20
21
  * @callback CallbackCache
21
- * @param {WebpackError=} err
22
+ * @param {(WebpackError | null)=} err
22
23
  * @param {T=} result
23
24
  * @returns {void}
24
25
  */
@@ -26,7 +27,7 @@ const mergeEtags = require("./cache/mergeEtags");
26
27
  /**
27
28
  * @template T
28
29
  * @callback CallbackNormalErrorCache
29
- * @param {Error=} err
30
+ * @param {(Error | null)=} err
30
31
  * @param {T=} result
31
32
  * @returns {void}
32
33
  */
@@ -46,15 +47,7 @@ class MultiItemCache {
46
47
  * @returns {void}
47
48
  */
48
49
  get(callback) {
49
- const next = i => {
50
- this._items[i].get((err, result) => {
51
- if (err) return callback(err);
52
- if (result !== undefined) return callback(null, result);
53
- if (++i >= this._items.length) return callback();
54
- next(i);
55
- });
56
- };
57
- next(0);
50
+ forEachBail(this._items, (item, callback) => item.get(callback), callback);
58
51
  }
59
52
 
60
53
  /**
package/lib/Chunk.js CHANGED
@@ -63,8 +63,9 @@ let debugId = 1000;
63
63
  class Chunk {
64
64
  /**
65
65
  * @param {string=} name of chunk being created, is optional (for subclasses)
66
+ * @param {boolean} backCompat enable backward-compatibility
66
67
  */
67
- constructor(name) {
68
+ constructor(name, backCompat = true) {
68
69
  /** @type {number | string | null} */
69
70
  this.id = null;
70
71
  /** @type {(number|string)[] | null} */
@@ -79,12 +80,14 @@ class Chunk {
79
80
  this.preventIntegration = false;
80
81
  /** @type {(string | function(PathData, AssetInfo=): string)?} */
81
82
  this.filenameTemplate = undefined;
83
+ /** @type {(string | function(PathData, AssetInfo=): string)?} */
84
+ this.cssFilenameTemplate = undefined;
82
85
  /** @private @type {SortableSet<ChunkGroup>} */
83
86
  this._groups = new SortableSet(undefined, compareChunkGroupsByIndex);
84
87
  /** @type {RuntimeSpec} */
85
88
  this.runtime = undefined;
86
89
  /** @type {Set<string>} */
87
- this.files = new ChunkFilesSet();
90
+ this.files = backCompat ? new ChunkFilesSet() : new Set();
88
91
  /** @type {Set<string>} */
89
92
  this.auxiliaryFiles = new Set();
90
93
  /** @type {boolean} */
@@ -687,7 +690,7 @@ class Chunk {
687
690
  for (const childGroup of group.childrenIterable) {
688
691
  for (const key of Object.keys(childGroup.options)) {
689
692
  if (key.endsWith("Order")) {
690
- const name = key.substr(0, key.length - "Order".length);
693
+ const name = key.slice(0, key.length - "Order".length);
691
694
  let list = lists.get(name);
692
695
  if (list === undefined) {
693
696
  list = [];
package/lib/ChunkGraph.js CHANGED
@@ -46,6 +46,7 @@ const compareModuleIterables = compareIterables(compareModulesByIdentifier);
46
46
 
47
47
  /** @typedef {(c: Chunk, chunkGraph: ChunkGraph) => boolean} ChunkFilterPredicate */
48
48
  /** @typedef {(m: Module) => boolean} ModuleFilterPredicate */
49
+ /** @typedef {[Module, Entrypoint | undefined]} EntryModuleWithChunkGroup */
49
50
 
50
51
  /**
51
52
  * @typedef {Object} ChunkSizeOptions
@@ -84,14 +85,17 @@ const getModuleRuntimes = chunks => {
84
85
  };
85
86
 
86
87
  /**
87
- * @param {SortableSet<Module>} set the set
88
- * @returns {Map<string, SortableSet<Module>>} modules by source type
88
+ * @param {WeakMap<Module, Set<string>> | undefined} sourceTypesByModule sourceTypesByModule
89
+ * @returns {function (SortableSet<Module>): Map<string, SortableSet<Module>>} modules by source type
89
90
  */
90
- const modulesBySourceType = set => {
91
+ const modulesBySourceType = sourceTypesByModule => set => {
91
92
  /** @type {Map<string, SortableSet<Module>>} */
92
93
  const map = new Map();
93
94
  for (const module of set) {
94
- for (const sourceType of module.getSourceTypes()) {
95
+ const sourceTypes =
96
+ (sourceTypesByModule && sourceTypesByModule.get(module)) ||
97
+ module.getSourceTypes();
98
+ for (const sourceType of sourceTypes) {
95
99
  let innerSet = map.get(sourceType);
96
100
  if (innerSet === undefined) {
97
101
  innerSet = new SortableSet();
@@ -109,6 +113,7 @@ const modulesBySourceType = set => {
109
113
  }
110
114
  return map;
111
115
  };
116
+ const defaultModulesBySourceType = modulesBySourceType(undefined);
112
117
 
113
118
  /** @type {WeakMap<Function, any>} */
114
119
  const createOrderedArrayFunctionMap = new WeakMap();
@@ -200,6 +205,8 @@ class ChunkGraphChunk {
200
205
  constructor() {
201
206
  /** @type {SortableSet<Module>} */
202
207
  this.modules = new SortableSet();
208
+ /** @type {WeakMap<Module, Set<string>> | undefined} */
209
+ this.sourceTypesByModule = undefined;
203
210
  /** @type {Map<Module, Entrypoint>} */
204
211
  this.entryModules = new Map();
205
212
  /** @type {SortableSet<RuntimeModule>} */
@@ -212,6 +219,8 @@ class ChunkGraphChunk {
212
219
  this.runtimeRequirements = undefined;
213
220
  /** @type {Set<string>} */
214
221
  this.runtimeRequirementsInTree = new Set();
222
+
223
+ this._modulesBySourceType = defaultModulesBySourceType;
215
224
  }
216
225
  }
217
226
 
@@ -314,6 +323,8 @@ class ChunkGraph {
314
323
  const cgm = this._getChunkGraphModule(module);
315
324
  const cgc = this._getChunkGraphChunk(chunk);
316
325
  cgc.modules.delete(module);
326
+ // No need to invalidate cgc._modulesBySourceType because we modified cgc.modules anyway
327
+ if (cgc.sourceTypesByModule) cgc.sourceTypesByModule.delete(module);
317
328
  cgm.chunks.delete(chunk);
318
329
  }
319
330
 
@@ -567,11 +578,84 @@ class ChunkGraph {
567
578
  getChunkModulesIterableBySourceType(chunk, sourceType) {
568
579
  const cgc = this._getChunkGraphChunk(chunk);
569
580
  const modulesWithSourceType = cgc.modules
570
- .getFromUnorderedCache(modulesBySourceType)
581
+ .getFromUnorderedCache(cgc._modulesBySourceType)
571
582
  .get(sourceType);
572
583
  return modulesWithSourceType;
573
584
  }
574
585
 
586
+ /**
587
+ * @param {Chunk} chunk chunk
588
+ * @param {Module} module chunk module
589
+ * @param {Set<string>} sourceTypes source types
590
+ */
591
+ setChunkModuleSourceTypes(chunk, module, sourceTypes) {
592
+ const cgc = this._getChunkGraphChunk(chunk);
593
+ if (cgc.sourceTypesByModule === undefined) {
594
+ cgc.sourceTypesByModule = new WeakMap();
595
+ }
596
+ cgc.sourceTypesByModule.set(module, sourceTypes);
597
+ // Update cgc._modulesBySourceType to invalidate the cache
598
+ cgc._modulesBySourceType = modulesBySourceType(cgc.sourceTypesByModule);
599
+ }
600
+
601
+ /**
602
+ * @param {Chunk} chunk chunk
603
+ * @param {Module} module chunk module
604
+ * @returns {Set<string>} source types
605
+ */
606
+ getChunkModuleSourceTypes(chunk, module) {
607
+ const cgc = this._getChunkGraphChunk(chunk);
608
+ if (cgc.sourceTypesByModule === undefined) {
609
+ return module.getSourceTypes();
610
+ }
611
+ return cgc.sourceTypesByModule.get(module) || module.getSourceTypes();
612
+ }
613
+
614
+ /**
615
+ * @param {Module} module module
616
+ * @returns {Set<string>} source types
617
+ */
618
+ getModuleSourceTypes(module) {
619
+ return (
620
+ this._getOverwrittenModuleSourceTypes(module) || module.getSourceTypes()
621
+ );
622
+ }
623
+
624
+ /**
625
+ * @param {Module} module module
626
+ * @returns {Set<string> | undefined} source types
627
+ */
628
+ _getOverwrittenModuleSourceTypes(module) {
629
+ let newSet = false;
630
+ let sourceTypes;
631
+ for (const chunk of this.getModuleChunksIterable(module)) {
632
+ const cgc = this._getChunkGraphChunk(chunk);
633
+ if (cgc.sourceTypesByModule === undefined) return;
634
+ const st = cgc.sourceTypesByModule.get(module);
635
+ if (st === undefined) return;
636
+ if (!sourceTypes) {
637
+ sourceTypes = st;
638
+ continue;
639
+ } else if (!newSet) {
640
+ for (const type of st) {
641
+ if (!newSet) {
642
+ if (!sourceTypes.has(type)) {
643
+ newSet = true;
644
+ sourceTypes = new Set(sourceTypes);
645
+ sourceTypes.add(type);
646
+ }
647
+ } else {
648
+ sourceTypes.add(type);
649
+ }
650
+ }
651
+ } else {
652
+ for (const type of st) sourceTypes.add(type);
653
+ }
654
+ }
655
+
656
+ return sourceTypes;
657
+ }
658
+
575
659
  /**
576
660
  * @param {Chunk} chunk the chunk
577
661
  * @param {function(Module, Module): -1|0|1} comparator comparator function
@@ -592,7 +676,7 @@ class ChunkGraph {
592
676
  getOrderedChunkModulesIterableBySourceType(chunk, sourceType, comparator) {
593
677
  const cgc = this._getChunkGraphChunk(chunk);
594
678
  const modulesWithSourceType = cgc.modules
595
- .getFromUnorderedCache(modulesBySourceType)
679
+ .getFromUnorderedCache(cgc._modulesBySourceType)
596
680
  .get(sourceType);
597
681
  if (modulesWithSourceType === undefined) return undefined;
598
682
  modulesWithSourceType.sortWith(comparator);
@@ -1180,8 +1264,6 @@ class ChunkGraph {
1180
1264
  return cgc.dependentHashModules;
1181
1265
  }
1182
1266
 
1183
- /** @typedef {[Module, Entrypoint | undefined]} EntryModuleWithChunkGroup */
1184
-
1185
1267
  /**
1186
1268
  * @param {Chunk} chunk the chunk
1187
1269
  * @returns {Iterable<EntryModuleWithChunkGroup>} iterable of modules (do not modify)
@@ -1474,6 +1556,10 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1474
1556
  const graphHash = cgm.graphHashes.provide(runtime, () => {
1475
1557
  const hash = createHash(this._hashFunction);
1476
1558
  hash.update(`${cgm.id}${this.moduleGraph.isAsync(module)}`);
1559
+ const sourceTypes = this._getOverwrittenModuleSourceTypes(module);
1560
+ if (sourceTypes !== undefined) {
1561
+ for (const type of sourceTypes) hash.update(type);
1562
+ }
1477
1563
  this.moduleGraph.getExportsInfo(module).updateHash(hash, runtime);
1478
1564
  return BigInt(`0x${/** @type {string} */ (hash.digest("hex"))}`);
1479
1565
  });
package/lib/ChunkGroup.js CHANGED
@@ -486,7 +486,7 @@ class ChunkGroup {
486
486
  for (const childGroup of this._children) {
487
487
  for (const key of Object.keys(childGroup.options)) {
488
488
  if (key.endsWith("Order")) {
489
- const name = key.substr(0, key.length - "Order".length);
489
+ const name = key.slice(0, key.length - "Order".length);
490
490
  let list = lists.get(name);
491
491
  if (list === undefined) {
492
492
  lists.set(name, (list = []));