WXL
4 天以前 3bd962a6d7f61239c020e2dbbeb7341e5b842dd1
node_modules/webpack/lib/css/CssLoadingRuntimeModule.js
@@ -7,6 +7,7 @@
const { SyncWaterfallHook } = require("tapable");
const Compilation = require("../Compilation");
const { CSS_TYPE } = require("../ModuleSourceTypeConstants");
const RuntimeGlobals = require("../RuntimeGlobals");
const RuntimeModule = require("../RuntimeModule");
const Template = require("../Template");
@@ -61,6 +62,7 @@
   }
   /**
    * Generates runtime code for this runtime module.
    * @returns {string | null} runtime code
    */
   generate() {
@@ -86,7 +88,7 @@
          * @returns {boolean} true, if the chunk has css
          */
         (chunk, chunkGraph) =>
            Boolean(chunkGraph.getChunkModulesIterableBySourceType(chunk, "css"))
            Boolean(chunkGraph.getChunkModulesIterableBySourceType(chunk, CSS_TYPE))
      );
      const hasCssMatcher = compileBooleanMatcher(conditionMap);
@@ -120,15 +122,12 @@
         (environment.document || isNeutralPlatform) &&
         chunk.hasChildByOrder(chunkGraph, "preload", true, chunkHasCss);
      const { linkPreload, linkPrefetch } =
      const { linkPreload, linkPrefetch, createStylesheet } =
         CssLoadingRuntimeModule.getCompilationHooks(compilation);
      const withFetchPriority = _runtimeRequirements.has(
         RuntimeGlobals.hasFetchPriority
      );
      const { createStylesheet } =
         CssLoadingRuntimeModule.getCompilationHooks(compilation);
      const stateExpression = withHmr
         ? `${RuntimeGlobals.hmrRuntimeStatePrefix}_css`
@@ -429,7 +428,7 @@
                        "while(oldTags.length) {",
                        Template.indent([
                           "var oldTag = oldTags.pop();",
                           "if(oldTag.parentNode) oldTag.parentNode.removeChild(oldTag);"
                           "if(oldTag && oldTag.parentNode) oldTag.parentNode.removeChild(oldTag);"
                        ]),
                        "}"
                     ])}, apply: ${runtimeTemplate.basicFunction("", [
@@ -451,17 +450,24 @@
                  `${
                     RuntimeGlobals.hmrDownloadUpdateHandlers
                  }.css = ${runtimeTemplate.basicFunction(
                     "chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList",
                     "chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList, css",
                     [
                        isNeutralPlatform
                           ? "if (typeof document === 'undefined') return;"
                           : "",
                        "applyHandlers.push(applyHandler);",
                        "// Read CSS removed chunks from update manifest",
                        "var cssRemovedChunks = css && css.r;",
                        `chunkIds.forEach(${runtimeTemplate.basicFunction("chunkId", [
                           `var filename = ${RuntimeGlobals.getChunkCssFilename}(chunkId);`,
                           `var url = ${RuntimeGlobals.publicPath} + filename;`,
                           "var oldTag = loadStylesheet(chunkId, url);",
                           "if(!oldTag) return;",
                           `if(!oldTag && !${withHmr} ) return;`,
                           "// Skip if CSS was removed",
                           "if(cssRemovedChunks && cssRemovedChunks.indexOf(chunkId) >= 0) {",
                           Template.indent(["oldTags.push(oldTag);", "return;"]),
                           "}",
                           "",
                           "// create error before stack unwound to get useful stacktrace later",
                           "var error = new Error();",
                           `promises.push(new Promise(${runtimeTemplate.basicFunction(