MCPcopy
hub / github.com/webpack/webpack / _generateCssText

Method _generateCssText

lib/css/CssGenerator.js:935–960  ·  view source on GitHub ↗

* Generate the merged CSS text for a module, optionally wrapped as a * JS string literal for embedding in JavaScript output. * @param {NormalModule} module the module * @param {GenerateContext} generateContext the generate context * @param {boolean} asJsLiteral wrap the result as a JS string

(module, generateContext, asJsLiteral)

Source from the content-addressed store, hash-verified

933 * @returns {Source} the CSS text source
934 */
935 _generateCssText(module, generateContext, asJsLiteral) {
936 const cssSource = this._renderMergedCss(module, generateContext, new Set());
937 const effectiveCharset = this._getEffectiveCharset(
938 module,
939 generateContext.moduleGraph
940 );
941
942 let result;
943 if (effectiveCharset !== undefined) {
944 const prefix = `@charset "${effectiveCharset}";\n`;
945 result = cssSource
946 ? new ConcatSource(prefix, cssSource)
947 : new RawSource(prefix);
948 } else {
949 result = cssSource;
950 }
951
952 if (asJsLiteral) {
953 const devtool =
954 generateContext.runtimeTemplate.compilation.options.devtool;
955 return result
956 ? this._cssToJsLiteral(result, devtool, generateContext)
957 : new RawSource('""');
958 }
959 return result || new RawSource("");
960 }
961}
962
963module.exports = CssGenerator;

Callers 2

generateMethod · 0.95

Calls 3

_renderMergedCssMethod · 0.95
_getEffectiveCharsetMethod · 0.95
_cssToJsLiteralMethod · 0.95

Tested by

no test coverage detected