* 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)
| 413 | * @returns {Source | null} generated code |
| 414 | */ |
| 415 | generate(module, generateContext) { |
| 416 | const originalSource = module.originalSource(); |
| 417 | |
| 418 | if (!originalSource) { |
| 419 | return new RawSource(""); |
| 420 | } |
| 421 | |
| 422 | if (generateContext.type === HTML_TYPE) { |
| 423 | // Preserve `[webpack/auto]`; renderManifest resolves it once `.html` filename is known. |
| 424 | return new RawSource( |
| 425 | this._renderHtml(module, generateContext, undefined) |
| 426 | ); |
| 427 | } |
| 428 | |
| 429 | // JS export: resolve `[webpack/auto]` to root-relative URLs. |
| 430 | const generated = this._renderHtml(module, generateContext, ""); |
| 431 | |
| 432 | /** @type {string} */ |
| 433 | let sourceContent; |
| 434 | // `module.hot` is set by `HotModuleReplacementPlugin` on every module |
| 435 | // when HMR is enabled. When set, we cannot use the concatenation path |
| 436 | // (it merges into a parent's module scope, where `module.hot.accept` |
| 437 | // would target the wrong id) — `getConcatenationBailoutReason` keeps |
| 438 | // us out of concatenation in that case. |
| 439 | if (generateContext.concatenationScope && !module.hot) { |
| 440 | generateContext.concatenationScope.registerNamespaceExport( |
| 441 | ConcatenationScope.NAMESPACE_OBJECT_EXPORT |
| 442 | ); |
| 443 | sourceContent = `${generateContext.runtimeTemplate.renderConst()} ${ |
| 444 | ConcatenationScope.NAMESPACE_OBJECT_EXPORT |
| 445 | } = ${JSON.stringify(generated)};`; |
| 446 | } else { |
| 447 | generateContext.runtimeRequirements.add(RuntimeGlobals.module); |
| 448 | if (module.hot) { |
| 449 | sourceContent = this._renderHmrShim( |
| 450 | module, |
| 451 | generated, |
| 452 | this._shouldExtract(module), |
| 453 | generateContext.runtimeTemplate |
| 454 | ); |
| 455 | } else { |
| 456 | sourceContent = `${module.moduleArgument}.exports = ${JSON.stringify( |
| 457 | generated |
| 458 | )};`; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | return new RawSource(sourceContent); |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * Emits the JS shim with HMR self-acceptance. When `extracting` is true the |
nothing calls this directly
no test coverage detected