@module-federation/electron 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +177 -2
  3. package/dist/index.cjs +104 -1
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +32 -1
  6. package/dist/index.d.cts.map +1 -1
  7. package/dist/index.d.ts +32 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +51 -1
  10. package/dist/index.js.map +1 -0
  11. package/dist/remote.cjs +287 -0
  12. package/dist/remote.cjs.map +1 -0
  13. package/dist/remote.d.cts +35 -0
  14. package/dist/remote.d.cts.map +1 -0
  15. package/dist/remote.d.ts +35 -0
  16. package/dist/remote.d.ts.map +1 -0
  17. package/dist/remote.js +227 -0
  18. package/dist/remote.js.map +1 -0
  19. package/dist/resolve.cjs +60 -0
  20. package/dist/resolve.cjs.map +1 -0
  21. package/dist/resolve.d.cts +7 -0
  22. package/dist/resolve.d.cts.map +1 -0
  23. package/dist/resolve.d.ts +7 -0
  24. package/dist/resolve.d.ts.map +1 -0
  25. package/dist/resolve.js +12 -0
  26. package/dist/resolve.js.map +1 -0
  27. package/dist/rsbuild.cjs +89 -0
  28. package/dist/rsbuild.cjs.map +1 -0
  29. package/dist/rsbuild.d.cts +31 -0
  30. package/dist/rsbuild.d.cts.map +1 -0
  31. package/dist/rsbuild.d.ts +31 -0
  32. package/dist/rsbuild.d.ts.map +1 -0
  33. package/dist/rsbuild.js +30 -0
  34. package/dist/rsbuild.js.map +1 -0
  35. package/dist/url.cjs +67 -0
  36. package/dist/url.cjs.map +1 -0
  37. package/dist/url.d.cts +22 -0
  38. package/dist/url.d.cts.map +1 -0
  39. package/dist/url.d.ts +22 -0
  40. package/dist/url.d.ts.map +1 -0
  41. package/dist/url.js +17 -0
  42. package/dist/url.js.map +1 -0
  43. package/dist/vite.cjs +84 -0
  44. package/dist/vite.cjs.map +1 -0
  45. package/dist/vite.d.cts +29 -0
  46. package/dist/vite.d.cts.map +1 -0
  47. package/dist/vite.d.ts +29 -0
  48. package/dist/vite.d.ts.map +1 -0
  49. package/dist/vite.js +25 -0
  50. package/dist/vite.js.map +1 -0
  51. package/package.json +82 -23
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote.js","sources":["../src/remote.ts"],"sourcesContent":["/**\n * Serves apps deployed to an http(s) URL, with an on-disk cache that stands in for\n * the network when it fails. Must not import `electron`: the fetch function is\n * passed in, so this runs (and is tested) in plain Node.\n *\n * Cache layout, relative to the cache directory:\n *\n * ```text\n * <sha1(origin)>/<sha1(pathname)> one JSON line with status and headers, then the body\n * ```\n */\nimport { createHash } from 'node:crypto';\nimport { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';\nimport path from 'node:path';\n\n/** Header added to responses served from the cache. */\nexport const CACHE_HEADER = 'x-mf-cache';\n\n/** How long an origin is skipped after a network failure, for requests that have a cached copy. */\nexport const UNREACHABLE_FOR_MS = 30_000;\n\nconst DEFAULT_TIMEOUT_MS = 10_000;\n\n/**\n * Headers not replayed from the upstream response: they describe the original connection,\n * an encoding the fetch already undid, or cookies that do not belong to the `mf://` origin.\n */\nconst DROPPED_HEADERS = new Set([\n 'connection',\n 'keep-alive',\n 'transfer-encoding',\n 'content-encoding',\n 'content-length',\n 'set-cookie',\n]);\n\n/** Request headers sent upstream. Conditional headers are left out: a 304 has no body to cache. */\nconst FORWARDED_HEADERS = ['accept', 'accept-language', 'content-type'];\n\nconst NULL_BODY_STATUSES = new Set([101, 103, 204, 205, 304]);\n\nexport type FetchFunction = (url: string, init: RequestInit) => Promise<Response>;\n\nexport interface RemoteCacheOptions {\n /** Directory for cached responses. */\n dir: string;\n /** Milliseconds to wait for response headers. Default 10 000. */\n connectTimeout?: number;\n /** Milliseconds the body may stall between chunks. Not a limit on the total download. Default 10 000. */\n readTimeout?: number;\n}\n\nexport interface RemoteHandlerOptions {\n /** Performs the network request. In Electron, `net.fetch`. */\n fetch: FetchFunction;\n /** Offline cache settings, or `false` to proxy without caching or timeouts. */\n cache: RemoteCacheOptions | false;\n /** Receives fallbacks and cache write failures. Default `console.warn`. */\n log?: (message: string) => void;\n /** Clock, for tests. */\n now?: () => number;\n}\n\n/** Fetches `upstream` on behalf of `request`, which is the `mf://` request it stands for. */\nexport type RemoteHandler = (request: Request, upstream: URL) => Promise<Response>;\n\n/** Whether an `apps` entry is a deployment URL rather than a directory. */\nexport function isRemoteLocation(location: string): boolean {\n return /^https?:\\/\\//i.test(location);\n}\n\n/**\n * Maps a request URL (`<scheme>://<host>/<appId>/<path>?<query>`) to the matching URL\n * under the app's base URL. Returns `undefined` for unknown apps or for paths that would\n * leave the base URL.\n */\nexport function resolveAppUrl(\n requestUrl: URL,\n bases: Readonly<Record<string, string>>,\n): URL | undefined {\n const [, appId, ...rest] = requestUrl.pathname.split('/');\n if (!appId || !Object.hasOwn(bases, appId)) return undefined;\n\n const base = new URL(bases[appId] as string);\n base.search = '';\n base.hash = '';\n if (!base.pathname.endsWith('/')) base.pathname += '/';\n\n const target = new URL(rest.join('/') + requestUrl.search, base);\n if (target.origin !== base.origin || !target.pathname.startsWith(base.pathname)) return undefined;\n return target;\n}\n\ninterface Fetched {\n status: number;\n headers: [string, string][];\n body: Uint8Array;\n}\n\nclass FetchFailure extends Error {\n constructor(\n message: string,\n readonly timedOut: boolean,\n ) {\n super(message);\n }\n}\n\nexport function createRemoteHandler(options: RemoteHandlerOptions): RemoteHandler {\n const { fetch, cache } = options;\n const log = options.log ?? ((message: string) => console.warn(`[module-federation] ${message}`));\n const now = options.now ?? Date.now;\n\n if (!cache) {\n return (request, upstream) => fetch(upstream.href, upstreamInit(request));\n }\n\n const connectTimeout = cache.connectTimeout ?? DEFAULT_TIMEOUT_MS;\n const readTimeout = cache.readTimeout ?? DEFAULT_TIMEOUT_MS;\n const unreachableSince = new Map<string, number>();\n const isUnreachable = (origin: string) => {\n const since = unreachableSince.get(origin);\n return since !== undefined && now() - since < UNREACHABLE_FOR_MS;\n };\n\n return async (request, upstream) => {\n const cacheable = request.method === 'GET';\n const file = cacheFile(cache.dir, upstream);\n const stale = async (reason: string) => {\n if (!cacheable) return undefined;\n const cached = await readCached(file);\n if (cached) log(`${upstream.href} ${reason}, serving the cached copy`);\n return cached && toResponse(cached, 'stale');\n };\n\n if (cacheable && isUnreachable(upstream.origin)) {\n const cached = await readCached(file);\n if (cached) return toResponse(cached, 'stale');\n }\n\n let fetched: Fetched;\n try {\n fetched = await fetchFully(fetch, upstream, request, connectTimeout, readTimeout);\n } catch (error) {\n unreachableSince.set(upstream.origin, now());\n const failure =\n error instanceof FetchFailure ? error : new FetchFailure(String(error), false);\n return (\n (await stale(`failed (${failure.message})`)) ??\n text(\n failure.timedOut ? 504 : 502,\n `${upstream.href} failed (${failure.message}) and is not cached`,\n )\n );\n }\n\n unreachableSince.delete(upstream.origin);\n if (fetched.status >= 200 && fetched.status < 300) {\n if (cacheable) {\n await writeCached(file, fetched).catch((error: unknown) =>\n log(`failed to cache ${upstream.href}: ${String(error)}`),\n );\n }\n return toResponse(fetched);\n }\n return (await stale(`answered ${fetched.status}`)) ?? toResponse(fetched);\n };\n}\n\nfunction upstreamInit(request: Request): RequestInit {\n const headers = new Headers();\n for (const name of FORWARDED_HEADERS) {\n const value = request.headers.get(name);\n if (value !== null) headers.set(name, value);\n }\n const init: RequestInit & { duplex?: 'half' } = { method: request.method, headers };\n if (request.body && request.method !== 'GET' && request.method !== 'HEAD') {\n init.body = request.body;\n init.duplex = 'half';\n }\n return init;\n}\n\n/**\n * Fetches the whole response. Throws a {@link FetchFailure} when the request fails, the\n * headers take longer than `connectTimeout`, the body stalls for `readTimeout`, or the\n * body fails halfway: a truncated response must not be cached as a success.\n */\nasync function fetchFully(\n fetch: FetchFunction,\n upstream: URL,\n request: Request,\n connectTimeout: number,\n readTimeout: number,\n): Promise<Fetched> {\n const controller = new AbortController();\n const response = await withTimeout(\n fetch(upstream.href, { ...upstreamInit(request), signal: controller.signal }),\n connectTimeout,\n controller,\n 'no response',\n );\n\n const chunks: Uint8Array[] = [];\n const reader = response.body?.getReader();\n if (reader) {\n try {\n for (;;) {\n const { done, value } = await withTimeout(\n reader.read(),\n readTimeout,\n controller,\n 'body stalled',\n );\n if (done) break;\n chunks.push(value);\n }\n } catch (error) {\n reader.cancel().catch(() => {});\n throw error;\n }\n }\n\n return {\n status: response.status,\n headers: [...response.headers].filter(([name]) => !DROPPED_HEADERS.has(name.toLowerCase())),\n body: concat(chunks),\n };\n}\n\nfunction withTimeout<T>(\n promise: Promise<T>,\n ms: number,\n controller: AbortController,\n what: string,\n): Promise<T> {\n let timer: ReturnType<typeof setTimeout> | undefined;\n const timeout = new Promise<never>((_, reject) => {\n timer = setTimeout(() => {\n // Reject before aborting: the abort also rejects `promise`, and the race must\n // settle with the timeout.\n reject(new FetchFailure(`${what} after ${ms} ms`, true));\n controller.abort();\n }, ms);\n });\n return Promise.race([promise, timeout])\n .catch((error: unknown) => {\n throw error instanceof FetchFailure ? error : new FetchFailure(errorMessage(error), false);\n })\n .finally(() => clearTimeout(timer));\n}\n\nfunction errorMessage(error: unknown): string {\n if (!(error instanceof Error)) return String(error);\n // Node's fetch reports \"fetch failed\" and puts the reason in `cause`.\n return error.cause instanceof Error ? `${error.message}: ${error.cause.message}` : error.message;\n}\n\nfunction concat(chunks: Uint8Array[]): Uint8Array {\n const body = new Uint8Array(chunks.reduce((size, chunk) => size + chunk.byteLength, 0));\n let offset = 0;\n for (const chunk of chunks) {\n body.set(chunk, offset);\n offset += chunk.byteLength;\n }\n return body;\n}\n\nfunction sha1(value: string): string {\n return createHash('sha1').update(value).digest('hex');\n}\n\n/** The query string is not part of the key, so cache-busting parameters still hit the cache. */\nfunction cacheFile(dir: string, url: URL): string {\n return path.join(dir, sha1(url.origin), sha1(url.pathname));\n}\n\nasync function readCached(file: string): Promise<Fetched | undefined> {\n let data: Buffer;\n try {\n data = await readFile(file);\n } catch {\n return undefined;\n }\n const newline = data.indexOf(0x0a);\n if (newline < 0) return undefined;\n try {\n const meta = JSON.parse(data.subarray(0, newline).toString('utf8')) as Omit<Fetched, 'body'>;\n return { status: meta.status, headers: meta.headers, body: data.subarray(newline + 1) };\n } catch {\n return undefined;\n }\n}\n\nlet tmpCounter = 0;\n\n/** Writes headers and body as one file through a rename, so a crash never leaves a mismatched pair. */\nasync function writeCached(file: string, fetched: Fetched): Promise<void> {\n await mkdir(path.dirname(file), { recursive: true });\n const meta = JSON.stringify({ status: fetched.status, headers: fetched.headers });\n const tmp = `${file}.tmp-${process.pid}-${tmpCounter++}`;\n try {\n await writeFile(tmp, Buffer.concat([Buffer.from(`${meta}\\n`), fetched.body]));\n await rename(tmp, file);\n } catch (error) {\n await rm(tmp, { force: true });\n throw error;\n }\n}\n\nfunction toResponse(fetched: Fetched, fromCache?: 'stale'): Response {\n const headers = new Headers(fetched.headers);\n if (fromCache) headers.set(CACHE_HEADER, fromCache);\n const body = NULL_BODY_STATUSES.has(fetched.status) ? null : fetched.body;\n return new Response(body, { status: fetched.status, headers });\n}\n\nfunction text(status: number, message: string): Response {\n return new Response(message, {\n status,\n headers: { 'content-type': 'text/plain; charset=utf-8', 'cache-control': 'no-store' },\n });\n}\n"],"names":["CACHE_HEADER","UNREACHABLE_FOR_MS","DEFAULT_TIMEOUT_MS","DROPPED_HEADERS","Set","FORWARDED_HEADERS","NULL_BODY_STATUSES","isRemoteLocation","location","resolveAppUrl","requestUrl","bases","appId","rest","Object","base","URL","target","FetchFailure","Error","message","timedOut","createRemoteHandler","options","fetch","cache","log","console","now","Date","request","upstream","upstreamInit","connectTimeout","readTimeout","unreachableSince","Map","isUnreachable","origin","since","undefined","cacheable","file","cacheFile","stale","reason","cached","readCached","toResponse","fetched","fetchFully","error","failure","String","text","writeCached","headers","Headers","name","value","init","controller","AbortController","response","withTimeout","chunks","reader","done","concat","promise","ms","what","timer","timeout","Promise","_","reject","setTimeout","errorMessage","clearTimeout","body","Uint8Array","size","chunk","offset","sha1","createHash","dir","url","path","data","readFile","newline","meta","JSON","tmpCounter","mkdir","tmp","process","writeFile","Buffer","rename","rm","fromCache","Response","status"],"mappings":";;;AAgBO,MAAMA,eAAe;AAGrB,MAAMC,qBAAqB;AAElC,MAAMC,qBAAqB;AAM3B,MAAMC,kBAAkB,IAAIC,IAAI;IAC9B;IACA;IACA;IACA;IACA;IACA;CACD;AAGD,MAAMC,oBAAoB;IAAC;IAAU;IAAmB;CAAe;AAEvE,MAAMC,qBAAqB,IAAIF,IAAI;IAAC;IAAK;IAAK;IAAK;IAAK;CAAI;AA4BrD,SAASG,iBAAiBC,QAAgB;IAC/C,OAAO,gBAAgB,IAAI,CAACA;AAC9B;AAOO,SAASC,cACdC,UAAe,EACfC,KAAuC;IAEvC,MAAM,GAAGC,OAAO,GAAGC,KAAK,GAAGH,WAAW,QAAQ,CAAC,KAAK,CAAC;IACrD,IAAI,CAACE,SAAS,CAACE,OAAO,MAAM,CAACH,OAAOC,QAAQ;IAE5C,MAAMG,OAAO,IAAIC,IAAIL,KAAK,CAACC,MAAM;IACjCG,KAAK,MAAM,GAAG;IACdA,KAAK,IAAI,GAAG;IACZ,IAAI,CAACA,KAAK,QAAQ,CAAC,QAAQ,CAAC,MAAMA,KAAK,QAAQ,IAAI;IAEnD,MAAME,SAAS,IAAID,IAAIH,KAAK,IAAI,CAAC,OAAOH,WAAW,MAAM,EAAEK;IAC3D,IAAIE,OAAO,MAAM,KAAKF,KAAK,MAAM,IAAI,CAACE,OAAO,QAAQ,CAAC,UAAU,CAACF,KAAK,QAAQ,GAAG;IACjF,OAAOE;AACT;AAQA,MAAMC,qBAAqBC;;IACzB,YACEC,OAAe,EACNC,QAAiB,CAC1B;QACA,KAAK,CAACD,UAAAA,IAAAA,CAFGC,QAAQ,GAARA;IAGX;AACF;AAEO,SAASC,oBAAoBC,OAA6B;IAC/D,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGF;IACzB,MAAMG,MAAMH,QAAQ,GAAG,I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AM,CAAC;YAACA,OAAO,IAAI,CAAC,GAAGP,KAAK,EAAE,CAAC;YAAG5C,QAAQ,IAAI;SAAC;QAC3E,MAAMoD,OAAOJ,KAAKvD;IACpB,EAAE,OAAOS,OAAO;QACd,MAAMmD,GAAGL,KAAK;YAAE,OAAO;QAAK;QAC5B,MAAM9C;IACR;AACF;AAEA,SAASH,WAAWC,OAAgB,EAAEsD,SAAmB;IACvD,MAAM/C,UAAU,IAAIC,QAAQR,QAAQ,OAAO;IAC3C,IAAIsD,WAAW/C,QAAQ,GAAG,CAACxD,cAAcuG;IACzC,MAAMvB,OAAO1E,mBAAmB,GAAG,CAAC2C,QAAQ,MAAM,IAAI,OAAOA,QAAQ,IAAI;IACzE,OAAO,IAAIuD,SAASxB,MAAM;QAAE,QAAQ/B,QAAQ,MAAM;QAAEO;IAAQ;AAC9D;AAEA,SAASF,YAAKmD,MAAc,EAAErF,OAAe;IAC3C,OAAO,IAAIoF,SAASpF,SAAS;QAC3BqF;QACA,SAAS;YAAE,gBAAgB;YAA6B,iBAAiB;QAAW;IACtF;AACF"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ resolveAppFile: ()=>resolveAppFile
41
+ });
42
+ const external_node_path_namespaceObject = require("node:path");
43
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
44
+ function resolveAppFile(pathname, apps) {
45
+ const [, appId, ...rest] = decodeURIComponent(pathname).split('/');
46
+ if (!appId || !Object.hasOwn(apps, appId)) return;
47
+ const root = external_node_path_default().resolve(apps[appId]);
48
+ const file = external_node_path_default().resolve(root, rest.join('/') || 'index.html');
49
+ if (file !== root && !file.startsWith(root + external_node_path_default().sep)) return;
50
+ return file;
51
+ }
52
+ exports.resolveAppFile = __webpack_exports__.resolveAppFile;
53
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
54
+ "resolveAppFile"
55
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
56
+ Object.defineProperty(exports, '__esModule', {
57
+ value: true
58
+ });
59
+
60
+ //# sourceMappingURL=resolve.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.cjs","sources":["webpack://webpack/runtime/compat_get_default_export","webpack://webpack/runtime/define_property_getters","webpack://webpack/runtime/has_own_property","webpack://webpack/runtime/make_namespace_object","../src/resolve.ts"],"sourcesContent":["// getDefaultExport function for compatibility with non-ESM modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};\n","__webpack_require__.d = (exports, getters, values) => {\n\tvar define = (defs, kind) => {\n\t\tfor(var key in defs) {\n\t\t\tif(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {\n\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });\n\t\t\t}\n\t\t}\n\t};\n\tdefine(getters, \"get\");\n\tdefine(values, \"value\");\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import path from 'node:path';\n\n/**\n * Maps a request pathname (`/<appId>/<file>`) to an absolute file path inside\n * the matching app directory. Returns `undefined` for unknown apps or for paths\n * that would escape the app directory.\n */\nexport function resolveAppFile(\n pathname: string,\n apps: Readonly<Record<string, string>>,\n): string | undefined {\n const [, appId, ...rest] = decodeURIComponent(pathname).split('/');\n if (!appId || !Object.hasOwn(apps, appId)) return undefined;\n\n const root = path.resolve(apps[appId] as string);\n const file = path.resolve(root, rest.join('/') || 'index.html');\n if (file !== root && !file.startsWith(root + path.sep)) return undefined;\n return file;\n}\n"],"names":["__webpack_require__","module","getter","getters","values","define","defs","kind","key","Object","obj","prop","Symbol","resolveAppFile","pathname","apps","appId","rest","decodeURIComponent","root","path","file"],"mappings":";;;IACAA,oBAAoB,CAAC,GAAG,CAACC;QACxB,IAAIC,SAASD,UAAUA,OAAO,UAAU,GACvC,IAAOA,MAAM,CAAC,UAAU,GACxB,IAAOA;QACRD,oBAAoB,CAAC,CAACE,QAAQ;YAAE,GAAGA;QAAO;QAC1C,OAAOA;IACR;;;ICPAF,oBAAoB,CAAC,GAAG,CAAC,UAASG,SAASC;QAC1C,IAAIC,SAAS,CAACC,MAAMC;YACnB,IAAI,IAAIC,OAAOF,KACd,IAAGN,oBAAoB,CAAC,CAACM,MAAME,QAAQ,CAACR,oBAAoB,CAAC,CAAC,UAASQ,MACtEC,OAAO,cAAc,CAAC,UAASD,KAAK;gBAAE,YAAY;gBAAM,CAACD,KAAK,EAAED,IAAI,CAACE,IAAI;YAAC;QAG7E;QACAH,OAAOF,SAAS;QAChBE,OAAOD,QAAQ;IAChB;;;ICVAJ,oBAAoB,CAAC,GAAG,CAACU,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFX,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,MAAlB,OAAOY,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;ACCO,SAASI,eACdC,QAAgB,EAChBC,IAAsC;IAEtC,MAAM,GAAGC,OAAO,GAAGC,KAAK,GAAGC,mBAAmBJ,UAAU,KAAK,CAAC;IAC9D,IAAI,CAACE,SAAS,CAACP,OAAO,MAAM,CAACM,MAAMC,QAAQ;IAE3C,MAAMG,OAAOC,6BAAAA,OAAY,CAACL,IAAI,CAACC,MAAM;IACrC,MAAMK,OAAOD,6BAAAA,OAAY,CAACD,MAAMF,KAAK,IAAI,CAAC,QAAQ;IAClD,IAAII,SAASF,QAAQ,CAACE,KAAK,UAAU,CAACF,OAAOC,AAAAA,6BAAAA,GAAQ,GAAG;IACxD,OAAOC;AACT"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Maps a request pathname (`/<appId>/<file>`) to an absolute file path inside
3
+ * the matching app directory. Returns `undefined` for unknown apps or for paths
4
+ * that would escape the app directory.
5
+ */
6
+ export declare function resolveAppFile(pathname: string, apps: Readonly<Record<string, string>>): string | undefined;
7
+ //# sourceMappingURL=resolve.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.cts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACrC,MAAM,GAAG,SAAS,CAQpB"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Maps a request pathname (`/<appId>/<file>`) to an absolute file path inside
3
+ * the matching app directory. Returns `undefined` for unknown apps or for paths
4
+ * that would escape the app directory.
5
+ */
6
+ export declare function resolveAppFile(pathname: string, apps: Readonly<Record<string, string>>): string | undefined;
7
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACrC,MAAM,GAAG,SAAS,CAQpB"}
@@ -0,0 +1,12 @@
1
+ import node_path from "node:path";
2
+ function resolveAppFile(pathname, apps) {
3
+ const [, appId, ...rest] = decodeURIComponent(pathname).split('/');
4
+ if (!appId || !Object.hasOwn(apps, appId)) return;
5
+ const root = node_path.resolve(apps[appId]);
6
+ const file = node_path.resolve(root, rest.join('/') || 'index.html');
7
+ if (file !== root && !file.startsWith(root + node_path.sep)) return;
8
+ return file;
9
+ }
10
+ export { resolveAppFile };
11
+
12
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.js","sources":["../src/resolve.ts"],"sourcesContent":["import path from 'node:path';\n\n/**\n * Maps a request pathname (`/<appId>/<file>`) to an absolute file path inside\n * the matching app directory. Returns `undefined` for unknown apps or for paths\n * that would escape the app directory.\n */\nexport function resolveAppFile(\n pathname: string,\n apps: Readonly<Record<string, string>>,\n): string | undefined {\n const [, appId, ...rest] = decodeURIComponent(pathname).split('/');\n if (!appId || !Object.hasOwn(apps, appId)) return undefined;\n\n const root = path.resolve(apps[appId] as string);\n const file = path.resolve(root, rest.join('/') || 'index.html');\n if (file !== root && !file.startsWith(root + path.sep)) return undefined;\n return file;\n}\n"],"names":["resolveAppFile","pathname","apps","appId","rest","decodeURIComponent","Object","root","path","file"],"mappings":";AAOO,SAASA,eACdC,QAAgB,EAChBC,IAAsC;IAEtC,MAAM,GAAGC,OAAO,GAAGC,KAAK,GAAGC,mBAAmBJ,UAAU,KAAK,CAAC;IAC9D,IAAI,CAACE,SAAS,CAACG,OAAO,MAAM,CAACJ,MAAMC,QAAQ;IAE3C,MAAMI,OAAOC,UAAAA,OAAY,CAACN,IAAI,CAACC,MAAM;IACrC,MAAMM,OAAOD,UAAAA,OAAY,CAACD,MAAMH,KAAK,IAAI,CAAC,QAAQ;IAClD,IAAIK,SAASF,QAAQ,CAACE,KAAK,UAAU,CAACF,OAAOC,UAAAA,GAAQ,GAAG;IACxD,OAAOC;AACT"}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ DEFAULT_HOST: ()=>external_url_cjs_namespaceObject.DEFAULT_HOST,
32
+ DEFAULT_SCHEME: ()=>external_url_cjs_namespaceObject.DEFAULT_SCHEME,
33
+ PLUGIN_ELECTRON_NAME: ()=>PLUGIN_ELECTRON_NAME,
34
+ federationBaseUrl: ()=>external_url_cjs_namespaceObject.federationBaseUrl,
35
+ federationUrl: ()=>external_url_cjs_namespaceObject.federationUrl,
36
+ pluginElectron: ()=>pluginElectron,
37
+ pluginModuleFederationElectron: ()=>pluginModuleFederationElectron,
38
+ toAppId: ()=>external_url_cjs_namespaceObject.toAppId
39
+ });
40
+ const rsbuild_plugin_namespaceObject = require("@module-federation/rsbuild-plugin");
41
+ const external_url_cjs_namespaceObject = require("./url.cjs");
42
+ const PLUGIN_ELECTRON_NAME = '@module-federation/electron:rsbuild';
43
+ function pluginElectron(name, options = {}) {
44
+ const { protocol = true, ...urlOptions } = options;
45
+ return {
46
+ name: PLUGIN_ELECTRON_NAME,
47
+ setup (api) {
48
+ api.modifyRsbuildConfig((config, { mergeRsbuildConfig })=>{
49
+ if (!protocol || 'build' !== api.context.action) return config;
50
+ if (api.getRsbuildConfig('original').output?.assetPrefix !== void 0) return config;
51
+ return mergeRsbuildConfig(config, {
52
+ output: {
53
+ assetPrefix: (0, external_url_cjs_namespaceObject.federationBaseUrl)(name, urlOptions)
54
+ }
55
+ });
56
+ });
57
+ }
58
+ };
59
+ }
60
+ function pluginModuleFederationElectron(federation, options = {}) {
61
+ if (!federation.name) throw new Error('[@module-federation/electron] `name` is required');
62
+ return [
63
+ (0, rsbuild_plugin_namespaceObject.pluginModuleFederation)(federation, options.rsbuild),
64
+ pluginElectron(federation.name, options.electron)
65
+ ];
66
+ }
67
+ exports.DEFAULT_HOST = __webpack_exports__.DEFAULT_HOST;
68
+ exports.DEFAULT_SCHEME = __webpack_exports__.DEFAULT_SCHEME;
69
+ exports.PLUGIN_ELECTRON_NAME = __webpack_exports__.PLUGIN_ELECTRON_NAME;
70
+ exports.federationBaseUrl = __webpack_exports__.federationBaseUrl;
71
+ exports.federationUrl = __webpack_exports__.federationUrl;
72
+ exports.pluginElectron = __webpack_exports__.pluginElectron;
73
+ exports.pluginModuleFederationElectron = __webpack_exports__.pluginModuleFederationElectron;
74
+ exports.toAppId = __webpack_exports__.toAppId;
75
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
76
+ "DEFAULT_HOST",
77
+ "DEFAULT_SCHEME",
78
+ "PLUGIN_ELECTRON_NAME",
79
+ "federationBaseUrl",
80
+ "federationUrl",
81
+ "pluginElectron",
82
+ "pluginModuleFederationElectron",
83
+ "toAppId"
84
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
85
+ Object.defineProperty(exports, '__esModule', {
86
+ value: true
87
+ });
88
+
89
+ //# sourceMappingURL=rsbuild.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rsbuild.cjs","sources":["webpack://webpack/runtime/define_property_getters","webpack://webpack/runtime/has_own_property","webpack://webpack/runtime/make_namespace_object","../src/rsbuild.ts"],"sourcesContent":["__webpack_require__.d = (exports, getters, values) => {\n\tvar define = (defs, kind) => {\n\t\tfor(var key in defs) {\n\t\t\tif(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {\n\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });\n\t\t\t}\n\t\t}\n\t};\n\tdefine(getters, \"get\");\n\tdefine(values, \"value\");\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import {\n type ModuleFederationOptions,\n pluginModuleFederation,\n} from '@module-federation/rsbuild-plugin';\nimport { type FederationUrlOptions, federationBaseUrl } from './url.ts';\nimport type { RsbuildPlugin, RsbuildPlugins } from '@rsbuild/core';\n\nexport type { ModuleFederationOptions };\nexport {\n DEFAULT_HOST,\n DEFAULT_SCHEME,\n federationBaseUrl,\n federationUrl,\n toAppId,\n type FederationUrlOptions,\n} from './url.ts';\n\nexport const PLUGIN_ELECTRON_NAME = '@module-federation/electron:rsbuild';\n\nexport interface ElectronFederationOptions extends FederationUrlOptions {\n /**\n * Point production asset URLs at the federation protocol\n * (`mf://local/<app-id>/`). Disable when the build is hosted elsewhere,\n * e.g. a CDN. An explicit `output.assetPrefix` always wins.\n * @default true\n */\n protocol?: boolean;\n}\n\nexport interface PluginOptions {\n electron?: ElectronFederationOptions;\n /** Passed through to `@module-federation/rsbuild-plugin`. */\n rsbuild?: Parameters<typeof pluginModuleFederation>[1];\n}\n\n/** Electron defaults layered on top of the Module Federation plugin. */\nexport function pluginElectron(\n name: string,\n options: ElectronFederationOptions = {},\n): RsbuildPlugin {\n const { protocol = true, ...urlOptions } = options;\n return {\n name: PLUGIN_ELECTRON_NAME,\n setup(api) {\n api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {\n if (!protocol || api.context.action !== 'build') return config;\n // `config` already has defaults merged in; check what the user actually wrote.\n if (api.getRsbuildConfig('original').output?.assetPrefix !== undefined) return config;\n return mergeRsbuildConfig(config, {\n output: { assetPrefix: federationBaseUrl(name, urlOptions) },\n });\n });\n },\n };\n}\n\n/**\n * Module Federation for an Electron renderer built with Rsbuild.\n *\n * ```ts\n * plugins: [pluginModuleFederationElectron({ name: 'host', remotes: { ... } })]\n * ```\n */\nexport function pluginModuleFederationElectron(\n federation: ModuleFederationOptions,\n options: PluginOptions = {},\n): RsbuildPlugins {\n if (!federation.name) {\n throw new Error('[@module-federation/electron] `name` is required');\n }\n return [\n pluginModuleFederation(federation, options.rsbuild),\n pluginElectron(federation.name, options.electron),\n ];\n}\n"],"names":["__webpack_require__","getters","values","define","defs","kind","key","Object","obj","prop","Symbol","PLUGIN_ELECTRON_NAME","pluginElectron","name","options","protocol","urlOptions","api","config","mergeRsbuildConfig","undefined","federationB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,MAAMG;oBAAY;gBAC7D;YACF;QACF;IACF;AACF;AASO,SAASM,+BACdC,UAAmC,EACnCT,UAAyB,CAAC,CAAC;IAE3B,IAAI,CAACS,WAAW,IAAI,EAClB,MAAM,IAAIC,MAAM;IAElB,OAAO;QACLC,IAAAA,+BAAAA,sBAAAA,AAAAA,EAAuBF,YAAYT,QAAQ,OAAO;QAClDF,eAAeW,WAAW,IAAI,EAAET,QAAQ,QAAQ;KACjD;AACH"}
@@ -0,0 +1,31 @@
1
+ import { type ModuleFederationOptions, pluginModuleFederation } from '@module-federation/rsbuild-plugin';
2
+ import { type FederationUrlOptions } from './url.cjs';
3
+ import type { RsbuildPlugin, RsbuildPlugins } from '@rsbuild/core';
4
+ export type { ModuleFederationOptions };
5
+ export { DEFAULT_HOST, DEFAULT_SCHEME, federationBaseUrl, federationUrl, toAppId, type FederationUrlOptions, } from './url.cjs';
6
+ export declare const PLUGIN_ELECTRON_NAME = "@module-federation/electron:rsbuild";
7
+ export interface ElectronFederationOptions extends FederationUrlOptions {
8
+ /**
9
+ * Point production asset URLs at the federation protocol
10
+ * (`mf://local/<app-id>/`). Disable when the build is hosted elsewhere,
11
+ * e.g. a CDN. An explicit `output.assetPrefix` always wins.
12
+ * @default true
13
+ */
14
+ protocol?: boolean;
15
+ }
16
+ export interface PluginOptions {
17
+ electron?: ElectronFederationOptions;
18
+ /** Passed through to `@module-federation/rsbuild-plugin`. */
19
+ rsbuild?: Parameters<typeof pluginModuleFederation>[1];
20
+ }
21
+ /** Electron defaults layered on top of the Module Federation plugin. */
22
+ export declare function pluginElectron(name: string, options?: ElectronFederationOptions): RsbuildPlugin;
23
+ /**
24
+ * Module Federation for an Electron renderer built with Rsbuild.
25
+ *
26
+ * ```ts
27
+ * plugins: [pluginModuleFederationElectron({ name: 'host', remotes: { ... } })]
28
+ * ```
29
+ */
30
+ export declare function pluginModuleFederationElectron(federation: ModuleFederationOptions, options?: PluginOptions): RsbuildPlugins;
31
+ //# sourceMappingURL=rsbuild.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rsbuild.d.cts","sourceRoot":"","sources":["../src/rsbuild.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,uBAAuB,EAC5B,sBAAsB,EACvB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,KAAK,oBAAoB,EAAqB,MAAM,UAAU,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEnE,YAAY,EAAE,uBAAuB,EAAE,CAAC;AACxC,OAAO,EACL,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,OAAO,EACP,KAAK,oBAAoB,GAC1B,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,oBAAoB,wCAAwC,CAAC;AAE1E,MAAM,WAAW,yBAA0B,SAAQ,oBAAoB;IACrE;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,yBAAyB,CAAC;IACrC,6DAA6D;IAC7D,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC;CACxD;AAED,wEAAwE;AACxE,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,yBAA8B,GACtC,aAAa,CAef;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC5C,UAAU,EAAE,uBAAuB,EACnC,OAAO,GAAE,aAAkB,GAC1B,cAAc,CAQhB"}
@@ -0,0 +1,31 @@
1
+ import { type ModuleFederationOptions, pluginModuleFederation } from '@module-federation/rsbuild-plugin';
2
+ import { type FederationUrlOptions } from './url.js';
3
+ import type { RsbuildPlugin, RsbuildPlugins } from '@rsbuild/core';
4
+ export type { ModuleFederationOptions };
5
+ export { DEFAULT_HOST, DEFAULT_SCHEME, federationBaseUrl, federationUrl, toAppId, type FederationUrlOptions, } from './url.js';
6
+ export declare const PLUGIN_ELECTRON_NAME = "@module-federation/electron:rsbuild";
7
+ export interface ElectronFederationOptions extends FederationUrlOptions {
8
+ /**
9
+ * Point production asset URLs at the federation protocol
10
+ * (`mf://local/<app-id>/`). Disable when the build is hosted elsewhere,
11
+ * e.g. a CDN. An explicit `output.assetPrefix` always wins.
12
+ * @default true
13
+ */
14
+ protocol?: boolean;
15
+ }
16
+ export interface PluginOptions {
17
+ electron?: ElectronFederationOptions;
18
+ /** Passed through to `@module-federation/rsbuild-plugin`. */
19
+ rsbuild?: Parameters<typeof pluginModuleFederation>[1];
20
+ }
21
+ /** Electron defaults layered on top of the Module Federation plugin. */
22
+ export declare function pluginElectron(name: string, options?: ElectronFederationOptions): RsbuildPlugin;
23
+ /**
24
+ * Module Federation for an Electron renderer built with Rsbuild.
25
+ *
26
+ * ```ts
27
+ * plugins: [pluginModuleFederationElectron({ name: 'host', remotes: { ... } })]
28
+ * ```
29
+ */
30
+ export declare function pluginModuleFederationElectron(federation: ModuleFederationOptions, options?: PluginOptions): RsbuildPlugins;
31
+ //# sourceMappingURL=rsbuild.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rsbuild.d.ts","sourceRoot":"","sources":["../src/rsbuild.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,uBAAuB,EAC5B,sBAAsB,EACvB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,KAAK,oBAAoB,EAAqB,MAAM,UAAU,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEnE,YAAY,EAAE,uBAAuB,EAAE,CAAC;AACxC,OAAO,EACL,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,OAAO,EACP,KAAK,oBAAoB,GAC1B,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,oBAAoB,wCAAwC,CAAC;AAE1E,MAAM,WAAW,yBAA0B,SAAQ,oBAAoB;IACrE;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,yBAAyB,CAAC;IACrC,6DAA6D;IAC7D,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC;CACxD;AAED,wEAAwE;AACxE,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,yBAA8B,GACtC,aAAa,CAef;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC5C,UAAU,EAAE,uBAAuB,EACnC,OAAO,GAAE,aAAkB,GAC1B,cAAc,CAQhB"}
@@ -0,0 +1,30 @@
1
+ import { pluginModuleFederation } from "@module-federation/rsbuild-plugin";
2
+ import { DEFAULT_HOST, DEFAULT_SCHEME, federationBaseUrl, federationUrl, toAppId } from "./url.js";
3
+ const PLUGIN_ELECTRON_NAME = '@module-federation/electron:rsbuild';
4
+ function pluginElectron(name, options = {}) {
5
+ const { protocol = true, ...urlOptions } = options;
6
+ return {
7
+ name: PLUGIN_ELECTRON_NAME,
8
+ setup (api) {
9
+ api.modifyRsbuildConfig((config, { mergeRsbuildConfig })=>{
10
+ if (!protocol || 'build' !== api.context.action) return config;
11
+ if (api.getRsbuildConfig('original').output?.assetPrefix !== void 0) return config;
12
+ return mergeRsbuildConfig(config, {
13
+ output: {
14
+ assetPrefix: federationBaseUrl(name, urlOptions)
15
+ }
16
+ });
17
+ });
18
+ }
19
+ };
20
+ }
21
+ function pluginModuleFederationElectron(federation, options = {}) {
22
+ if (!federation.name) throw new Error('[@module-federation/electron] `name` is required');
23
+ return [
24
+ pluginModuleFederation(federation, options.rsbuild),
25
+ pluginElectron(federation.name, options.electron)
26
+ ];
27
+ }
28
+ export { DEFAULT_HOST, DEFAULT_SCHEME, PLUGIN_ELECTRON_NAME, federationBaseUrl, federationUrl, pluginElectron, pluginModuleFederationElectron, toAppId };
29
+
30
+ //# sourceMappingURL=rsbuild.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rsbuild.js","sources":["../src/rsbuild.ts"],"sourcesContent":["import {\n type ModuleFederationOptions,\n pluginModuleFederation,\n} from '@module-federation/rsbuild-plugin';\nimport { type FederationUrlOptions, federationBaseUrl } from './url.ts';\nimport type { RsbuildPlugin, RsbuildPlugins } from '@rsbuild/core';\n\nexport type { ModuleFederationOptions };\nexport {\n DEFAULT_HOST,\n DEFAULT_SCHEME,\n federationBaseUrl,\n federationUrl,\n toAppId,\n type FederationUrlOptions,\n} from './url.ts';\n\nexport const PLUGIN_ELECTRON_NAME = '@module-federation/electron:rsbuild';\n\nexport interface ElectronFederationOptions extends FederationUrlOptions {\n /**\n * Point production asset URLs at the federation protocol\n * (`mf://local/<app-id>/`). Disable when the build is hosted elsewhere,\n * e.g. a CDN. An explicit `output.assetPrefix` always wins.\n * @default true\n */\n protocol?: boolean;\n}\n\nexport interface PluginOptions {\n electron?: ElectronFederationOptions;\n /** Passed through to `@module-federation/rsbuild-plugin`. */\n rsbuild?: Parameters<typeof pluginModuleFederation>[1];\n}\n\n/** Electron defaults layered on top of the Module Federation plugin. */\nexport function pluginElectron(\n name: string,\n options: ElectronFederationOptions = {},\n): RsbuildPlugin {\n const { protocol = true, ...urlOptions } = options;\n return {\n name: PLUGIN_ELECTRON_NAME,\n setup(api) {\n api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {\n if (!protocol || api.context.action !== 'build') return config;\n // `config` already has defaults merged in; check what the user actually wrote.\n if (api.getRsbuildConfig('original').output?.assetPrefix !== undefined) return config;\n return mergeRsbuildConfig(config, {\n output: { assetPrefix: federationBaseUrl(name, urlOptions) },\n });\n });\n },\n };\n}\n\n/**\n * Module Federation for an Electron renderer built with Rsbuild.\n *\n * ```ts\n * plugins: [pluginModuleFederationElectron({ name: 'host', remotes: { ... } })]\n * ```\n */\nexport function pluginModuleFederationElectron(\n federation: ModuleFederationOptions,\n options: PluginOptions = {},\n): RsbuildPlugins {\n if (!federation.name) {\n throw new Error('[@module-federation/electron] `name` is required');\n }\n return [\n pluginModuleFederation(federation, options.rsbuild),\n pluginElectron(federation.name, options.electron),\n ];\n}\n"],"names":["PLUGIN_ELECTRON_NAME","pluginElectron","name","options","protocol","urlOptions","api","config","mergeRsbuildConfig","undefined","federationBaseUrl","pluginModuleFederationElectron","federation","Error","pluginModuleFederation"],"mappings":";;AAiBO,MAAMA,uBAAuB;AAmB7B,SAASC,eACdC,IAAY,EACZC,UAAqC,CAAC,CAAC;IAEvC,MAAM,EAAEC,WAAW,IAAI,EAAE,GAAGC,YAAY,GAAGF;IAC3C,OAAO;QACL,MAAMH;QACN,OAAMM,GAAG;YACPA,IAAI,mBAAmB,CAAC,CAACC,QAAQ,EAAEC,kBAAkB,EAAE;gBACrD,IAAI,CAACJ,YAAYE,AAAuB,YAAvBA,IAAI,OAAO,CAAC,MAAM,EAAc,OAAOC;gBAExD,IAAID,IAAI,gBAAgB,CAAC,YAAY,MAAM,EAAE,gBAAgBG,QAAW,OAAOF;gBAC/E,OAAOC,mBAAmBD,QAAQ;oBAChC,QAAQ;wBAAE,aAAaG,kBAAkBR,MAAMG;oBAAY;gBAC7D;YACF;QACF;IACF;AACF;AASO,SAASM,+BACdC,UAAmC,EACnCT,UAAyB,CAAC,CAAC;IAE3B,IAAI,CAACS,WAAW,IAAI,EAClB,MAAM,IAAIC,MAAM;IAElB,OAAO;QACLC,uBAAuBF,YAAYT,QAAQ,OAAO;QAClDF,eAAeW,WAAW,IAAI,EAAET,QAAQ,QAAQ;KACjD;AACH"}
package/dist/url.cjs ADDED
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ const DEFAULT_SCHEME = 'mf';
31
+ const DEFAULT_HOST = 'local';
32
+ function toAppId(name) {
33
+ const id = name.toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, '');
34
+ if (!id) throw new Error(`Cannot derive an app id from federation name "${name}"`);
35
+ return id;
36
+ }
37
+ function federationBaseUrl(name, options = {}) {
38
+ const { scheme = DEFAULT_SCHEME, host = DEFAULT_HOST } = options;
39
+ return `${scheme}://${host}/${toAppId(name)}/`;
40
+ }
41
+ function federationUrl(name, file, options = {}) {
42
+ return new URL(file.replace(/^\/+/, ''), federationBaseUrl(name, options)).href;
43
+ }
44
+ __webpack_require__.d(__webpack_exports__, {}, {
45
+ DEFAULT_HOST: DEFAULT_HOST,
46
+ DEFAULT_SCHEME: DEFAULT_SCHEME,
47
+ federationBaseUrl: federationBaseUrl,
48
+ federationUrl: federationUrl,
49
+ toAppId: toAppId
50
+ });
51
+ exports.DEFAULT_HOST = __webpack_exports__.DEFAULT_HOST;
52
+ exports.DEFAULT_SCHEME = __webpack_exports__.DEFAULT_SCHEME;
53
+ exports.federationBaseUrl = __webpack_exports__.federationBaseUrl;
54
+ exports.federationUrl = __webpack_exports__.federationUrl;
55
+ exports.toAppId = __webpack_exports__.toAppId;
56
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
57
+ "DEFAULT_HOST",
58
+ "DEFAULT_SCHEME",
59
+ "federationBaseUrl",
60
+ "federationUrl",
61
+ "toAppId"
62
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
63
+ Object.defineProperty(exports, '__esModule', {
64
+ value: true
65
+ });
66
+
67
+ //# sourceMappingURL=url.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.cjs","sources":["webpack://webpack/runtime/define_property_getters","webpack://webpack/runtime/has_own_property","webpack://webpack/runtime/make_namespace_object","../src/url.ts"],"sourcesContent":["__webpack_require__.d = (exports, getters, values) => {\n\tvar define = (defs, kind) => {\n\t\tfor(var key in defs) {\n\t\t\tif(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {\n\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });\n\t\t\t}\n\t\t}\n\t};\n\tdefine(getters, \"get\");\n\tdefine(values, \"value\");\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/**\n * URL helpers shared by the main process and the bundler plugins. Must not import\n * `electron`: `./rsbuild` and `./vite` re-export these for use in build configs.\n */\n\n/** Default custom protocol scheme used to serve federated bundles inside Electron. */\nexport const DEFAULT_SCHEME = 'mf';\n\n/** Default host for the custom protocol. Every app shares it, so they share one origin. */\nexport const DEFAULT_HOST = 'local';\n\nexport interface FederationUrlOptions {\n scheme?: string;\n host?: string;\n}\n\n/**\n * Turns a Module Federation `name` (e.g. `remote_vite`) into the path segment\n * used on the custom protocol (e.g. `remote-vite`).\n */\nexport function toAppId(name: string): string {\n const id = name\n .toLowerCase()\n .replace(/[^a-z0-9-]+/g, '-')\n .replace(/^-+|-+$/g, '');\n if (!id) throw new Error(`Cannot derive an app id from federation name \"${name}\"`);\n return id;\n}\n\n/** Base URL an app is served from in production, e.g. `mf://local/remote-vite/`. */\nexport function federationBaseUrl(name: string, options: FederationUrlOptions = {}): string {\n const { scheme = DEFAULT_SCHEME, host = DEFAULT_HOST } = options;\n return `${scheme}://${host}/${toAppId(name)}/`;\n}\n\n/** URL of a file inside an app, e.g. `federationUrl('remote_vite', 'remoteEntry.js')`. */\nexport function federationUrl(\n name: string,\n file: string,\n options: FederationUrlOptions = {},\n): string {\n return new URL(file.replace(/^\\/+/, ''), federationBaseUrl(name, options)).href;\n}\n"],"names":["__webpack_require__","getters","values","define","defs","kind","key","Object","obj","prop","Symbol","DEFAULT_SCHEME","DEFAULT_HOST","toAppId","name","id","Error","federationBaseUrl","options","scheme","host","federationUrl","file","URL"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC,SAASC;QAC1C,IAAIC,SAAS,CAACC,MAAMC;YACnB,IAAI,IAAIC,OAAOF,KACd,IAAGJ,oBAAoB,CAAC,CAACI,MAAME,QAAQ,CAACN,oBAAoB,CAAC,CAAC,UAASM,MACtEC,OAAO,cAAc,CAAC,UAASD,KAAK;gBAAE,YAAY;gBAAM,CAACD,KAAK,EAAED,IAAI,CAACE,IAAI;YAAC;QAG7E;QACAH,OAAOF,SAAS;QAChBE,OAAOD,QAAQ;IAChB;;;ICVAF,oBAAoB,CAAC,GAAG,CAACQ,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFT,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,MAAlB,OAAOU,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;ACAO,MAAMI,iBAAiB;AAGvB,MAAMC,eAAe;AAWrB,SAASC,QAAQC,IAAY;IAClC,MAAMC,KAAKD,KACR,WAAW,GACX,OAAO,CAAC,gBAAgB,KACxB,OAAO,CAAC,YAAY;IACvB,IAAI,CAACC,IAAI,MAAM,IAAIC,MAAM,CAAC,8CAA8C,EAAEF,KAAK,CAAC,CAAC;IACjF,OAAOC;AACT;AAGO,SAASE,kBAAkBH,IAAY,EAAEI,UAAgC,CAAC,CAAC;IAChF,MAAM,EAAEC,SAASR,cAAc,EAAES,OAAOR,YAAY,EAAE,GAAGM;IACzD,OAAO,GAAGC,OAAO,GAAG,EAAEC,KAAK,CAAC,EAAEP,QAAQC,MAAM,CAAC,CAAC;AAChD;AAGO,SAASO,cACdP,IAAY,EACZQ,IAAY,EACZJ,UAAgC,CAAC,CAAC;IAElC,OAAO,IAAIK,IAAID,KAAK,OAAO,CAAC,QAAQ,KAAKL,kBAAkBH,MAAMI,UAAU,IAAI;AACjF"}
package/dist/url.d.cts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * URL helpers shared by the main process and the bundler plugins. Must not import
3
+ * `electron`: `./rsbuild` and `./vite` re-export these for use in build configs.
4
+ */
5
+ /** Default custom protocol scheme used to serve federated bundles inside Electron. */
6
+ export declare const DEFAULT_SCHEME = "mf";
7
+ /** Default host for the custom protocol. Every app shares it, so they share one origin. */
8
+ export declare const DEFAULT_HOST = "local";
9
+ export interface FederationUrlOptions {
10
+ scheme?: string;
11
+ host?: string;
12
+ }
13
+ /**
14
+ * Turns a Module Federation `name` (e.g. `remote_vite`) into the path segment
15
+ * used on the custom protocol (e.g. `remote-vite`).
16
+ */
17
+ export declare function toAppId(name: string): string;
18
+ /** Base URL an app is served from in production, e.g. `mf://local/remote-vite/`. */
19
+ export declare function federationBaseUrl(name: string, options?: FederationUrlOptions): string;
20
+ /** URL of a file inside an app, e.g. `federationUrl('remote_vite', 'remoteEntry.js')`. */
21
+ export declare function federationUrl(name: string, file: string, options?: FederationUrlOptions): string;
22
+ //# sourceMappingURL=url.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.d.cts","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sFAAsF;AACtF,eAAO,MAAM,cAAc,OAAO,CAAC;AAEnC,2FAA2F;AAC3F,eAAO,MAAM,YAAY,UAAU,CAAC;AAEpC,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO5C;AAED,oFAAoF;AACpF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,MAAM,CAG1F;AAED,0FAA0F;AAC1F,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,oBAAyB,GACjC,MAAM,CAER"}
package/dist/url.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * URL helpers shared by the main process and the bundler plugins. Must not import
3
+ * `electron`: `./rsbuild` and `./vite` re-export these for use in build configs.
4
+ */
5
+ /** Default custom protocol scheme used to serve federated bundles inside Electron. */
6
+ export declare const DEFAULT_SCHEME = "mf";
7
+ /** Default host for the custom protocol. Every app shares it, so they share one origin. */
8
+ export declare const DEFAULT_HOST = "local";
9
+ export interface FederationUrlOptions {
10
+ scheme?: string;
11
+ host?: string;
12
+ }
13
+ /**
14
+ * Turns a Module Federation `name` (e.g. `remote_vite`) into the path segment
15
+ * used on the custom protocol (e.g. `remote-vite`).
16
+ */
17
+ export declare function toAppId(name: string): string;
18
+ /** Base URL an app is served from in production, e.g. `mf://local/remote-vite/`. */
19
+ export declare function federationBaseUrl(name: string, options?: FederationUrlOptions): string;
20
+ /** URL of a file inside an app, e.g. `federationUrl('remote_vite', 'remoteEntry.js')`. */
21
+ export declare function federationUrl(name: string, file: string, options?: FederationUrlOptions): string;
22
+ //# sourceMappingURL=url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sFAAsF;AACtF,eAAO,MAAM,cAAc,OAAO,CAAC;AAEnC,2FAA2F;AAC3F,eAAO,MAAM,YAAY,UAAU,CAAC;AAEpC,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO5C;AAED,oFAAoF;AACpF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,MAAM,CAG1F;AAED,0FAA0F;AAC1F,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,oBAAyB,GACjC,MAAM,CAER"}
package/dist/url.js ADDED
@@ -0,0 +1,17 @@
1
+ const DEFAULT_SCHEME = 'mf';
2
+ const DEFAULT_HOST = 'local';
3
+ function toAppId(name) {
4
+ const id = name.toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, '');
5
+ if (!id) throw new Error(`Cannot derive an app id from federation name "${name}"`);
6
+ return id;
7
+ }
8
+ function federationBaseUrl(name, options = {}) {
9
+ const { scheme = DEFAULT_SCHEME, host = DEFAULT_HOST } = options;
10
+ return `${scheme}://${host}/${toAppId(name)}/`;
11
+ }
12
+ function federationUrl(name, file, options = {}) {
13
+ return new URL(file.replace(/^\/+/, ''), federationBaseUrl(name, options)).href;
14
+ }
15
+ export { DEFAULT_HOST, DEFAULT_SCHEME, federationBaseUrl, federationUrl, toAppId };
16
+
17
+ //# sourceMappingURL=url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.js","sources":["../src/url.ts"],"sourcesContent":["/**\n * URL helpers shared by the main process and the bundler plugins. Must not import\n * `electron`: `./rsbuild` and `./vite` re-export these for use in build configs.\n */\n\n/** Default custom protocol scheme used to serve federated bundles inside Electron. */\nexport const DEFAULT_SCHEME = 'mf';\n\n/** Default host for the custom protocol. Every app shares it, so they share one origin. */\nexport const DEFAULT_HOST = 'local';\n\nexport interface FederationUrlOptions {\n scheme?: string;\n host?: string;\n}\n\n/**\n * Turns a Module Federation `name` (e.g. `remote_vite`) into the path segment\n * used on the custom protocol (e.g. `remote-vite`).\n */\nexport function toAppId(name: string): string {\n const id = name\n .toLowerCase()\n .replace(/[^a-z0-9-]+/g, '-')\n .replace(/^-+|-+$/g, '');\n if (!id) throw new Error(`Cannot derive an app id from federation name \"${name}\"`);\n return id;\n}\n\n/** Base URL an app is served from in production, e.g. `mf://local/remote-vite/`. */\nexport function federationBaseUrl(name: string, options: FederationUrlOptions = {}): string {\n const { scheme = DEFAULT_SCHEME, host = DEFAULT_HOST } = options;\n return `${scheme}://${host}/${toAppId(name)}/`;\n}\n\n/** URL of a file inside an app, e.g. `federationUrl('remote_vite', 'remoteEntry.js')`. */\nexport function federationUrl(\n name: string,\n file: string,\n options: FederationUrlOptions = {},\n): string {\n return new URL(file.replace(/^\\/+/, ''), federationBaseUrl(name, options)).href;\n}\n"],"names":["DEFAULT_SCHEME","DEFAULT_HOST","toAppId","name","id","Error","federationBaseUrl","options","scheme","host","federationUrl","file","URL"],"mappings":"AAMO,MAAMA,iBAAiB;AAGvB,MAAMC,eAAe;AAWrB,SAASC,QAAQC,IAAY;IAClC,MAAMC,KAAKD,KACR,WAAW,GACX,OAAO,CAAC,gBAAgB,KACxB,OAAO,CAAC,YAAY;IACvB,IAAI,CAACC,IAAI,MAAM,IAAIC,MAAM,CAAC,8CAA8C,EAAEF,KAAK,CAAC,CAAC;IACjF,OAAOC;AACT;AAGO,SAASE,kBAAkBH,IAAY,EAAEI,UAAgC,CAAC,CAAC;IAChF,MAAM,EAAEC,SAASR,cAAc,EAAES,OAAOR,YAAY,EAAE,GAAGM;IACzD,OAAO,GAAGC,OAAO,GAAG,EAAEC,KAAK,CAAC,EAAEP,QAAQC,MAAM,CAAC,CAAC;AAChD;AAGO,SAASO,cACdP,IAAY,EACZQ,IAAY,EACZJ,UAAgC,CAAC,CAAC;IAElC,OAAO,IAAIK,IAAID,KAAK,OAAO,CAAC,QAAQ,KAAKL,kBAAkBH,MAAMI,UAAU,IAAI;AACjF"}
package/dist/vite.cjs ADDED
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ DEFAULT_HOST: ()=>external_url_cjs_namespaceObject.DEFAULT_HOST,
32
+ DEFAULT_SCHEME: ()=>external_url_cjs_namespaceObject.DEFAULT_SCHEME,
33
+ PLUGIN_ELECTRON_NAME: ()=>PLUGIN_ELECTRON_NAME,
34
+ electron: ()=>electron,
35
+ federationBaseUrl: ()=>external_url_cjs_namespaceObject.federationBaseUrl,
36
+ federationElectron: ()=>federationElectron,
37
+ federationUrl: ()=>external_url_cjs_namespaceObject.federationUrl,
38
+ toAppId: ()=>external_url_cjs_namespaceObject.toAppId
39
+ });
40
+ const vite_namespaceObject = require("@module-federation/vite");
41
+ const external_url_cjs_namespaceObject = require("./url.cjs");
42
+ const PLUGIN_ELECTRON_NAME = '@module-federation/electron:vite';
43
+ function electron(name, options = {}) {
44
+ const { protocol = true, ...urlOptions } = options;
45
+ return {
46
+ name: PLUGIN_ELECTRON_NAME,
47
+ config (config, { command }) {
48
+ if (!protocol || 'build' !== command || void 0 !== config.base) return;
49
+ return {
50
+ base: (0, external_url_cjs_namespaceObject.federationBaseUrl)(name, urlOptions)
51
+ };
52
+ }
53
+ };
54
+ }
55
+ function federationElectron(options, pluginOptions = {}) {
56
+ if (!options.name) throw new Error('[@module-federation/electron] `name` is required');
57
+ return [
58
+ ...(0, vite_namespaceObject.federation)(options),
59
+ electron(options.name, pluginOptions.electron)
60
+ ];
61
+ }
62
+ exports.DEFAULT_HOST = __webpack_exports__.DEFAULT_HOST;
63
+ exports.DEFAULT_SCHEME = __webpack_exports__.DEFAULT_SCHEME;
64
+ exports.PLUGIN_ELECTRON_NAME = __webpack_exports__.PLUGIN_ELECTRON_NAME;
65
+ exports.electron = __webpack_exports__.electron;
66
+ exports.federationBaseUrl = __webpack_exports__.federationBaseUrl;
67
+ exports.federationElectron = __webpack_exports__.federationElectron;
68
+ exports.federationUrl = __webpack_exports__.federationUrl;
69
+ exports.toAppId = __webpack_exports__.toAppId;
70
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
71
+ "DEFAULT_HOST",
72
+ "DEFAULT_SCHEME",
73
+ "PLUGIN_ELECTRON_NAME",
74
+ "electron",
75
+ "federationBaseUrl",
76
+ "federationElectron",
77
+ "federationUrl",
78
+ "toAppId"
79
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
80
+ Object.defineProperty(exports, '__esModule', {
81
+ value: true
82
+ });
83
+
84
+ //# sourceMappingURL=vite.cjs.map