webpack 5.90.3 → 5.92.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 (257) hide show
  1. package/README.md +5 -5
  2. package/bin/webpack.js +6 -3
  3. package/lib/APIPlugin.js +14 -6
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/BannerPlugin.js +3 -1
  6. package/lib/Cache.js +8 -2
  7. package/lib/CacheFacade.js +3 -3
  8. package/lib/Chunk.js +7 -4
  9. package/lib/ChunkGraph.js +52 -25
  10. package/lib/ChunkGroup.js +23 -17
  11. package/lib/CleanPlugin.js +8 -6
  12. package/lib/Compilation.js +295 -120
  13. package/lib/Compiler.js +223 -87
  14. package/lib/ConcatenationScope.js +3 -3
  15. package/lib/ConditionalInitFragment.js +4 -5
  16. package/lib/ContextModule.js +95 -41
  17. package/lib/ContextModuleFactory.js +4 -2
  18. package/lib/ContextReplacementPlugin.js +3 -2
  19. package/lib/DefinePlugin.js +18 -6
  20. package/lib/Dependency.js +12 -10
  21. package/lib/DependencyTemplate.js +17 -7
  22. package/lib/DllModule.js +1 -0
  23. package/lib/DllReferencePlugin.js +7 -3
  24. package/lib/EntryOptionPlugin.js +4 -1
  25. package/lib/EntryPlugin.js +6 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/EvalDevToolModulePlugin.js +11 -0
  28. package/lib/ExportsInfo.js +23 -8
  29. package/lib/ExternalModule.js +160 -35
  30. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  31. package/lib/FileSystemInfo.js +69 -42
  32. package/lib/FlagDependencyExportsPlugin.js +21 -7
  33. package/lib/Generator.js +4 -4
  34. package/lib/HookWebpackError.js +2 -2
  35. package/lib/HotModuleReplacementPlugin.js +108 -45
  36. package/lib/IgnorePlugin.js +4 -1
  37. package/lib/InitFragment.js +5 -3
  38. package/lib/LibManifestPlugin.js +17 -9
  39. package/lib/Module.js +41 -14
  40. package/lib/ModuleFactory.js +3 -3
  41. package/lib/ModuleFilenameHelpers.js +30 -17
  42. package/lib/ModuleGraph.js +60 -31
  43. package/lib/ModuleGraphConnection.js +2 -1
  44. package/lib/MultiCompiler.js +62 -9
  45. package/lib/NodeStuffPlugin.js +14 -3
  46. package/lib/NormalModule.js +13 -13
  47. package/lib/NormalModuleFactory.js +18 -9
  48. package/lib/NormalModuleReplacementPlugin.js +5 -1
  49. package/lib/Parser.js +1 -1
  50. package/lib/PlatformPlugin.js +39 -0
  51. package/lib/ProgressPlugin.js +1 -1
  52. package/lib/ProvidePlugin.js +3 -1
  53. package/lib/RawModule.js +2 -1
  54. package/lib/RecordIdsPlugin.js +4 -4
  55. package/lib/ResolverFactory.js +6 -4
  56. package/lib/RuntimeModule.js +4 -4
  57. package/lib/RuntimePlugin.js +1 -0
  58. package/lib/RuntimeTemplate.js +124 -52
  59. package/lib/SourceMapDevToolPlugin.js +4 -1
  60. package/lib/Stats.js +11 -4
  61. package/lib/Template.js +5 -5
  62. package/lib/TemplatedPathPlugin.js +48 -7
  63. package/lib/Watching.js +67 -60
  64. package/lib/WebpackError.js +6 -6
  65. package/lib/WebpackOptionsApply.js +18 -5
  66. package/lib/asset/AssetGenerator.js +15 -0
  67. package/lib/asset/RawDataUrlModule.js +3 -1
  68. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  69. package/lib/buildChunkGraph.js +120 -67
  70. package/lib/cache/IdleFileCachePlugin.js +8 -3
  71. package/lib/cache/MemoryCachePlugin.js +1 -1
  72. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  73. package/lib/cache/PackFileCacheStrategy.js +51 -18
  74. package/lib/cache/ResolverCachePlugin.js +22 -14
  75. package/lib/cache/getLazyHashedEtag.js +2 -2
  76. package/lib/cli.js +5 -5
  77. package/lib/config/browserslistTargetHandler.js +7 -1
  78. package/lib/config/defaults.js +108 -34
  79. package/lib/config/normalization.js +3 -1
  80. package/lib/config/target.js +18 -11
  81. package/lib/container/ContainerEntryDependency.js +2 -1
  82. package/lib/container/ContainerEntryModule.js +4 -2
  83. package/lib/container/ContainerPlugin.js +14 -10
  84. package/lib/container/FallbackModule.js +1 -1
  85. package/lib/container/RemoteRuntimeModule.js +12 -3
  86. package/lib/css/CssExportsGenerator.js +68 -25
  87. package/lib/css/CssGenerator.js +34 -6
  88. package/lib/css/CssLoadingRuntimeModule.js +217 -98
  89. package/lib/css/CssModulesPlugin.js +238 -107
  90. package/lib/css/CssParser.js +24 -15
  91. package/lib/css/walkCssTokens.js +1 -1
  92. package/lib/debug/ProfilingPlugin.js +28 -3
  93. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  94. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  95. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  96. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  97. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  98. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  99. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  100. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  101. package/lib/dependencies/ContextElementDependency.js +8 -1
  102. package/lib/dependencies/CssExportDependency.js +2 -2
  103. package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
  104. package/lib/dependencies/CssUrlDependency.js +10 -7
  105. package/lib/dependencies/ExportsInfoDependency.js +5 -4
  106. package/lib/dependencies/ExternalModuleDependency.js +4 -2
  107. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  108. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  109. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  110. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  111. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  112. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  113. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  114. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +70 -19
  115. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  116. package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
  117. package/lib/dependencies/ImportDependency.js +9 -2
  118. package/lib/dependencies/ImportEagerDependency.js +4 -2
  119. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  120. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  121. package/lib/dependencies/ImportMetaPlugin.js +1 -1
  122. package/lib/dependencies/ImportParserPlugin.js +15 -5
  123. package/lib/dependencies/ImportWeakDependency.js +4 -2
  124. package/lib/dependencies/LoaderDependency.js +2 -1
  125. package/lib/dependencies/LoaderImportDependency.js +2 -1
  126. package/lib/dependencies/LoaderPlugin.js +2 -2
  127. package/lib/dependencies/ModuleDependency.js +4 -5
  128. package/lib/dependencies/PureExpressionDependency.js +64 -47
  129. package/lib/dependencies/RequireContextPlugin.js +1 -1
  130. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  131. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  132. package/lib/dependencies/URLDependency.js +7 -4
  133. package/lib/dependencies/WorkerDependency.js +1 -1
  134. package/lib/dependencies/WorkerPlugin.js +2 -1
  135. package/lib/dependencies/getFunctionExpression.js +3 -1
  136. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
  137. package/lib/hmr/LazyCompilationPlugin.js +2 -2
  138. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
  139. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  140. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  141. package/lib/ids/IdHelpers.js +6 -6
  142. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  143. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  144. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  145. package/lib/index.js +11 -0
  146. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  147. package/lib/javascript/ChunkHelpers.js +2 -2
  148. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  149. package/lib/javascript/JavascriptGenerator.js +0 -1
  150. package/lib/javascript/JavascriptModulesPlugin.js +174 -17
  151. package/lib/javascript/JavascriptParser.js +204 -71
  152. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  153. package/lib/javascript/StartupHelpers.js +22 -5
  154. package/lib/library/AbstractLibraryPlugin.js +2 -2
  155. package/lib/library/AmdLibraryPlugin.js +2 -2
  156. package/lib/library/AssignLibraryPlugin.js +3 -3
  157. package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
  158. package/lib/library/JsonpLibraryPlugin.js +2 -2
  159. package/lib/library/ModuleLibraryPlugin.js +2 -2
  160. package/lib/library/SystemLibraryPlugin.js +2 -2
  161. package/lib/library/UmdLibraryPlugin.js +33 -12
  162. package/lib/logging/Logger.js +27 -2
  163. package/lib/logging/createConsoleLogger.js +13 -9
  164. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  165. package/lib/node/NodeEnvironmentPlugin.js +14 -8
  166. package/lib/node/NodeTemplatePlugin.js +1 -1
  167. package/lib/node/NodeWatchFileSystem.js +37 -26
  168. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  169. package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
  170. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  171. package/lib/node/nodeConsole.js +24 -1
  172. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  173. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  174. package/lib/optimize/ConcatenatedModule.js +140 -121
  175. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  176. package/lib/optimize/InnerGraph.js +8 -3
  177. package/lib/optimize/InnerGraphPlugin.js +36 -13
  178. package/lib/optimize/LimitChunkCountPlugin.js +1 -2
  179. package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
  180. package/lib/optimize/RealContentHashPlugin.js +3 -3
  181. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  182. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  183. package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
  184. package/lib/optimize/SplitChunksPlugin.js +10 -10
  185. package/lib/performance/SizeLimitsPlugin.js +13 -2
  186. package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
  187. package/lib/rules/RuleSetCompiler.js +9 -7
  188. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  189. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  190. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  191. package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
  192. package/lib/schemes/HttpUriPlugin.js +1 -1
  193. package/lib/serialization/BinaryMiddleware.js +4 -4
  194. package/lib/serialization/FileMiddleware.js +4 -3
  195. package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
  196. package/lib/serialization/ObjectMiddleware.js +8 -5
  197. package/lib/serialization/PlainObjectSerializer.js +2 -2
  198. package/lib/serialization/Serializer.js +19 -0
  199. package/lib/serialization/SerializerMiddleware.js +2 -2
  200. package/lib/serialization/SingleItemMiddleware.js +2 -2
  201. package/lib/serialization/types.js +1 -1
  202. package/lib/sharing/ConsumeSharedModule.js +2 -2
  203. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  204. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  205. package/lib/sharing/ProvideSharedPlugin.js +13 -6
  206. package/lib/sharing/resolveMatchedConfigs.js +3 -3
  207. package/lib/sharing/utils.js +13 -6
  208. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
  209. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  210. package/lib/stats/StatsFactory.js +2 -2
  211. package/lib/stats/StatsPrinter.js +6 -6
  212. package/lib/util/ArrayQueue.js +14 -21
  213. package/lib/util/AsyncQueue.js +1 -1
  214. package/lib/util/Queue.js +8 -2
  215. package/lib/util/SortableSet.js +16 -4
  216. package/lib/util/StackedCacheMap.js +26 -0
  217. package/lib/util/TupleQueue.js +8 -2
  218. package/lib/util/WeakTupleMap.js +57 -13
  219. package/lib/util/binarySearchBounds.js +1 -1
  220. package/lib/util/cleverMerge.js +26 -13
  221. package/lib/util/comparators.js +37 -15
  222. package/lib/util/conventions.js +129 -0
  223. package/lib/util/createHash.js +3 -5
  224. package/lib/util/deprecation.js +3 -3
  225. package/lib/util/deterministicGrouping.js +2 -2
  226. package/lib/util/findGraphRoots.js +1 -1
  227. package/lib/util/fs.js +383 -69
  228. package/lib/util/hash/BatchedHash.js +3 -0
  229. package/lib/util/hash/xxhash64.js +2 -2
  230. package/lib/util/identifier.js +5 -5
  231. package/lib/util/mergeScope.js +79 -0
  232. package/lib/util/runtime.js +2 -17
  233. package/lib/util/semver.js +3 -0
  234. package/lib/util/smartGrouping.js +3 -3
  235. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
  236. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  237. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  238. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  239. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
  240. package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
  241. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  242. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  243. package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
  244. package/lib/web/FetchCompileWasmPlugin.js +1 -1
  245. package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
  246. package/lib/webpack.js +19 -6
  247. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  248. package/package.json +40 -39
  249. package/schemas/WebpackOptions.check.js +1 -1
  250. package/schemas/WebpackOptions.json +97 -8
  251. package/schemas/plugins/BannerPlugin.check.js +1 -1
  252. package/schemas/plugins/BannerPlugin.json +5 -1
  253. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  254. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  255. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  256. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  257. package/types.d.ts +1826 -639
