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
@@ -0,0 +1,109 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Sergey Melyukov @smelukov
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const { ReplaceSource } = require("webpack-sources");
9
+ const Generator = require("../Generator");
10
+ const InitFragment = require("../InitFragment");
11
+ const RuntimeGlobals = require("../RuntimeGlobals");
12
+
13
+ /** @typedef {import("webpack-sources").Source} Source */
14
+ /** @typedef {import("../Dependency")} Dependency */
15
+ /** @typedef {import("../Generator").GenerateContext} GenerateContext */
16
+ /** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
17
+ /** @typedef {import("../NormalModule")} NormalModule */
18
+ /** @typedef {import("../util/Hash")} Hash */
19
+
20
+ const TYPES = new Set(["css"]);
21
+
22
+ class CssGenerator extends Generator {
23
+ constructor() {
24
+ super();
25
+ }
26
+
27
+ /**
28
+ * @param {NormalModule} module module for which the code should be generated
29
+ * @param {GenerateContext} generateContext context for generate
30
+ * @returns {Source} generated code
31
+ */
32
+ generate(module, generateContext) {
33
+ const originalSource = module.originalSource();
34
+ const source = new ReplaceSource(originalSource);
35
+ const initFragments = [];
36
+ const cssExports = new Map();
37
+
38
+ generateContext.runtimeRequirements.add(RuntimeGlobals.hasCssModules);
39
+
40
+ const templateContext = {
41
+ runtimeTemplate: generateContext.runtimeTemplate,
42
+ dependencyTemplates: generateContext.dependencyTemplates,
43
+ moduleGraph: generateContext.moduleGraph,
44
+ chunkGraph: generateContext.chunkGraph,
45
+ module,
46
+ runtime: generateContext.runtime,
47
+ runtimeRequirements: generateContext.runtimeRequirements,
48
+ concatenationScope: generateContext.concatenationScope,
49
+ codeGenerationResults: generateContext.codeGenerationResults,
50
+ initFragments,
51
+ cssExports
52
+ };
53
+
54
+ const handleDependency = dependency => {
55
+ const constructor = /** @type {new (...args: any[]) => Dependency} */ (
56
+ dependency.constructor
57
+ );
58
+ const template = generateContext.dependencyTemplates.get(constructor);
59
+ if (!template) {
60
+ throw new Error(
61
+ "No template for dependency: " + dependency.constructor.name
62
+ );
63
+ }
64
+
65
+ template.apply(dependency, source, templateContext);
66
+ };
67
+ module.dependencies.forEach(handleDependency);
68
+ if (module.presentationalDependencies !== undefined)
69
+ module.presentationalDependencies.forEach(handleDependency);
70
+
71
+ if (cssExports.size > 0) {
72
+ const data = generateContext.getData();
73
+ data.set("css-exports", cssExports);
74
+ }
75
+
76
+ return InitFragment.addToSource(source, initFragments, generateContext);
77
+ }
78
+
79
+ /**
80
+ * @param {NormalModule} module fresh module
81
+ * @returns {Set<string>} available types (do not mutate)
82
+ */
83
+ getTypes(module) {
84
+ return TYPES;
85
+ }
86
+
87
+ /**
88
+ * @param {NormalModule} module the module
89
+ * @param {string=} type source type
90
+ * @returns {number} estimate size of the module
91
+ */
92
+ getSize(module, type) {
93
+ const originalSource = module.originalSource();
94
+
95
+ if (!originalSource) {
96
+ return 0;
97
+ }
98
+
99
+ return originalSource.size();
100
+ }
101
+
102
+ /**
103
+ * @param {Hash} hash hash that will be modified
104
+ * @param {UpdateHashContext} updateHashContext context for updating hash
105
+ */
106
+ updateHash(hash, { module }) {}
107
+ }
108
+
109
+ module.exports = CssGenerator;
@@ -0,0 +1,442 @@
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 { SyncWaterfallHook } = require("tapable");
9
+ const Compilation = require("../Compilation");
10
+ const RuntimeGlobals = require("../RuntimeGlobals");
11
+ const RuntimeModule = require("../RuntimeModule");
12
+ const Template = require("../Template");
13
+ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
14
+ const { chunkHasCss } = require("./CssModulesPlugin");
15
+
16
+ /** @typedef {import("../Chunk")} Chunk */
17
+
18
+ /**
19
+ * @typedef {Object} JsonpCompilationPluginHooks
20
+ * @property {SyncWaterfallHook<[string, Chunk]>} createStylesheet
21
+ */
22
+
23
+ /** @type {WeakMap<Compilation, JsonpCompilationPluginHooks>} */
24
+ const compilationHooksMap = new WeakMap();
25
+
26
+ class CssLoadingRuntimeModule extends RuntimeModule {
27
+ /**
28
+ * @param {Compilation} compilation the compilation
29
+ * @returns {JsonpCompilationPluginHooks} hooks
30
+ */
31
+ static getCompilationHooks(compilation) {
32
+ if (!(compilation instanceof Compilation)) {
33
+ throw new TypeError(
34
+ "The 'compilation' argument must be an instance of Compilation"
35
+ );
36
+ }
37
+ let hooks = compilationHooksMap.get(compilation);
38
+ if (hooks === undefined) {
39
+ hooks = {
40
+ createStylesheet: new SyncWaterfallHook(["source", "chunk"])
41
+ };
42
+ compilationHooksMap.set(compilation, hooks);
43
+ }
44
+ return hooks;
45
+ }
46
+
47
+ constructor(runtimeRequirements, runtimeOptions) {
48
+ super("css loading", 10);
49
+
50
+ this._runtimeRequirements = runtimeRequirements;
51
+ this.runtimeOptions = runtimeOptions;
52
+ }
53
+
54
+ /**
55
+ * @returns {string} runtime code
56
+ */
57
+ generate() {
58
+ const { compilation, chunk, _runtimeRequirements } = this;
59
+ const {
60
+ chunkGraph,
61
+ runtimeTemplate,
62
+ outputOptions: {
63
+ crossOriginLoading,
64
+ uniqueName,
65
+ chunkLoadTimeout: loadTimeout
66
+ }
67
+ } = compilation;
68
+ const fn = RuntimeGlobals.ensureChunkHandlers;
69
+ const conditionMap = chunkGraph.getChunkConditionMap(
70
+ chunk,
71
+ (chunk, chunkGraph) =>
72
+ !!chunkGraph.getChunkModulesIterableBySourceType(chunk, "css")
73
+ );
74
+ const hasCssMatcher = compileBooleanMatcher(conditionMap);
75
+
76
+ const withLoading =
77
+ _runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers) &&
78
+ hasCssMatcher !== false;
79
+ const withHmr = _runtimeRequirements.has(
80
+ RuntimeGlobals.hmrDownloadUpdateHandlers
81
+ );
82
+ const initialChunkIdsWithCss = new Set();
83
+ const initialChunkIdsWithoutCss = new Set();
84
+ for (const c of chunk.getAllInitialChunks()) {
85
+ (chunkHasCss(c, chunkGraph)
86
+ ? initialChunkIdsWithCss
87
+ : initialChunkIdsWithoutCss
88
+ ).add(c.id);
89
+ }
90
+
91
+ if (!withLoading && !withHmr && initialChunkIdsWithCss.size === 0) {
92
+ return null;
93
+ }
94
+
95
+ const { createStylesheet } =
96
+ CssLoadingRuntimeModule.getCompilationHooks(compilation);
97
+
98
+ const stateExpression = withHmr
99
+ ? `${RuntimeGlobals.hmrRuntimeStatePrefix}_css`
100
+ : undefined;
101
+
102
+ const code = Template.asString([
103
+ "link = document.createElement('link');",
104
+ uniqueName
105
+ ? 'link.setAttribute("data-webpack", uniqueName + ":" + key);'
106
+ : "",
107
+ "link.setAttribute(loadingAttribute, 1);",
108
+ 'link.rel = "stylesheet";',
109
+ "link.href = url;",
110
+ crossOriginLoading
111
+ ? crossOriginLoading === "use-credentials"
112
+ ? 'link.crossOrigin = "use-credentials";'
113
+ : Template.asString([
114
+ "if (link.src.indexOf(window.location.origin + '/') !== 0) {",
115
+ Template.indent(
116
+ `link.crossOrigin = ${JSON.stringify(crossOriginLoading)};`
117
+ ),
118
+ "}"
119
+ ])
120
+ : ""
121
+ ]);
122
+
123
+ const cc = str => str.charCodeAt(0);
124
+
125
+ return Template.asString([
126
+ "// object to store loaded and loading chunks",
127
+ "// undefined = chunk not loaded, null = chunk preloaded/prefetched",
128
+ "// [resolve, reject, Promise] = chunk loading, 0 = chunk loaded",
129
+ `var installedChunks = ${
130
+ stateExpression ? `${stateExpression} = ${stateExpression} || ` : ""
131
+ }{${Array.from(
132
+ initialChunkIdsWithoutCss,
133
+ id => `${JSON.stringify(id)}:0`
134
+ ).join(",")}};`,
135
+ "",
136
+ uniqueName
137
+ ? `var uniqueName = ${JSON.stringify(
138
+ runtimeTemplate.outputOptions.uniqueName
139
+ )};`
140
+ : "// data-webpack is not used as build has no uniqueName",
141
+ `var loadCssChunkData = ${runtimeTemplate.basicFunction(
142
+ "target, link, chunkId",
143
+ [
144
+ `var data, token = "", token2, exports = {}, exportsWithId = [], exportsWithDashes = [], ${
145
+ withHmr ? "moduleIds = [], " : ""
146
+ }i = 0, cc = 1;`,
147
+ "try { if(!link) link = loadStylesheet(chunkId); data = link.sheet.cssRules; data = data[data.length - 1].style; } catch(e) { data = getComputedStyle(document.head); }",
148
+ `data = data.getPropertyValue(${
149
+ uniqueName
150
+ ? runtimeTemplate.concatenation(
151
+ "--webpack-",
152
+ { expr: "uniqueName" },
153
+ "-",
154
+ { expr: "chunkId" }
155
+ )
156
+ : runtimeTemplate.concatenation("--webpack-", { expr: "chunkId" })
157
+ });`,
158
+ "if(!data) return [];",
159
+ "for(; cc; i++) {",
160
+ Template.indent([
161
+ "cc = data.charCodeAt(i);",
162
+ `if(cc == ${cc("(")}) { token2 = token; token = ""; }`,
163
+ `else if(cc == ${cc(
164
+ ")"
165
+ )}) { exports[token2.replace(/^_/, "")] = token.replace(/^_/, ""); token = ""; }`,
166
+ `else if(cc == ${cc("/")} || cc == ${cc(
167
+ "%"
168
+ )}) { token = token.replace(/^_/, ""); exports[token] = token; exportsWithId.push(token); if(cc == ${cc(
169
+ "%"
170
+ )}) exportsWithDashes.push(token); token = ""; }`,
171
+ `else if(!cc || cc == ${cc(
172
+ ","
173
+ )}) { token = token.replace(/^_/, ""); exportsWithId.forEach(${runtimeTemplate.expressionFunction(
174
+ `exports[x] = ${
175
+ uniqueName
176
+ ? runtimeTemplate.concatenation(
177
+ { expr: "uniqueName" },
178
+ "-",
179
+ { expr: "token" },
180
+ "-",
181
+ { expr: "exports[x]" }
182
+ )
183
+ : runtimeTemplate.concatenation({ expr: "token" }, "-", {
184
+ expr: "exports[x]"
185
+ })
186
+ }`,
187
+ "x"
188
+ )}); exportsWithDashes.forEach(${runtimeTemplate.expressionFunction(
189
+ `exports[x] = "--" + exports[x]`,
190
+ "x"
191
+ )}); ${
192
+ RuntimeGlobals.makeNamespaceObject
193
+ }(exports); target[token] = (${runtimeTemplate.basicFunction(
194
+ "exports, module",
195
+ `module.exports = exports;`
196
+ )}).bind(null, exports); ${
197
+ withHmr ? "moduleIds.push(token); " : ""
198
+ }token = ""; exports = {}; exportsWithId.length = 0; }`,
199
+ `else if(cc == ${cc("\\")}) { token += data[++i] }`,
200
+ `else { token += data[i]; }`
201
+ ]),
202
+ "}",
203
+ `${
204
+ withHmr ? `if(target == ${RuntimeGlobals.moduleFactories}) ` : ""
205
+ }installedChunks[chunkId] = 0;`,
206
+ withHmr ? "return moduleIds;" : ""
207
+ ]
208
+ )}`,
209
+ 'var loadingAttribute = "data-webpack-loading";',
210
+ `var loadStylesheet = ${runtimeTemplate.basicFunction(
211
+ "chunkId, url, done" + (withHmr ? ", hmr" : ""),
212
+ [
213
+ 'var link, needAttach, key = "chunk-" + chunkId;',
214
+ withHmr ? "if(!hmr) {" : "",
215
+ 'var links = document.getElementsByTagName("link");',
216
+ "for(var i = 0; i < links.length; i++) {",
217
+ Template.indent([
218
+ "var l = links[i];",
219
+ `if(l.rel == "stylesheet" && (${
220
+ withHmr
221
+ ? 'l.href.startsWith(url) || l.getAttribute("href").startsWith(url)'
222
+ : 'l.href == url || l.getAttribute("href") == url'
223
+ }${
224
+ uniqueName
225
+ ? ' || l.getAttribute("data-webpack") == uniqueName + ":" + key'
226
+ : ""
227
+ })) { link = l; break; }`
228
+ ]),
229
+ "}",
230
+ "if(!done) return link;",
231
+ withHmr ? "}" : "",
232
+ "if(!link) {",
233
+ Template.indent([
234
+ "needAttach = true;",
235
+ createStylesheet.call(code, this.chunk)
236
+ ]),
237
+ "}",
238
+ `var onLinkComplete = ${runtimeTemplate.basicFunction(
239
+ "prev, event",
240
+ Template.asString([
241
+ "link.onerror = link.onload = null;",
242
+ "link.removeAttribute(loadingAttribute);",
243
+ "clearTimeout(timeout);",
244
+ 'if(event && event.type != "load") link.parentNode.removeChild(link)',
245
+ "done(event);",
246
+ "if(prev) return prev(event);"
247
+ ])
248
+ )};`,
249
+ "if(link.getAttribute(loadingAttribute)) {",
250
+ Template.indent([
251
+ `var timeout = setTimeout(onLinkComplete.bind(null, undefined, { type: 'timeout', target: link }), ${loadTimeout});`,
252
+ "link.onerror = onLinkComplete.bind(null, link.onerror);",
253
+ "link.onload = onLinkComplete.bind(null, link.onload);"
254
+ ]),
255
+ "} else onLinkComplete(undefined, { type: 'load', target: link });", // We assume any existing stylesheet is render blocking
256
+ withHmr ? "hmr ? document.head.insertBefore(link, hmr) :" : "",
257
+ "needAttach && document.head.appendChild(link);",
258
+ "return link;"
259
+ ]
260
+ )};`,
261
+ initialChunkIdsWithCss.size > 2
262
+ ? `${JSON.stringify(
263
+ Array.from(initialChunkIdsWithCss)
264
+ )}.forEach(loadCssChunkData.bind(null, ${
265
+ RuntimeGlobals.moduleFactories
266
+ }, 0));`
267
+ : initialChunkIdsWithCss.size > 0
268
+ ? `${Array.from(
269
+ initialChunkIdsWithCss,
270
+ id =>
271
+ `loadCssChunkData(${
272
+ RuntimeGlobals.moduleFactories
273
+ }, 0, ${JSON.stringify(id)});`
274
+ ).join("")}`
275
+ : "// no initial css",
276
+ "",
277
+ withLoading
278
+ ? Template.asString([
279
+ `${fn}.css = ${runtimeTemplate.basicFunction("chunkId, promises", [
280
+ "// css chunk loading",
281
+ `var installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
282
+ 'if(installedChunkData !== 0) { // 0 means "already installed".',
283
+ Template.indent([
284
+ "",
285
+ '// a Promise means "currently loading".',
286
+ "if(installedChunkData) {",
287
+ Template.indent(["promises.push(installedChunkData[2]);"]),
288
+ "} else {",
289
+ Template.indent([
290
+ hasCssMatcher === true
291
+ ? "if(true) { // all chunks have CSS"
292
+ : `if(${hasCssMatcher("chunkId")}) {`,
293
+ Template.indent([
294
+ "// setup Promise in chunk cache",
295
+ `var promise = new Promise(${runtimeTemplate.expressionFunction(
296
+ `installedChunkData = installedChunks[chunkId] = [resolve, reject]`,
297
+ "resolve, reject"
298
+ )});`,
299
+ "promises.push(installedChunkData[2] = promise);",
300
+ "",
301
+ "// start chunk loading",
302
+ `var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
303
+ "// create error before stack unwound to get useful stacktrace later",
304
+ "var error = new Error();",
305
+ `var loadingEnded = ${runtimeTemplate.basicFunction(
306
+ "event",
307
+ [
308
+ `if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId)) {`,
309
+ Template.indent([
310
+ "installedChunkData = installedChunks[chunkId];",
311
+ "if(installedChunkData !== 0) installedChunks[chunkId] = undefined;",
312
+ "if(installedChunkData) {",
313
+ Template.indent([
314
+ 'if(event.type !== "load") {',
315
+ Template.indent([
316
+ "var errorType = event && event.type;",
317
+ "var realSrc = event && event.target && event.target.src;",
318
+ "error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')';",
319
+ "error.name = 'ChunkLoadError';",
320
+ "error.type = errorType;",
321
+ "error.request = realSrc;",
322
+ "installedChunkData[1](error);"
323
+ ]),
324
+ "} else {",
325
+ Template.indent([
326
+ `loadCssChunkData(${RuntimeGlobals.moduleFactories}, link, chunkId);`,
327
+ "installedChunkData[0]();"
328
+ ]),
329
+ "}"
330
+ ]),
331
+ "}"
332
+ ]),
333
+ "}"
334
+ ]
335
+ )};`,
336
+ "var link = loadStylesheet(chunkId, url, loadingEnded);"
337
+ ]),
338
+ "} else installedChunks[chunkId] = 0;"
339
+ ]),
340
+ "}"
341
+ ]),
342
+ "}"
343
+ ])};`
344
+ ])
345
+ : "// no chunk loading",
346
+ "",
347
+ withHmr
348
+ ? Template.asString([
349
+ "var oldTags = [];",
350
+ "var newTags = [];",
351
+ `var applyHandler = ${runtimeTemplate.basicFunction("options", [
352
+ `return { dispose: ${runtimeTemplate.basicFunction(
353
+ "",
354
+ []
355
+ )}, apply: ${runtimeTemplate.basicFunction("", [
356
+ "var moduleIds = [];",
357
+ `newTags.forEach(${runtimeTemplate.expressionFunction(
358
+ "info[1].sheet.disabled = false",
359
+ "info"
360
+ )});`,
361
+ "while(oldTags.length) {",
362
+ Template.indent([
363
+ "var oldTag = oldTags.pop();",
364
+ "if(oldTag.parentNode) oldTag.parentNode.removeChild(oldTag);"
365
+ ]),
366
+ "}",
367
+ "while(newTags.length) {",
368
+ Template.indent([
369
+ `var info = newTags.pop();`,
370
+ `var chunkModuleIds = loadCssChunkData(${RuntimeGlobals.moduleFactories}, info[1], info[0]);`,
371
+ `chunkModuleIds.forEach(${runtimeTemplate.expressionFunction(
372
+ "moduleIds.push(id)",
373
+ "id"
374
+ )});`
375
+ ]),
376
+ "}",
377
+ "return moduleIds;"
378
+ ])} };`
379
+ ])}`,
380
+ `var cssTextKey = ${runtimeTemplate.returningFunction(
381
+ `Array.from(link.sheet.cssRules, ${runtimeTemplate.returningFunction(
382
+ "r.cssText",
383
+ "r"
384
+ )}).join()`,
385
+ "link"
386
+ )}`,
387
+ `${
388
+ RuntimeGlobals.hmrDownloadUpdateHandlers
389
+ }.css = ${runtimeTemplate.basicFunction(
390
+ "chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList",
391
+ [
392
+ "applyHandlers.push(applyHandler);",
393
+ `chunkIds.forEach(${runtimeTemplate.basicFunction("chunkId", [
394
+ `var filename = ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
395
+ `var url = ${RuntimeGlobals.publicPath} + filename;`,
396
+ "var oldTag = loadStylesheet(chunkId, url);",
397
+ "if(!oldTag) return;",
398
+ `promises.push(new Promise(${runtimeTemplate.basicFunction(
399
+ "resolve, reject",
400
+ [
401
+ `var link = loadStylesheet(chunkId, url + (url.indexOf("?") < 0 ? "?" : "&") + "hmr=" + Date.now(), ${runtimeTemplate.basicFunction(
402
+ "event",
403
+ [
404
+ 'if(event.type !== "load") {',
405
+ Template.indent([
406
+ "var errorType = event && event.type;",
407
+ "var realSrc = event && event.target && event.target.src;",
408
+ "error.message = 'Loading css hot update chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')';",
409
+ "error.name = 'ChunkLoadError';",
410
+ "error.type = errorType;",
411
+ "error.request = realSrc;",
412
+ "reject(error);"
413
+ ]),
414
+ "} else {",
415
+ Template.indent([
416
+ "try { if(cssTextKey(oldTag) == cssTextKey(link)) { if(link.parentNode) link.parentNode.removeChild(link); return resolve(); } } catch(e) {}",
417
+ "var factories = {};",
418
+ "loadCssChunkData(factories, link, chunkId);",
419
+ `Object.keys(factories).forEach(${runtimeTemplate.expressionFunction(
420
+ "updatedModulesList.push(id)",
421
+ "id"
422
+ )})`,
423
+ "link.sheet.disabled = true;",
424
+ "oldTags.push(oldTag);",
425
+ "newTags.push([chunkId, link]);",
426
+ "resolve();"
427
+ ]),
428
+ "}"
429
+ ]
430
+ )}, oldTag);`
431
+ ]
432
+ )}));`
433
+ ])});`
434
+ ]
435
+ )}`
436
+ ])
437
+ : "// no hmr"
438
+ ]);
439
+ }
440
+ }
441
+
442
+ module.exports = CssLoadingRuntimeModule;