CssLoadingRuntimeModule.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const { SyncWaterfallHook } = require("tapable");
  7. const Compilation = require("../Compilation");
  8. const RuntimeGlobals = require("../RuntimeGlobals");
  9. const RuntimeModule = require("../RuntimeModule");
  10. const Template = require("../Template");
  11. const compileBooleanMatcher = require("../util/compileBooleanMatcher");
  12. const { chunkHasCss } = require("./CssModulesPlugin");
  13. /** @typedef {import("../Chunk")} Chunk */
  14. /** @typedef {import("../ChunkGraph")} ChunkGraph */
  15. /** @typedef {import("../Compilation").RuntimeRequirementsContext} RuntimeRequirementsContext */
  16. /** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
  17. /**
  18. * @typedef {Object} CssLoadingRuntimeModulePluginHooks
  19. * @property {SyncWaterfallHook<[string, Chunk]>} createStylesheet
  20. * @property {SyncWaterfallHook<[string, Chunk]>} linkPreload
  21. * @property {SyncWaterfallHook<[string, Chunk]>} linkPrefetch
  22. */
  23. /** @type {WeakMap<Compilation, CssLoadingRuntimeModulePluginHooks>} */
  24. const compilationHooksMap = new WeakMap();
  25. class CssLoadingRuntimeModule extends RuntimeModule {
  26. /**
  27. * @param {Compilation} compilation the compilation
  28. * @returns {CssLoadingRuntimeModulePluginHooks} hooks
  29. */
  30. static getCompilationHooks(compilation) {
  31. if (!(compilation instanceof Compilation)) {
  32. throw new TypeError(
  33. "The 'compilation' argument must be an instance of Compilation"
  34. );
  35. }
  36. let hooks = compilationHooksMap.get(compilation);
  37. if (hooks === undefined) {
  38. hooks = {
  39. createStylesheet: new SyncWaterfallHook(["source", "chunk"]),
  40. linkPreload: new SyncWaterfallHook(["source", "chunk"]),
  41. linkPrefetch: new SyncWaterfallHook(["source", "chunk"])
  42. };
  43. compilationHooksMap.set(compilation, hooks);
  44. }
  45. return hooks;
  46. }
  47. /**
  48. * @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
  49. */
  50. constructor(runtimeRequirements) {
  51. super("css loading", 10);
  52. this._runtimeRequirements = runtimeRequirements;
  53. }
  54. /**
  55. * @returns {string | null} runtime code
  56. */
  57. generate() {
  58. const { _runtimeRequirements } = this;
  59. const compilation = /** @type {Compilation} */ (this.compilation);
  60. const chunk = /** @type {Chunk} */ (this.chunk);
  61. const {
  62. chunkGraph,
  63. runtimeTemplate,
  64. outputOptions: {
  65. crossOriginLoading,
  66. uniqueName,
  67. chunkLoadTimeout: loadTimeout,
  68. cssHeadDataCompression: withCompression
  69. }
  70. } = compilation;
  71. const fn = RuntimeGlobals.ensureChunkHandlers;
  72. const conditionMap = chunkGraph.getChunkConditionMap(
  73. /** @type {Chunk} */ (chunk),
  74. /**
  75. * @param {Chunk} chunk the chunk
  76. * @param {ChunkGraph} chunkGraph the chunk graph
  77. * @returns {boolean} true, if the chunk has css
  78. */
  79. (chunk, chunkGraph) =>
  80. !!chunkGraph.getChunkModulesIterableBySourceType(chunk, "css")
  81. );
  82. const hasCssMatcher = compileBooleanMatcher(conditionMap);
  83. const withLoading =
  84. _runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers) &&
  85. hasCssMatcher !== false;
  86. const withPrefetch = this._runtimeRequirements.has(
  87. RuntimeGlobals.prefetchChunkHandlers
  88. );
  89. const withPreload = this._runtimeRequirements.has(
  90. RuntimeGlobals.preloadChunkHandlers
  91. );
  92. /** @type {boolean} */
  93. const withHmr = _runtimeRequirements.has(
  94. RuntimeGlobals.hmrDownloadUpdateHandlers
  95. );
  96. /** @type {Set<number | string | null>} */
  97. const initialChunkIdsWithCss = new Set();
  98. /** @type {Set<number | string | null>} */
  99. const initialChunkIdsWithoutCss = new Set();
  100. for (const c of /** @type {Chunk} */ (chunk).getAllInitialChunks()) {
  101. (chunkHasCss(c, chunkGraph)
  102. ? initialChunkIdsWithCss
  103. : initialChunkIdsWithoutCss
  104. ).add(c.id);
  105. }
  106. if (!withLoading && !withHmr && initialChunkIdsWithCss.size === 0) {
  107. return null;
  108. }
  109. const { linkPreload, linkPrefetch } =
  110. CssLoadingRuntimeModule.getCompilationHooks(compilation);
  111. const withFetchPriority = _runtimeRequirements.has(
  112. RuntimeGlobals.hasFetchPriority
  113. );
  114. const { createStylesheet } =
  115. CssLoadingRuntimeModule.getCompilationHooks(compilation);
  116. const stateExpression = withHmr
  117. ? `${RuntimeGlobals.hmrRuntimeStatePrefix}_css`
  118. : undefined;
  119. const code = Template.asString([
  120. "link = document.createElement('link');",
  121. `if (${RuntimeGlobals.scriptNonce}) {`,
  122. Template.indent(
  123. `link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
  124. ),
  125. "}",
  126. uniqueName
  127. ? 'link.setAttribute("data-webpack", uniqueName + ":" + key);'
  128. : "",
  129. withFetchPriority
  130. ? Template.asString([
  131. "if(fetchPriority) {",
  132. Template.indent(
  133. 'link.setAttribute("fetchpriority", fetchPriority);'
  134. ),
  135. "}"
  136. ])
  137. : "",
  138. "link.setAttribute(loadingAttribute, 1);",
  139. 'link.rel = "stylesheet";',
  140. "link.href = url;",
  141. crossOriginLoading
  142. ? crossOriginLoading === "use-credentials"
  143. ? 'link.crossOrigin = "use-credentials";'
  144. : Template.asString([
  145. "if (link.href.indexOf(window.location.origin + '/') !== 0) {",
  146. Template.indent(
  147. `link.crossOrigin = ${JSON.stringify(crossOriginLoading)};`
  148. ),
  149. "}"
  150. ])
  151. : ""
  152. ]);
  153. /** @type {(str: string) => number} */
  154. const cc = str => str.charCodeAt(0);
  155. const name = uniqueName
  156. ? runtimeTemplate.concatenation(
  157. "--webpack-",
  158. { expr: "uniqueName" },
  159. "-",
  160. { expr: "chunkId" }
  161. )
  162. : runtimeTemplate.concatenation("--webpack-", { expr: "chunkId" });
  163. return Template.asString([
  164. "// object to store loaded and loading chunks",
  165. "// undefined = chunk not loaded, null = chunk preloaded/prefetched",
  166. "// [resolve, reject, Promise] = chunk loading, 0 = chunk loaded",
  167. `var installedChunks = ${
  168. stateExpression ? `${stateExpression} = ${stateExpression} || ` : ""
  169. }{${Array.from(
  170. initialChunkIdsWithoutCss,
  171. id => `${JSON.stringify(id)}:0`
  172. ).join(",")}};`,
  173. "",
  174. uniqueName
  175. ? `var uniqueName = ${JSON.stringify(
  176. runtimeTemplate.outputOptions.uniqueName
  177. )};`
  178. : "// data-webpack is not used as build has no uniqueName",
  179. `var loadCssChunkData = ${runtimeTemplate.basicFunction(
  180. "target, link, chunkId",
  181. [
  182. `var data, token = "", token2 = "", exports = {}, ${
  183. withHmr ? "moduleIds = [], " : ""
  184. }name = ${name}, i, cc = 1;`,
  185. "try {",
  186. Template.indent([
  187. "if(!link) link = loadStylesheet(chunkId);",
  188. // `link.sheet.rules` for legacy browsers
  189. "var cssRules = link.sheet.cssRules || link.sheet.rules;",
  190. "var j = cssRules.length - 1;",
  191. "while(j > -1 && !data) {",
  192. Template.indent([
  193. "var style = cssRules[j--].style;",
  194. "if(!style) continue;",
  195. `data = style.getPropertyValue(name);`
  196. ]),
  197. "}"
  198. ]),
  199. "}catch(e){}",
  200. "if(!data) {",
  201. Template.indent([
  202. "data = getComputedStyle(document.head).getPropertyValue(name);"
  203. ]),
  204. "}",
  205. "if(!data) return [];",
  206. withCompression
  207. ? Template.asString([
  208. // LZW decode
  209. `var map = {}, char = data[0], oldPhrase = char, decoded = char, code = 256, maxCode = "\uffff".charCodeAt(0), phrase;`,
  210. "for (i = 1; i < data.length; i++) {",
  211. Template.indent([
  212. "cc = data[i].charCodeAt(0);",
  213. "if (cc < 256) phrase = data[i]; else phrase = map[cc] ? map[cc] : (oldPhrase + char);",
  214. "decoded += phrase;",
  215. "char = phrase.charAt(0);",
  216. "map[code] = oldPhrase + char;",
  217. "if (++code > maxCode) { code = 256; map = {}; }",
  218. "oldPhrase = phrase;"
  219. ]),
  220. "}",
  221. "data = decoded;"
  222. ])
  223. : "// css head data compression is disabled",
  224. "for(i = 0; cc; i++) {",
  225. Template.indent([
  226. "cc = data.charCodeAt(i);",
  227. `if(cc == ${cc(":")}) { token2 = token; token = ""; }`,
  228. `else if(cc == ${cc(
  229. "/"
  230. )}) { token = token.replace(/^_/, ""); token2 = token2.replace(/^_/, ""); exports[token2] = token; token = ""; token2 = ""; }`,
  231. `else if(!cc || cc == ${cc(
  232. ","
  233. )}) { token = token.replace(/^_/, ""); ${
  234. RuntimeGlobals.makeNamespaceObject
  235. }(exports); target[token] = (${runtimeTemplate.basicFunction(
  236. "exports, module",
  237. `module.exports = exports;`
  238. )}).bind(null, exports); ${
  239. withHmr ? "moduleIds.push(token); " : ""
  240. }token = ""; token2 = ""; exports = {}; }`,
  241. `else if(cc == ${cc("\\")}) { token += data[++i] }`,
  242. `else { token += data[i]; }`
  243. ]),
  244. "}",
  245. `${
  246. withHmr ? `if(target == ${RuntimeGlobals.moduleFactories}) ` : ""
  247. }installedChunks[chunkId] = 0;`,
  248. withHmr ? "return moduleIds;" : ""
  249. ]
  250. )}`,
  251. 'var loadingAttribute = "data-webpack-loading";',
  252. `var loadStylesheet = ${runtimeTemplate.basicFunction(
  253. "chunkId, url, done" +
  254. (withHmr ? ", hmr" : "") +
  255. (withFetchPriority ? ", fetchPriority" : ""),
  256. [
  257. 'var link, needAttach, key = "chunk-" + chunkId;',
  258. withHmr ? "if(!hmr) {" : "",
  259. 'var links = document.getElementsByTagName("link");',
  260. "for(var i = 0; i < links.length; i++) {",
  261. Template.indent([
  262. "var l = links[i];",
  263. `if(l.rel == "stylesheet" && (${
  264. withHmr
  265. ? 'l.href.startsWith(url) || l.getAttribute("href").startsWith(url)'
  266. : 'l.href == url || l.getAttribute("href") == url'
  267. }${
  268. uniqueName
  269. ? ' || l.getAttribute("data-webpack") == uniqueName + ":" + key'
  270. : ""
  271. })) { link = l; break; }`
  272. ]),
  273. "}",
  274. "if(!done) return link;",
  275. withHmr ? "}" : "",
  276. "if(!link) {",
  277. Template.indent([
  278. "needAttach = true;",
  279. createStylesheet.call(code, /** @type {Chunk} */ (this.chunk))
  280. ]),
  281. "}",
  282. `var onLinkComplete = ${runtimeTemplate.basicFunction(
  283. "prev, event",
  284. Template.asString([
  285. "link.onerror = link.onload = null;",
  286. "link.removeAttribute(loadingAttribute);",
  287. "clearTimeout(timeout);",
  288. 'if(event && event.type != "load") link.parentNode.removeChild(link)',
  289. "done(event);",
  290. "if(prev) return prev(event);"
  291. ])
  292. )};`,
  293. "if(link.getAttribute(loadingAttribute)) {",
  294. Template.indent([
  295. `var timeout = setTimeout(onLinkComplete.bind(null, undefined, { type: 'timeout', target: link }), ${loadTimeout});`,
  296. "link.onerror = onLinkComplete.bind(null, link.onerror);",
  297. "link.onload = onLinkComplete.bind(null, link.onload);"
  298. ]),
  299. "} else onLinkComplete(undefined, { type: 'load', target: link });", // We assume any existing stylesheet is render blocking
  300. withHmr ? "hmr ? document.head.insertBefore(link, hmr) :" : "",
  301. "needAttach && document.head.appendChild(link);",
  302. "return link;"
  303. ]
  304. )};`,
  305. initialChunkIdsWithCss.size > 2
  306. ? `${JSON.stringify(
  307. Array.from(initialChunkIdsWithCss)
  308. )}.forEach(loadCssChunkData.bind(null, ${
  309. RuntimeGlobals.moduleFactories
  310. }, 0));`
  311. : initialChunkIdsWithCss.size > 0
  312. ? `${Array.from(
  313. initialChunkIdsWithCss,
  314. id =>
  315. `loadCssChunkData(${
  316. RuntimeGlobals.moduleFactories
  317. }, 0, ${JSON.stringify(id)});`
  318. ).join("")}`
  319. : "// no initial css",
  320. "",
  321. withLoading
  322. ? Template.asString([
  323. `${fn}.css = ${runtimeTemplate.basicFunction(
  324. `chunkId, promises${withFetchPriority ? " , fetchPriority" : ""}`,
  325. [
  326. "// css chunk loading",
  327. `var installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`,
  328. 'if(installedChunkData !== 0) { // 0 means "already installed".',
  329. Template.indent([
  330. "",
  331. '// a Promise means "currently loading".',
  332. "if(installedChunkData) {",
  333. Template.indent(["promises.push(installedChunkData[2]);"]),
  334. "} else {",
  335. Template.indent([
  336. hasCssMatcher === true
  337. ? "if(true) { // all chunks have CSS"
  338. : `if(${hasCssMatcher("chunkId")}) {`,
  339. Template.indent([
  340. "// setup Promise in chunk cache",
  341. `var promise = new Promise(${runtimeTemplate.expressionFunction(
  342. `installedChunkData = installedChunks[chunkId] = [resolve, reject]`,
  343. "resolve, reject"
  344. )});`,
  345. "promises.push(installedChunkData[2] = promise);",
  346. "",
  347. "// start chunk loading",
  348. `var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
  349. "// create error before stack unwound to get useful stacktrace later",
  350. "var error = new Error();",
  351. `var loadingEnded = ${runtimeTemplate.basicFunction(
  352. "event",
  353. [
  354. `if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId)) {`,
  355. Template.indent([
  356. "installedChunkData = installedChunks[chunkId];",
  357. "if(installedChunkData !== 0) installedChunks[chunkId] = undefined;",
  358. "if(installedChunkData) {",
  359. Template.indent([
  360. 'if(event.type !== "load") {',
  361. Template.indent([
  362. "var errorType = event && event.type;",
  363. "var realHref = event && event.target && event.target.href;",
  364. "error.message = 'Loading css chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realHref + ')';",
  365. "error.name = 'ChunkLoadError';",
  366. "error.type = errorType;",
  367. "error.request = realHref;",
  368. "installedChunkData[1](error);"
  369. ]),
  370. "} else {",
  371. Template.indent([
  372. `loadCssChunkData(${RuntimeGlobals.moduleFactories}, link, chunkId);`,
  373. "installedChunkData[0]();"
  374. ]),
  375. "}"
  376. ]),
  377. "}"
  378. ]),
  379. "}"
  380. ]
  381. )};`,
  382. `var link = loadStylesheet(chunkId, url, loadingEnded${
  383. withFetchPriority ? ", fetchPriority" : ""
  384. });`
  385. ]),
  386. "} else installedChunks[chunkId] = 0;"
  387. ]),
  388. "}"
  389. ]),
  390. "}"
  391. ]
  392. )};`
  393. ])
  394. : "// no chunk loading",
  395. "",
  396. withPrefetch && hasCssMatcher !== false
  397. ? `${
  398. RuntimeGlobals.prefetchChunkHandlers
  399. }.s = ${runtimeTemplate.basicFunction("chunkId", [
  400. `if((!${
  401. RuntimeGlobals.hasOwnProperty
  402. }(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
  403. hasCssMatcher === true ? "true" : hasCssMatcher("chunkId")
  404. }) {`,
  405. Template.indent([
  406. "installedChunks[chunkId] = null;",
  407. linkPrefetch.call(
  408. Template.asString([
  409. "var link = document.createElement('link');",
  410. crossOriginLoading
  411. ? `link.crossOrigin = ${JSON.stringify(
  412. crossOriginLoading
  413. )};`
  414. : "",
  415. `if (${RuntimeGlobals.scriptNonce}) {`,
  416. Template.indent(
  417. `link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
  418. ),
  419. "}",
  420. 'link.rel = "prefetch";',
  421. 'link.as = "style";',
  422. `link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`
  423. ]),
  424. chunk
  425. ),
  426. "document.head.appendChild(link);"
  427. ]),
  428. "}"
  429. ])};`
  430. : "// no prefetching",
  431. "",
  432. withPreload && hasCssMatcher !== false
  433. ? `${
  434. RuntimeGlobals.preloadChunkHandlers
  435. }.s = ${runtimeTemplate.basicFunction("chunkId", [
  436. `if((!${
  437. RuntimeGlobals.hasOwnProperty
  438. }(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
  439. hasCssMatcher === true ? "true" : hasCssMatcher("chunkId")
  440. }) {`,
  441. Template.indent([
  442. "installedChunks[chunkId] = null;",
  443. linkPreload.call(
  444. Template.asString([
  445. "var link = document.createElement('link');",
  446. "link.charset = 'utf-8';",
  447. `if (${RuntimeGlobals.scriptNonce}) {`,
  448. Template.indent(
  449. `link.setAttribute("nonce", ${RuntimeGlobals.scriptNonce});`
  450. ),
  451. "}",
  452. 'link.rel = "preload";',
  453. 'link.as = "style";',
  454. `link.href = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
  455. crossOriginLoading
  456. ? crossOriginLoading === "use-credentials"
  457. ? 'link.crossOrigin = "use-credentials";'
  458. : Template.asString([
  459. "if (link.href.indexOf(window.location.origin + '/') !== 0) {",
  460. Template.indent(
  461. `link.crossOrigin = ${JSON.stringify(
  462. crossOriginLoading
  463. )};`
  464. ),
  465. "}"
  466. ])
  467. : ""
  468. ]),
  469. chunk
  470. ),
  471. "document.head.appendChild(link);"
  472. ]),
  473. "}"
  474. ])};`
  475. : "// no preloaded",
  476. withHmr
  477. ? Template.asString([
  478. "var oldTags = [];",
  479. "var newTags = [];",
  480. `var applyHandler = ${runtimeTemplate.basicFunction("options", [
  481. `return { dispose: ${runtimeTemplate.basicFunction(
  482. "",
  483. []
  484. )}, apply: ${runtimeTemplate.basicFunction("", [
  485. "var moduleIds = [];",
  486. `newTags.forEach(${runtimeTemplate.expressionFunction(
  487. "info[1].sheet.disabled = false",
  488. "info"
  489. )});`,
  490. "while(oldTags.length) {",
  491. Template.indent([
  492. "var oldTag = oldTags.pop();",
  493. "if(oldTag.parentNode) oldTag.parentNode.removeChild(oldTag);"
  494. ]),
  495. "}",
  496. "while(newTags.length) {",
  497. Template.indent([
  498. `var info = newTags.pop();`,
  499. `var chunkModuleIds = loadCssChunkData(${RuntimeGlobals.moduleFactories}, info[1], info[0]);`,
  500. `chunkModuleIds.forEach(${runtimeTemplate.expressionFunction(
  501. "moduleIds.push(id)",
  502. "id"
  503. )});`
  504. ]),
  505. "}",
  506. "return moduleIds;"
  507. ])} };`
  508. ])}`,
  509. `var cssTextKey = ${runtimeTemplate.returningFunction(
  510. `Array.from(link.sheet.cssRules, ${runtimeTemplate.returningFunction(
  511. "r.cssText",
  512. "r"
  513. )}).join()`,
  514. "link"
  515. )}`,
  516. `${
  517. RuntimeGlobals.hmrDownloadUpdateHandlers
  518. }.css = ${runtimeTemplate.basicFunction(
  519. "chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList",
  520. [
  521. "applyHandlers.push(applyHandler);",
  522. `chunkIds.forEach(${runtimeTemplate.basicFunction("chunkId", [
  523. `var filename = ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
  524. `var url = ${RuntimeGlobals.publicPath} + filename;`,
  525. "var oldTag = loadStylesheet(chunkId, url);",
  526. "if(!oldTag) return;",
  527. `promises.push(new Promise(${runtimeTemplate.basicFunction(
  528. "resolve, reject",
  529. [
  530. `var link = loadStylesheet(chunkId, url + (url.indexOf("?") < 0 ? "?" : "&") + "hmr=" + Date.now(), ${runtimeTemplate.basicFunction(
  531. "event",
  532. [
  533. 'if(event.type !== "load") {',
  534. Template.indent([
  535. "var errorType = event && event.type;",
  536. "var realHref = event && event.target && event.target.href;",
  537. "error.message = 'Loading css hot update chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realHref + ')';",
  538. "error.name = 'ChunkLoadError';",
  539. "error.type = errorType;",
  540. "error.request = realHref;",
  541. "reject(error);"
  542. ]),
  543. "} else {",
  544. Template.indent([
  545. "try { if(cssTextKey(oldTag) == cssTextKey(link)) { if(link.parentNode) link.parentNode.removeChild(link); return resolve(); } } catch(e) {}",
  546. "var factories = {};",
  547. "loadCssChunkData(factories, link, chunkId);",
  548. `Object.keys(factories).forEach(${runtimeTemplate.expressionFunction(
  549. "updatedModulesList.push(id)",
  550. "id"
  551. )})`,
  552. "link.sheet.disabled = true;",
  553. "oldTags.push(oldTag);",
  554. "newTags.push([chunkId, link]);",
  555. "resolve();"
  556. ]),
  557. "}"
  558. ]
  559. )}, oldTag);`
  560. ]
  561. )}));`
  562. ])});`
  563. ]
  564. )}`
  565. ])
  566. : "// no hmr"
  567. ]);
  568. }
  569. }
  570. module.exports = CssLoadingRuntimeModule;