@@ -10,9 +10,14 @@ const { UsageState } = require("../ExportsInfo");
10
10
  const Generator = require("../Generator");
11
11
  const RuntimeGlobals = require("../RuntimeGlobals");
12
12
  const Template = require("../Template");
13
+ const { cssExportConvention } = require("../util/conventions");
13
14
 
14
15
  /** @typedef {import("webpack-sources").Source} Source */
16
+ /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
17
+ /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
15
18
  /** @typedef {import("../Dependency")} Dependency */
19
+ /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
20
+ /** @typedef {import("../DependencyTemplate").CssExportsData} CssExportsData */
16
21
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
17
22
  /** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
18
23
  /** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
@@ -27,12 +32,39 @@ const Template = require("../Template");
27
32
  const TYPES = new Set(["javascript"]);
28
33
 
29
34
  class CssExportsGenerator extends Generator {
30
- constructor() {
35
+ /**
36
+ * @param {CssGeneratorExportsConvention | undefined} convention the convention of the exports name
37
+ * @param {CssGeneratorLocalIdentName | undefined} localIdentName css export local ident name
38
+ * @param {boolean} esModule whether to use ES modules syntax
39
+ */
40
+ constructor(convention, localIdentName, esModule) {
31
41
  super();
42
+ /** @type {CssGeneratorExportsConvention | undefined} */
43
+ this.convention = convention;
44
+ /** @type {CssGeneratorLocalIdentName | undefined} */
45
+ this.localIdentName = localIdentName;
46
+ /** @type {boolean} */
47
+ this.esModule = esModule;
32
48
  }
