* Generates generated code for this runtime module. * @param {NormalModule} module module for which the code should be generated * @param {GenerateContext} generateContext context for generate * @returns {Source | null} generated code
(module, generateContext)
| 286 | * @returns {Source | null} generated code |
| 287 | */ |
| 288 | generate(module, generateContext) { |
| 289 | const exportType = /** @type {CssModule} */ (module).exportType || "link"; |
| 290 | const source = |
| 291 | generateContext.type === JAVASCRIPT_TYPE && exportType === "link" |
| 292 | ? new ReplaceSource(new RawSource("")) |
| 293 | : new ReplaceSource(/** @type {Source} */ (module.originalSource())); |
| 294 | /** @type {InitFragment<GenerateContext>[]} */ |
| 295 | const initFragments = []; |
| 296 | /** @type {CssData} */ |
| 297 | const cssData = { |
| 298 | esModule: /** @type {boolean} */ (this._esModule), |
| 299 | exports: new Map(), |
| 300 | exportLocs: new Map() |
| 301 | }; |
| 302 | |
| 303 | this.sourceModule(module, initFragments, source, { |
| 304 | ...generateContext, |
| 305 | cssData |
| 306 | }); |
| 307 | |
| 308 | switch (generateContext.type) { |
| 309 | case JAVASCRIPT_TYPE: { |
| 310 | const compilation = generateContext.runtimeTemplate.compilation; |
| 311 | const devtool = compilation.options.devtool; |
| 312 | const isCssModule = /** @type {CssModuleBuildMeta} */ (module.buildMeta) |
| 313 | .isCssModule; |
| 314 | |
| 315 | const generateContentCode = () => { |
| 316 | switch (exportType) { |
| 317 | case "style": { |
| 318 | const cssSource = this._renderCss(module, generateContext); |
| 319 | if (!cssSource) return ""; |
| 320 | |
| 321 | generateContext.runtimeRequirements.add( |
| 322 | RuntimeGlobals.cssInjectStyle |
| 323 | ); |
| 324 | |
| 325 | const moduleId = generateContext.chunkGraph.getModuleId(module); |
| 326 | |
| 327 | if (generateContext.concatenationScope) { |
| 328 | return new ConcatSource( |
| 329 | `__webpack_css_styles__.push([${JSON.stringify(moduleId)}, `, |
| 330 | this._cssToJsLiteral(cssSource, devtool, generateContext), |
| 331 | "]);" |
| 332 | ); |
| 333 | } |
| 334 | |
| 335 | return new ConcatSource( |
| 336 | `${RuntimeGlobals.cssInjectStyle}(${JSON.stringify( |
| 337 | moduleId |
| 338 | )}, `, |
| 339 | this._cssToJsLiteral(cssSource, devtool, generateContext), |
| 340 | ");" |
| 341 | ); |
| 342 | } |
| 343 | |
| 344 | default: |
| 345 | return ""; |
no test coverage detected