UNPKG

@module-federation/enhanced

Version:

This package provides enhanced features for module federation.

58 lines (56 loc) 2.17 kB
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } }); const require_runtime = require('../../../_virtual/_rolldown/runtime.js'); let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path"); //#region src/lib/container/runtime/EmbedFederationRuntimeModule.ts const { RuntimeModule, Template, RuntimeGlobals } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack")); var EmbedFederationRuntimeModule = class extends RuntimeModule { constructor(containerEntrySet) { super("embed federation", RuntimeModule.STAGE_ATTACH); this.containerEntrySet = containerEntrySet; this._cachedGeneratedCode = void 0; } identifier() { return "webpack/runtime/embed/federation"; } generate() { if (this._cachedGeneratedCode !== void 0) return this._cachedGeneratedCode; const { compilation, chunk, chunkGraph } = this; if (!chunk || !chunkGraph || !compilation) return null; let found; if (chunk.name) for (const dep of this.containerEntrySet) { const mod = compilation.moduleGraph.getModule(dep); if (mod && compilation.chunkGraph.isModuleInChunk(mod, chunk)) { found = mod; break; } } if (!found) return null; const initRuntimeModuleGetter = compilation.runtimeTemplate.moduleRaw({ module: found, chunkGraph, request: found.request, weak: false, runtimeRequirements: /* @__PURE__ */ new Set() }); const result = Template.asString([ `var prevStartup = ${RuntimeGlobals.startup};`, `var hasRun = false;`, `${RuntimeGlobals.startup} = ${compilation.runtimeTemplate.basicFunction("", [ `if (!hasRun) {`, ` hasRun = true;`, ` ${initRuntimeModuleGetter};`, `}`, `if (typeof prevStartup === 'function') {`, ` return prevStartup();`, `} else {`, ` console.warn('[Module Federation] prevStartup is not a function, skipping startup execution');`, `}` ])};` ]); this._cachedGeneratedCode = result; return result; } }; //#endregion exports.default = EmbedFederationRuntimeModule; //# sourceMappingURL=EmbedFederationRuntimeModule.js.map