33
49
 
34
- // TODO add getConcatenationBailoutReason to allow concatenation
35
- // but how to make it have a module id
50
+ /**
51
+ * @param {NormalModule} module module for which the bailout reason should be determined
52
+ * @param {ConcatenationBailoutReasonContext} context context
53
+ * @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
54
+ */
55
+ getConcatenationBailoutReason(module, context) {
56
+ if (!this.esModule) {
57
+ return "Module is not an ECMAScript module";
58
+ }
59
+ // TODO webpack 6: remove /\[moduleid\]/.test
60
+ if (
61
+ /\[id\]/.test(this.localIdentName) ||
62
+ /\[moduleid\]/.test(this.localIdentName)
63
+ ) {
64
+ return "The localIdentName includes moduleId ([id] or [moduleid])";
65
+ }
66
+ return undefined;
67
+ }
36
68
 
37
69
  /**
38
70
  * @param {NormalModule} module module for which the code should be generated
@@ -43,13 +75,18 @@ class CssExportsGenerator extends Generator {
43
75
  const source = new ReplaceSource(new RawSource(""));
44
76
  /** @type {InitFragment<TODO>[]} */
45
77
  const initFragments = [];
46
- const cssExports = new Map();
78
+ /** @type {CssExportsData} */
79
+ const cssExportsData = {
80
+ esModule: this.esModule,
81
+ exports: new Map()
82
+ };
47
83
 
48
84
  generateContext.runtimeRequirements.add(RuntimeGlobals.module);
49
85
 
50
86
  let chunkInitFragments;
51
87
  const runtimeRequirements = new Set();
52
88
 
