From d07e73edc7bb858767a795acae1c8d96ecc3fb19 Mon Sep 17 00:00:00 2001 From: zhangHongEn Date: Fri, 4 Oct 2024 09:14:58 +0800 Subject: [PATCH 1/2] fix: fix publicPath; feat: getPublicPath --- src/plugins/pluginMFManifest.ts | 4 +++- src/utils/normalizeModuleFederationOptions.ts | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/plugins/pluginMFManifest.ts b/src/plugins/pluginMFManifest.ts index 03467dc..4ca243c 100644 --- a/src/plugins/pluginMFManifest.ts +++ b/src/plugins/pluginMFManifest.ts @@ -8,7 +8,7 @@ import { getPreBuildLibImportId, getUsedRemotesMap, getUsedShares } from '../vir const Manifest = (): Plugin[] => { const mfOptions = getNormalizeModuleFederationOptions(); - const { name, filename, manifest: manifestOptions } = mfOptions; + const { name, filename, getPublicPath, manifest: manifestOptions } = mfOptions; let mfManifestName: string = ''; if (manifestOptions === true) { mfManifestName = 'mf-manifest.json'; @@ -63,6 +63,7 @@ const Manifest = (): Plugin[] => { types: { path: '', name: '' }, globalName: name, pluginVersion: '0.2.5', + publicPath }, }) ); @@ -321,6 +322,7 @@ const Manifest = (): Plugin[] => { }, globalName: name, pluginVersion: '0.2.5', + ...(!!getPublicPath ? { getPublicPath } : { publicPath }), }, shared, remotes, diff --git a/src/utils/normalizeModuleFederationOptions.ts b/src/utils/normalizeModuleFederationOptions.ts index b6d54ed..9154dfd 100644 --- a/src/utils/normalizeModuleFederationOptions.ts +++ b/src/utils/normalizeModuleFederationOptions.ts @@ -244,7 +244,6 @@ export type ModuleFederationOptions = { > | undefined; runtimePlugins?: string[]; - publicPath?: string; getPublicPath?: string; implementation?: any; manifest?: ManifestOptions | boolean; @@ -269,6 +268,7 @@ export interface NormalizedModuleFederationOptions { dev?: boolean | PluginDevOptions; dts?: boolean | PluginDtsOptions; shareStrategy?: ShareStrategy; + getPublicPath?: string } interface PluginDevOptions { @@ -322,9 +322,9 @@ export function getNormalizeShareItem(key: string) { export function normalizeModuleFederationOptions( options: ModuleFederationOptions ): NormalizedModuleFederationOptions { - if (options.getPublicPath || options.publicPath) { + if (options.getPublicPath) { warn( - `We are ignoring the getPublicPath and publicPath options because they are natively supported by Vite\nwith the "experimental.renderBuiltUrl" configuration https://vitejs.dev/guide/build#advanced-base-options` + `We are ignoring the getPublicPath options because they are natively supported by Vite\nwith the "experimental.renderBuiltUrl" configuration https://vitejs.dev/guide/build#advanced-base-options` ); } return (config = { @@ -342,6 +342,7 @@ export function normalizeModuleFederationOptions( manifest: normalizeManifest(options.manifest), dev: options.dev, dts: options.dts, + getPublicPath: options.getPublicPath, shareStrategy: options.shareStrategy, }); } From b159dd821276f4338c59d3514018b831529ad6e6 Mon Sep 17 00:00:00 2001 From: zhangHongEn Date: Fri, 4 Oct 2024 09:18:03 +0800 Subject: [PATCH 2/2] fix: format code --- src/plugins/pluginMFManifest.ts | 2 +- src/utils/normalizeModuleFederationOptions.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/pluginMFManifest.ts b/src/plugins/pluginMFManifest.ts index 4ca243c..61029e6 100644 --- a/src/plugins/pluginMFManifest.ts +++ b/src/plugins/pluginMFManifest.ts @@ -63,7 +63,7 @@ const Manifest = (): Plugin[] => { types: { path: '', name: '' }, globalName: name, pluginVersion: '0.2.5', - publicPath + publicPath, }, }) ); diff --git a/src/utils/normalizeModuleFederationOptions.ts b/src/utils/normalizeModuleFederationOptions.ts index 9154dfd..6fc071a 100644 --- a/src/utils/normalizeModuleFederationOptions.ts +++ b/src/utils/normalizeModuleFederationOptions.ts @@ -268,7 +268,7 @@ export interface NormalizedModuleFederationOptions { dev?: boolean | PluginDevOptions; dts?: boolean | PluginDtsOptions; shareStrategy?: ShareStrategy; - getPublicPath?: string + getPublicPath?: string; } interface PluginDevOptions {