MCPcopy
hub / github.com/webpack/webpack / _renderMergedCss

Method _renderMergedCss

lib/css/CssGenerator.js:814–847  ·  view source on GitHub ↗

* Recursively merge `@import`'d CSS into a single Source (text/css-style-sheet only). * @param {NormalModule} module the module to render * @param {GenerateContext} generateContext the generate context * @param {Set<NormalModule>} ancestors modules on the current path (cycle guard) * @return

(module, generateContext, ancestors)

Source from the content-addressed store, hash-verified

812 * @returns {Source | null} merged CSS source, or null when the module has no content
813 */
814 _renderMergedCss(module, generateContext, ancestors) {
815 if (ancestors.has(module)) return null;
816 ancestors.add(module);
817 try {
818 const { moduleGraph } = generateContext;
819 /** @type {Source[]} */
820 const parts = [];
821
822 for (const dep of module.dependencies) {
823 if (!(dep instanceof CssImportDependency)) continue;
824 const depModule = /** @type {CssModule} */ (moduleGraph.getModule(dep));
825 if (!depModule) continue;
826 const depExportType = depModule.exportType;
827 if (depExportType !== "text" && depExportType !== "css-style-sheet") {
828 continue;
829 }
830 const depMerged = this._renderMergedCss(
831 depModule,
832 generateContext,
833 ancestors
834 );
835 if (depMerged) parts.push(depMerged);
836 }
837
838 const own = this._renderCss(module, generateContext);
839 if (own) parts.push(own);
840
841 if (parts.length === 0) return null;
842 if (parts.length === 1) return parts[0];
843 return new ConcatSource(...parts);
844 } finally {
845 ancestors.delete(module);
846 }
847 }
848
849 /**
850 * Generate CSS source for the current module

Callers 1

_generateCssTextMethod · 0.95

Calls 6

_renderCssMethod · 0.95
hasMethod · 0.45
addMethod · 0.45
getModuleMethod · 0.45
pushMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected