| | |
| | | |
| | | 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"); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Generates runtime code for this runtime module. |
| | | * @returns {string | null} runtime code |
| | | */ |
| | | generate() { |
| | |
| | | * @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); |
| | | |
| | |
| | | (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` |
| | |
| | | "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("", [ |
| | |
| | | `${ |
| | | 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( |