89
+ /** @type {DependencyTemplateContext} */
53
90
  const templateContext = {
54
91
  runtimeTemplate: generateContext.runtimeTemplate,
55
92
  dependencyTemplates: generateContext.dependencyTemplates,
@@ -61,7 +98,7 @@ class CssExportsGenerator extends Generator {
61
98
  concatenationScope: generateContext.concatenationScope,
62
99
  codeGenerationResults: generateContext.codeGenerationResults,
63
100
  initFragments,
64
- cssExports,
101
+ cssExportsData,
65
102
  get chunkInitFragments() {
66
103
  if (!chunkInitFragments) {
67
104
  const data = generateContext.getData();
@@ -97,39 +134,45 @@ class CssExportsGenerator extends Generator {
97
134
  if (generateContext.concatenationScope) {
98
135
  const source = new ConcatSource();
99
136
  const usedIdentifiers = new Set();
100
- for (const [k, v] of cssExports) {
101
- let identifier = Template.toIdentifier(k);
102
- let i = 0;
103
- while (usedIdentifiers.has(identifier)) {
104
- identifier = Template.toIdentifier(k + i);
137
+ for (const [name, v] of cssExportsData.exports) {
138
+ for (let k of cssExportConvention(name, this.convention)) {
139
+ let identifier = Template.toIdentifier(k);
140
+ let i = 0;
141
+ while (usedIdentifiers.has(identifier)) {
142
+ identifier = Template.toIdentifier(k + i);
143
+ }
144
+ usedIdentifiers.add(identifier);
145
+ generateContext.concatenationScope.registerExport(k, identifier);
146
+ source.add(
147
+ `${
148
+ generateContext.runtimeTemplate.supportsConst() ? "const" : "var"
149
+ } ${identifier} = ${JSON.stringify(v)};\n`
150
+ );
105
151
  }
106
- usedIdentifiers.add(identifier);
107
- generateContext.concatenationScope.registerExport(k, identifier);
108
- source.add(
109
- `${
110
- generateContext.runtimeTemplate.supportsConst ? "const" : "var"
111
- } ${identifier} = ${JSON.stringify(v)};\n`
112
- );
113
152
  }
114
153
  return source;
115
154
  } else {
116
- const otherUsed =
155
+ const needNsObj =
156
+ this.esModule &&
117
157
  generateContext.moduleGraph
118
158
  .getExportsInfo(module)
119
159
  .otherExportsInfo.getUsed(generateContext.runtime) !==
120
- UsageState.Unused;
121
- if (otherUsed) {
160
+ UsageState.Unused;
161
+ if (needNsObj) {
122
162
  generateContext.runtimeRequirements.add(
123
163
  RuntimeGlobals.makeNamespaceObject
124
164
  );
125
165
  }
166
+ const newExports = [];
167
+ for (let [k, v] of cssExportsData.exports) {
168
+ for (let name of cssExportConvention(k, this.convention)) {
169
+ newExports.push(`\t${JSON.stringify(name)}: ${JSON.stringify(v)}`);
170
+ }
171
+ }
126
172
  return new RawSource(
127
- `${otherUsed ? `${RuntimeGlobals.makeNamespaceObject}(` : ""}${
173
+ `${needNsObj ? `${RuntimeGlobals.makeNamespaceObject}(` : ""}${
128
174
  module.moduleArgument
129
- }.exports = {\n${Array.from(
130
- cssExports,
131
- ([k, v]) => `\t${JSON.stringify(k)}: ${JSON.stringify(v)}`
132
- ).join(",\n")}\n}${otherUsed ? ")" : ""};`
175
+ }.exports = {\n${newExports.join(",\n")}\n}${needNsObj ? ")" : ""};`
133
176
  );
134
177
  }
135
178
  }
@@ -9,9 +9,14 @@ const { ReplaceSource } = require("webpack-sources");
9
9
  const Generator = require("../Generator");
10
10
  const InitFragment = require("../InitFragment");
11
11
  const RuntimeGlobals = require("../RuntimeGlobals");
12
+ const { cssExportConvention } = require("../util/conventions");
12
13
 
13
14
  /** @typedef {import("webpack-sources").Source} Source */
15
+ /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
16
+ /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
14
17
  /** @typedef {import("../Dependency")} Dependency */
18
+ /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
19
+ /** @typedef {import("../DependencyTemplate").CssExportsData} CssExportsData */
15
20
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
16
21
  /** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
17
22
  /** @typedef {import("../NormalModule")} NormalModule */
@@ -20,8 +25,19 @@ const RuntimeGlobals = require("../RuntimeGlobals");
20
25
  const TYPES = new Set(["css"]);
21
26
 
22
27
  class CssGenerator extends Generator {
23
- constructor() {
28
+ /**
29
+ * @param {CssGeneratorExportsConvention | undefined} convention the convention of the exports name
30
+ * @param {CssGeneratorLocalIdentName | undefined} localIdentName css export local ident name
31
+ * @param {boolean} esModule whether to use ES modules syntax
32
+ */
33
+ constructor(convention, localIdentName, esModule) {
24
34
  super();
35
+ /** @type {CssGeneratorExportsConvention | undefined} */
36
+ this.convention = convention;
37
+ /** @type {CssGeneratorLocalIdentName | undefined} */
38
+ this.localIdentName = localIdentName;
39
+ /** @type {boolean} */
40
+ this.esModule = esModule;
25
41
  }
26
42
 
27
43
  /**
@@ -34,11 +50,16 @@ class CssGenerator extends Generator {
34
50
  const source = new ReplaceSource(originalSource);
35
51
  /** @type {InitFragment[]} */
36
52
  const initFragments = [];
37
- const cssExports = new Map();
53
+ /** @type {CssExportsData} */
54
+ const cssExportsData = {
55
+ esModule: this.esModule,
56
+ exports: new Map()
57
+ };
38
58
 
39
59
  generateContext.runtimeRequirements.add(RuntimeGlobals.hasCssModules);
40
60
 
41
61
  let chunkInitFragments;
62
+ /** @type {DependencyTemplateContext} */
42
63
  const templateContext = {
43
64
  runtimeTemplate: generateContext.runtimeTemplate,
44
65
  dependencyTemplates: generateContext.dependencyTemplates,
@@ -50,7 +71,7 @@ class CssGenerator extends Generator {
50
71
  concatenationScope: generateContext.concatenationScope,
51
72
  codeGenerationResults: generateContext.codeGenerationResults,
52
73
  initFragments,
53
- cssExports,
74
+ cssExportsData,
54
75
  get chunkInitFragments() {
55
76
  if (!chunkInitFragments) {
56
77
  const data = generateContext.getData();
@@ -85,10 +106,17 @@ class CssGenerator extends Generator {
85
106
  if (module.presentationalDependencies !== undefined)
86
107
  module.presentationalDependencies.forEach(handleDependency);
87
108
 
88
- if (cssExports.size > 0) {
89
- const data = generateContext.getData();
90
- data.set("css-exports", cssExports);
109
+ if (cssExportsData.exports.size > 0) {
110
+ const newExports = new Map();
111
+ for (let [name, v] of cssExportsData.exports) {
112
+ for (let newName of cssExportConvention(name, this.convention)) {
113
+ newExports.set(newName, v);
114
+ }
115
+ }
116
+ cssExportsData.exports = newExports;
91
117
  }
118
+ const data = generateContext.getData();
119
+ data.set("css-exports", cssExportsData);
92
120
 
93
121
  return InitFragment.addToSource(source, initFragments, generateContext);
94
122
  }
@@ -16,19 +16,22 @@ const { chunkHasCss } = require("./CssModulesPlugin");
16
16
  /** @typedef {import("../Chunk")} Chunk */
17
17
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
18
18
  /** @typedef {import("../Compilation").RuntimeRequirementsContext} RuntimeRequirementsContext */
19
+ /** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
19
20
 
20
21
  /**
21
- * @typedef {Object} JsonpCompilationPluginHooks
22
+ * @typedef {object} CssLoadingRuntimeModulePluginHooks
22
23
  * @property {SyncWaterfallHook<[string, Chunk]>} createStylesheet
24
+ * @property {SyncWaterfallHook<[string, Chunk]>} linkPreload
25
+ * @property {SyncWaterfallHook<[string, Chunk]>} linkPrefetch
23
26
  */
24
27
 
25
- /** @type {WeakMap<Compilation, JsonpCompilationPluginHooks>} */
28
+ /** @type {WeakMap<Compilation, CssLoadingRuntimeModulePluginHooks>} */
26
29
  const compilationHooksMap = new WeakMap();
27
30
 
28
31
  class CssLoadingRuntimeModule extends RuntimeModule {
29
32
  /**
30
33
  * @param {Compilation} compilation the compilation
31
- * @returns {JsonpCompilationPluginHooks} hooks
34
+ * @returns {CssLoadingRuntimeModulePluginHooks} hooks
32
35
  */
33
36
  static getCompilationHooks(compilation) {
34
37
  if (!(compilation instanceof Compilation)) {
@@ -39,7 +42,9 @@ class CssLoadingRuntimeModule extends RuntimeModule {
39
42
  let hooks = compilationHooksMap.get(compilation);
40
43
  if (hooks === undefined) {
41
44
  hooks = {
42
- createStylesheet: new SyncWaterfallHook(["source", "chunk"])
45
+ createStylesheet: new SyncWaterfallHook(["source", "chunk"]),
46
+ linkPreload: new SyncWaterfallHook(["source", "chunk"]),
47
+ linkPrefetch: new SyncWaterfallHook(["source", "chunk"])
43
48
  };
44
49
  compilationHooksMap.set(compilation, hooks);
45
50
  }
@@ -47,7 +52,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
47
52
  }
48
53
 
49
54
  /**
50
- * @param {Set<string>} runtimeRequirements runtime requirements
55
+ * @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
51
56
  */
52
57
  constructor(runtimeRequirements) {
53
58
  super("css loading", 10);
@@ -59,16 +64,19 @@ class CssLoadingRuntimeModule extends RuntimeModule {
59
64
  * @returns {string | null} runtime code
60
65
  */
61
66
  generate() {
62
- const { compilation, chunk, _runtimeRequirements } = this;
67
+ const { _runtimeRequirements } = this;
68
+ const compilation = /** @type {Compilation} */ (this.compilation);
69
+ const chunk = /** @type {Chunk} */ (this.chunk);
63
70
  const {
64
71
  chunkGraph,
65
72
  runtimeTemplate,
66
73
  outputOptions: {
67
74
  crossOriginLoading,
68
75
  uniqueName,
69
- chunkLoadTimeout: loadTimeout
76
+ chunkLoadTimeout: loadTimeout,
77
+ cssHeadDataCompression: withCompression
70
78
  }
71
- } = /** @type {Compilation} */ (compilation);
79
+ } = compilation;
72
80
  const fn = RuntimeGlobals.ensureChunkHandlers;
73
81
  const conditionMap = chunkGraph.getChunkConditionMap(
74
82
  /** @type {Chunk} */ (chunk),
@@ -85,6 +93,12 @@ class CssLoadingRuntimeModule extends RuntimeModule {
85
93
  const withLoading =
86
94
  _runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers) &&
87
95
  hasCssMatcher !== false;
96
+ const withPrefetch = this._runtimeRequirements.has(
97
+ RuntimeGlobals.prefetchChunkHandlers
98
+ );
99
+ const withPreload = this._runtimeRequirements.has(
100
+ RuntimeGlobals.preloadChunkHandlers
101
+ );
88
102
  /** @type {boolean} */
89
103
  const withHmr = _runtimeRequirements.has(
90
104
  RuntimeGlobals.hmrDownloadUpdateHandlers
@@ -104,19 +118,39 @@ class CssLoadingRuntimeModule extends RuntimeModule {
104
118
  return null;
105
119
  }
106
120
 
107
- const { createStylesheet } = CssLoadingRuntimeModule.getCompilationHooks(
108
- /** @type {Compilation} */ (compilation)
121
+ const { linkPreload, linkPrefetch } =
122
+ CssLoadingRuntimeModule.getCompilationHooks(compilation);
123
+
124
+ const withFetchPriority = _runtimeRequirements.has(
125
+ RuntimeGlobals.hasFetchPriority
109
126
  );
110
127
 
128
+ const { createStylesheet } =
129
+ CssLoadingRuntimeModule.getCompilationHooks(compilation);
130
+
111
131
  const stateExpression = withHmr
112
132
  ? `${RuntimeGlobals.hmrRuntimeStatePrefix}_css`
113
133
  : undefined;
114
134
 
115
135
  const code = Template.asString([
116
136
  "link = document.createElement('link');",
137
+ `if (${RuntimeGlobals.scriptNonce}) {`,
138
+ Template.indent(
139
+ `link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
140
+ ),
141
+ "}",
117
142
  uniqueName
118
143
  ? 'link.setAttribute("data-webpack", uniqueName + ":" + key);'
119
144
  : "",
145
+ withFetchPriority
146
+ ? Template.asString([
147
+ "if(fetchPriority) {",
148
+ Template.indent(
149
+ 'link.setAttribute("fetchpriority", fetchPriority);'
150
+ ),
151
+ "}"
152
+ ])
153
+ : "",
120
154
  "link.setAttribute(loadingAttribute, 1);",
121
155
  'link.rel = "stylesheet";',
122
156
  "link.href = url;",
@@ -163,9 +197,9 @@ class CssLoadingRuntimeModule extends RuntimeModule {
163
197
  `var loadCssChunkData = ${runtimeTemplate.basicFunction(
164
198
  "target, link, chunkId",
165
199
  [
166
- `var data, token = "", token2, exports = {}, exportsWithId = [], exportsWithDashes = [], ${
200
+ `var data, token = "", token2 = "", exports = {}, ${
167
201
  withHmr ? "moduleIds = [], " : ""
168
- }name = ${name}, i = 0, cc = 1;`,
202
+ }name = ${name}, i, cc = 1;`,
169
203
  "try {",
170
204
  Template.indent([
171
205
  "if(!link) link = loadStylesheet(chunkId);",
@@ -187,46 +221,44 @@ class CssLoadingRuntimeModule extends RuntimeModule {
187
221
  ]),
188
222
  "}",
189
223
  "if(!data) return [];",
190
- "for(; cc; i++) {",
224
+ withCompression
225
+ ? Template.asString([
226
+ // LZW decode
227
+ `var map = {}, char = data[0], oldPhrase = char, decoded = char, code = 256, maxCode = ${"\uffff".charCodeAt(
228
+ 0
229
+ )}, phrase;`,
230
+ "for (i = 1; i < data.length; i++) {",
231
+ Template.indent([
232
+ "cc = data[i].charCodeAt(0);",
233
+ "if (cc < 256) phrase = data[i]; else phrase = map[cc] ? map[cc] : (oldPhrase + char);",
234
+ "decoded += phrase;",
235
+ "char = phrase.charAt(0);",
236
+ "map[code] = oldPhrase + char;",
237
+ "if (++code > maxCode) { code = 256; map = {}; }",
238
+ "oldPhrase = phrase;"
239
+ ]),
240
+ "}",
241
+ "data = decoded;"
242
+ ])
243
+ : "// css head data compression is disabled",
244
+ "for(i = 0; cc; i++) {",
191
245
  Template.indent([
192
246
  "cc = data.charCodeAt(i);",
193
- `if(cc == ${cc("(")}) { token2 = token; token = ""; }`,
247
+ `if(cc == ${cc(":")}) { token2 = token; token = ""; }`,
194
248
  `else if(cc == ${cc(
195
- ")"
196
- )}) { exports[token2.replace(/^_/, "")] = token.replace(/^_/, ""); token = ""; }`,
197
- `else if(cc == ${cc("/")} || cc == ${cc(
198
- "%"
199
- )}) { token = token.replace(/^_/, ""); exports[token] = token; exportsWithId.push(token); if(cc == ${cc(
200
- "%"
201
- )}) exportsWithDashes.push(token); token = ""; }`,
249
+ "/"
250
+ )}) { token = token.replace(/^_/, ""); token2 = token2.replace(/^_/, ""); exports[token2] = token; token = ""; token2 = ""; }`,
251
+ `else if(cc == ${cc("&")}) { ${
252
+ RuntimeGlobals.makeNamespaceObject
253
+ }(exports); }`,
202
254
  `else if(!cc || cc == ${cc(
203
255
  ","
204
- )}) { token = token.replace(/^_/, ""); exportsWithId.forEach(${runtimeTemplate.expressionFunction(
205
- `exports[x] = ${
206
- uniqueName
207
- ? runtimeTemplate.concatenation(
208
- { expr: "uniqueName" },
209
- "-",
210
- { expr: "token" },
211
- "-",
212
- { expr: "exports[x]" }
213
- )
214
- : runtimeTemplate.concatenation({ expr: "token" }, "-", {
215
- expr: "exports[x]"
216
- })
217
- }`,
218
- "x"
219
- )}); exportsWithDashes.forEach(${runtimeTemplate.expressionFunction(
220
- `exports[x] = "--" + exports[x]`,
221
- "x"
222
- )}); ${
223
- RuntimeGlobals.makeNamespaceObject
224
- }(exports); target[token] = (${runtimeTemplate.basicFunction(
256
+ )}) { token = token.replace(/^_/, ""); target[token] = (${runtimeTemplate.basicFunction(
225
257
  "exports, module",
226
258
  `module.exports = exports;`
227
259
  )}).bind(null, exports); ${
228
260
  withHmr ? "moduleIds.push(token); " : ""
229
- }token = ""; exports = {}; exportsWithId.length = 0; exportsWithDashes.length = 0; }`,
261
+ }token = ""; token2 = ""; exports = {}; }`,
230
262
  `else if(cc == ${cc("\\")}) { token += data[++i] }`,
231
263
  `else { token += data[i]; }`
232
264
  ]),
@@ -239,7 +271,9 @@ class CssLoadingRuntimeModule extends RuntimeModule {
239
271
  )}`,
240
272
  'var loadingAttribute = "data-webpack-loading";',
241
273
  `var loadStylesheet = ${runtimeTemplate.basicFunction(
242
- "chunkId, url, done" + (withHmr ? ", hmr" : ""),
274
+ "chunkId, url, done" +
275
+ (withHmr ? ", hmr" : "") +
276
+ (withFetchPriority ? ", fetchPriority" : ""),
243
277
  [
244
278
  'var link, needAttach, key = "chunk-" + chunkId;',
245
279
  withHmr ? "if(!hmr) {" : "",
@@ -307,74 +341,159 @@ class CssLoadingRuntimeModule extends RuntimeModule {
307
341
  "",
308
342
  withLoading
309
343
  ? Template.asString([
310
- `${fn}.css = ${runtimeTemplate.basicFunction("chunkId, promises", [
311
- "// css chunk loading",
312
- `var installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
313
- 'if(installedChunkData !== 0) { // 0 means "already installed".',
314
- Template.indent([
315
- "",
316
- '// a Promise means "currently loading".',
317
- "if(installedChunkData) {",
318
- Template.indent(["promises.push(installedChunkData[2]);"]),
319
- "} else {",
344
+ `${fn}.css = ${runtimeTemplate.basicFunction(
345
+ `chunkId, promises${withFetchPriority ? " , fetchPriority" : ""}`,
346
+ [
347
+ "// css chunk loading",
348
+ `var installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
349
+ 'if(installedChunkData !== 0) { // 0 means "already installed".',
320
350
  Template.indent([
321
- hasCssMatcher === true
322
- ? "if(true) { // all chunks have CSS"
323
- : `if(${hasCssMatcher("chunkId")}) {`,
351
+ "",
352
+ '// a Promise means "currently loading".',
353
+ "if(installedChunkData) {",
354
+ Template.indent(["promises.push(installedChunkData[2]);"]),
355
+ "} else {",
324
356
  Template.indent([
325
- "// setup Promise in chunk cache",
326
- `var promise = new Promise(${runtimeTemplate.expressionFunction(
327
- `installedChunkData = installedChunks[chunkId] = [resolve, reject]`,
328
- "resolve, reject"
329
- )});`,
330
- "promises.push(installedChunkData[2] = promise);",
331
- "",
332
- "// start chunk loading",
333
- `var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
334
- "// create error before stack unwound to get useful stacktrace later",
335
- "var error = new Error();",
336
- `var loadingEnded = ${runtimeTemplate.basicFunction(
337
- "event",
338
- [
339
- `if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId)) {`,
340
- Template.indent([
341
- "installedChunkData = installedChunks[chunkId];",
342
- "if(installedChunkData !== 0) installedChunks[chunkId] = undefined;",
343
- "if(installedChunkData) {",
357
+ hasCssMatcher === true
358
+ ? "if(true) { // all chunks have CSS"
359
+ : `if(${hasCssMatcher("chunkId")}) {`,
360
+ Template.indent([
361
+ "// setup Promise in chunk cache",
362
+ `var promise = new Promise(${runtimeTemplate.expressionFunction(
363
+ `installedChunkData = installedChunks[chunkId] = [resolve, reject]`,
364
+ "resolve, reject"
365
+ )});`,
366
+ "promises.push(installedChunkData[2] = promise);",
367
+ "",
368
+ "// start chunk loading",
369
+ `var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
370
+ "// create error before stack unwound to get useful stacktrace later",
371
+ "var error = new Error();",
372
+ `var loadingEnded = ${runtimeTemplate.basicFunction(
373
+ "event",
374
+ [
375
+ `if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId)) {`,
344
376
  Template.indent([
345
- 'if(event.type !== "load") {',
377
+ "installedChunkData = installedChunks[chunkId];",
378
+ "if(installedChunkData !== 0) installedChunks[chunkId] = undefined;",
379
+ "if(installedChunkData) {",
346
380
  Template.indent([
347
- "var errorType = event && event.type;",
348
- "var realHref = event && event.target && event.target.href;",
349
- "error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realHref + ')';",
350
- "error.name = 'ChunkLoadError';",
351
- "error.type = errorType;",
352
- "error.request = realHref;",
353
- "installedChunkData[1](error);"
354
- ]),
355
- "} else {",
356
- Template.indent([
357
- `loadCssChunkData(${RuntimeGlobals.moduleFactories}, link, chunkId);`,
358
- "installedChunkData[0]();"
381
+ 'if(event.type !== "load") {',
382
+ Template.indent([
383
+ "var errorType = event && event.type;",
384
+ "var realHref = event && event.target && event.target.href;",
385
+ "error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realHref + ')';",
386
+ "error.name = 'ChunkLoadError';",
387
+ "error.type = errorType;",
388
+ "error.request = realHref;",
389
+ "installedChunkData[1](error);"
390
+ ]),
391
+ "} else {",
392
+ Template.indent([
393
+ `loadCssChunkData(${RuntimeGlobals.moduleFactories}, link, chunkId);`,
394
+ "installedChunkData[0]();"
395
+ ]),
396
+ "}"
359
397
  ]),
360
398
  "}"
361
399
  ]),
362
400
  "}"
363
- ]),
364
- "}"
365
- ]
366
- )};`,
367
- "var link = loadStylesheet(chunkId, url, loadingEnded);"
401
+ ]
402
+ )};`,
403
+ `var link = loadStylesheet(chunkId, url, loadingEnded${
404
+ withFetchPriority ? ", fetchPriority" : ""
405
+ });`
406
+ ]),
407
+ "} else installedChunks[chunkId] = 0;"
368
408
  ]),
369
- "} else installedChunks[chunkId] = 0;"
409
+ "}"
370
410
  ]),
371
411
  "}"
372
- ]),
373
- "}"
374
- ])};`
412
+ ]
413
+ )};`
375
414
  ])
376
415
  : "// no chunk loading",
377
416
  "",
417
+ withPrefetch && hasCssMatcher !== false
418
+ ? `${
419
+ RuntimeGlobals.prefetchChunkHandlers
420
+ }.s = ${runtimeTemplate.basicFunction("chunkId", [
421
+ `if((!${
422
+ RuntimeGlobals.hasOwnProperty
423
+ }(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
424
+ hasCssMatcher === true ? "true" : hasCssMatcher("chunkId")
425
+ }) {`,
426
+ Template.indent([
427
+ "installedChunks[chunkId] = null;",
428
+ linkPrefetch.call(
429
+ Template.asString([
430
+ "var link = document.createElement('link');",
431
+ crossOriginLoading
432
+ ? `link.crossOrigin = ${JSON.stringify(
433
+ crossOriginLoading
434
+ )};`
435
+ : "",
436
+ `if (${RuntimeGlobals.scriptNonce}) {`,
437
+ Template.indent(
438
+ `link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
439
+ ),
440
+ "}",
441
+ 'link.rel = "prefetch";',
442
+ 'link.as = "style";',
443
+ `link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`
444
+ ]),
445
+ chunk
446
+ ),
447
+ "document.head.appendChild(link);"
448
+ ]),
449
+ "}"
450
+ ])};`
451
+ : "// no prefetching",
452
+ "",
453
+ withPreload && hasCssMatcher !== false
454
+ ? `${
455
+ RuntimeGlobals.preloadChunkHandlers
456
+ }.s = ${runtimeTemplate.basicFunction("chunkId", [
457
+ `if((!${
458
+ RuntimeGlobals.hasOwnProperty
459
+ }(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
460
+ hasCssMatcher === true ? "true" : hasCssMatcher("chunkId")
461
+ }) {`,
462
+ Template.indent([
463
+ "installedChunks[chunkId] = null;",
464
+ linkPreload.call(
465
+ Template.asString([
466
+ "var link = document.createElement('link');",
467
+ "link.charset = 'utf-8';",
468
+ `if (${RuntimeGlobals.scriptNonce}) {`,
469
+ Template.indent(
470
+ `link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
471
+ ),
472
+ "}",
473
+ 'link.rel = "preload";',
474
+ 'link.as = "style";',
475
+ `link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
476
+ crossOriginLoading
477
+ ? crossOriginLoading === "use-credentials"
478
+ ? 'link.crossOrigin = "use-credentials";'
479
+ : Template.asString([
480
+ "if (link.href.indexOf(window.location.origin + '/') !== 0) {",
481
+ Template.indent(
482
+ `link.crossOrigin = ${JSON.stringify(
483
+ crossOriginLoading
484
+ )};`
485
+ ),
486
+ "}"
487
+ ])
488
+ : ""
489
+ ]),
490
+ chunk
491
+ ),
492
+ "document.head.appendChild(link);"
493
+ ]),
494
+ "}"
495
+ ])};`
496
+ : "// no preloaded",
378
497
  withHmr
379
498
  ? Template.asString([
380
499
  "var oldTags = [];",