MCPcopy
hub / github.com/webpack/webpack / generate

Method generate

lib/css/CssLoadingRuntimeModule.js:46–572  ·  view source on GitHub ↗

* Generates runtime code for this runtime module. * @returns {string | null} runtime code

()

Source from the content-addressed store, hash-verified

44 * @returns {string | null} runtime code
45 */
46 generate() {
47 const { _runtimeRequirements } = this;
48 const compilation = /** @type {Compilation} */ (this.compilation);
49 const chunk = /** @type {Chunk} */ (this.chunk);
50 const {
51 chunkGraph,
52 runtimeTemplate,
53 outputOptions: {
54 crossOriginLoading,
55 uniqueName,
56 chunkLoadTimeout: loadTimeout,
57 charset,
58 importMetaName
59 }
60 } = compilation;
61 const fn = RuntimeGlobals.ensureChunkHandlers;
62 const conditionMap = chunkGraph.getChunkConditionMap(
63 chunk,
64 /**
65 * @param {Chunk} chunk the chunk
66 * @param {ChunkGraph} chunkGraph the chunk graph
67 * @returns {boolean} true, if the chunk has css
68 */
69 (chunk, chunkGraph) =>
70 Boolean(chunkGraph.getChunkModulesIterableBySourceType(chunk, CSS_TYPE))
71 );
72 const hasCssMatcher = compileBooleanMatcher(conditionMap);
73
74 const withLoading =
75 _runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers) &&
76 hasCssMatcher !== false;
77 /** @type {boolean} */
78 const withHmr = _runtimeRequirements.has(
79 RuntimeGlobals.hmrDownloadUpdateHandlers
80 );
81 /** @type {Set<ChunkId>} */
82 const initialChunkIds = new Set();
83 for (const c of chunk.getAllInitialChunks()) {
84 if (chunkHasCss(c, chunkGraph)) {
85 initialChunkIds.add(/** @type {ChunkId} */ (c.id));
86 }
87 }
88
89 if (!withLoading && !withHmr) {
90 return null;
91 }
92
93 const environment = compilation.outputOptions.environment;
94 const isNeutralPlatform = runtimeTemplate.isNeutralPlatform();
95 const withPrefetch =
96 this._runtimeRequirements.has(RuntimeGlobals.prefetchChunkHandlers) &&
97 (environment.document || isNeutralPlatform) &&
98 chunk.hasChildByOrder(chunkGraph, "prefetch", true, chunkHasCss);
99 const withPreload =
100 this._runtimeRequirements.has(RuntimeGlobals.preloadChunkHandlers) &&
101 (environment.document || isNeutralPlatform) &&
102 chunk.hasChildByOrder(chunkGraph, "preload", true, chunkHasCss);
103

Callers

nothing calls this directly

Calls 15

chunkHasCssFunction · 0.85
getChunkConditionMapMethod · 0.80
getAllInitialChunksMethod · 0.80
isNeutralPlatformMethod · 0.80
hasChildByOrderMethod · 0.80
indentMethod · 0.80
renderConstMethod · 0.80
renderLetMethod · 0.80
assignOrMethod · 0.80
basicFunctionMethod · 0.80
expressionFunctionMethod · 0.80

Tested by

no test coverage detected