MCPcopy
hub / github.com/webpack/webpack / generateExportCode

Method generateExportCode

lib/css/CssGenerator.js:359–533  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

357 }
358 };
359 const generateExportCode = () => {
360 /**
361 * Generates js default export.
362 * @returns {Source | null} the default export
363 */
364 const generateJSDefaultExport = () => {
365 switch (exportType) {
366 case "text": {
367 return this._generateCssText(module, generateContext, true);
368 }
369 case "css-style-sheet": {
370 const rt = generateContext.runtimeTemplate;
371 const fnPrefix = rt.supportsArrowFunction()
372 ? "() => {\n"
373 : "function() {\n";
374 const constOrVar = rt.renderConst();
375 const fallback =
376 "{ cssText: css, replaceSync: function(value) { this.cssText = value; } }";
377 if (rt.compilation.compiler.platform.node === true) {
378 return new ConcatSource(
379 `(${fnPrefix}${constOrVar} css = `,
380 this._generateCssText(module, generateContext, true),
381 `;\nreturn ${fallback};\n})()`
382 );
383 }
384 if (rt.isUniversalTarget()) {
385 return new ConcatSource(
386 `(${fnPrefix}${constOrVar} css = `,
387 this._generateCssText(module, generateContext, true),
388 `;\nif (typeof CSSStyleSheet === 'undefined') return ${fallback};\n${constOrVar} sheet = new CSSStyleSheet();\nsheet.replaceSync(css);\nreturn sheet;\n})()`
389 );
390 }
391 return new ConcatSource(
392 `(${fnPrefix}${constOrVar} sheet = new CSSStyleSheet();\nsheet.replaceSync(`,
393 this._generateCssText(module, generateContext, true),
394 ");\nreturn sheet;\n})()"
395 );
396 }
397 default:
398 return null;
399 }
400 };
401
402 /** @type {Source | null} */
403 const defaultExport = generateJSDefaultExport();
404
405 /** @type {CssModuleBuildInfo} */
406 (module.buildInfo).cssData = cssData;
407
408 // Required for HMR
409 if (module.hot) {
410 generateContext.runtimeRequirements.add(RuntimeGlobals.module);
411 }
412
413 if (!defaultExport && cssData.exports.size === 0 && !isCssModule) {
414 return new RawSource("");
415 }
416

Callers

nothing calls this directly

Calls 10

getExportsInfoMethod · 0.80
toIdentifierMethod · 0.80
registerExportMethod · 0.80
renderConstMethod · 0.80
addMethod · 0.45
getUsedNameMethod · 0.45
getExportInfoMethod · 0.45
hasMethod · 0.45
getUsedMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected