From 36f1e2e1e571fa8a3f62791d45f44b67f6d4c093 Mon Sep 17 00:00:00 2001 From: gioboa Date: Wed, 25 Sep 2024 22:01:32 +0200 Subject: [PATCH 1/2] feat: manage getPublicPath --- src/plugins/pluginMFManifest.ts | 6 +++--- src/utils/normalizeModuleFederationOptions.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plugins/pluginMFManifest.ts b/src/plugins/pluginMFManifest.ts index 82199ec..4b75643 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'; @@ -62,7 +62,7 @@ const Manifest = (): Plugin[] => { types: { path: '', name: '' }, globalName: name, pluginVersion: '0.2.5', - publicPath, + ...(!!getPublicPath ? { getPublicPath } : { publicPath }), }, shared: Array.from(getUsedShares()).map((shareKey) => { const shareItem = getNormalizeShareItem(shareKey); @@ -378,7 +378,7 @@ const Manifest = (): Plugin[] => { }, globalName: name, pluginVersion: '0.2.5', - publicPath, + ...(!!getPublicPath ? { getPublicPath } : { publicPath }), }, shared, remotes, diff --git a/src/utils/normalizeModuleFederationOptions.ts b/src/utils/normalizeModuleFederationOptions.ts index fe435e1..e2f150d 100644 --- a/src/utils/normalizeModuleFederationOptions.ts +++ b/src/utils/normalizeModuleFederationOptions.ts @@ -243,7 +243,7 @@ export type ModuleFederationOptions = { > | undefined; runtimePlugins?: string[]; - getPublicPath?: any; + getPublicPath?: string; implementation?: any; manifest?: ManifestOptions | boolean; dev?: any; @@ -262,7 +262,7 @@ export interface NormalizedModuleFederationOptions { shareScope: string; shared: NormalizedShared; runtimePlugins: string[]; - getPublicPath: any; + getPublicPath?: string; implementation: any; manifest: ManifestOptions | boolean; dev: any; From 95cbc8c79599c8ba8eb27167f9089b1d4024ece1 Mon Sep 17 00:00:00 2001 From: gioboa Date: Wed, 2 Oct 2024 11:14:00 +0200 Subject: [PATCH 2/2] docs: add warn message for publicPath and getPublicPath --- src/plugins/pluginMFManifest.ts | 4 +--- src/utils/logUtils.ts | 2 ++ src/utils/normalizeModuleFederationOptions.ts | 9 +++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 src/utils/logUtils.ts diff --git a/src/plugins/pluginMFManifest.ts b/src/plugins/pluginMFManifest.ts index 5643b17..03467dc 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, getPublicPath, manifest: manifestOptions } = mfOptions; + const { name, filename, manifest: manifestOptions } = mfOptions; let mfManifestName: string = ''; if (manifestOptions === true) { mfManifestName = 'mf-manifest.json'; @@ -63,7 +63,6 @@ const Manifest = (): Plugin[] => { types: { path: '', name: '' }, globalName: name, pluginVersion: '0.2.5', - ...(!!getPublicPath ? { getPublicPath } : { publicPath }), }, }) ); @@ -322,7 +321,6 @@ const Manifest = (): Plugin[] => { }, globalName: name, pluginVersion: '0.2.5', - ...(!!getPublicPath ? { getPublicPath } : { publicPath }), }, shared, remotes, diff --git a/src/utils/logUtils.ts b/src/utils/logUtils.ts new file mode 100644 index 0000000..c3e7069 --- /dev/null +++ b/src/utils/logUtils.ts @@ -0,0 +1,2 @@ +export const warn = (message: string) => + message.split('\n').forEach((msg) => console.warn('\x1b[33m%s\x1b[0m', msg)); diff --git a/src/utils/normalizeModuleFederationOptions.ts b/src/utils/normalizeModuleFederationOptions.ts index 0b6c300..90fd202 100644 --- a/src/utils/normalizeModuleFederationOptions.ts +++ b/src/utils/normalizeModuleFederationOptions.ts @@ -22,6 +22,7 @@ export type RemoteEntryType = | string; import * as path from 'pathe'; +import { warn } from './logUtils'; interface ExposesItem { import: string; @@ -243,6 +244,7 @@ export type ModuleFederationOptions = { > | undefined; runtimePlugins?: string[]; + publicPath?: string; getPublicPath?: string; implementation?: any; manifest?: ManifestOptions | boolean; @@ -262,7 +264,6 @@ export interface NormalizedModuleFederationOptions { shareScope: string; shared: NormalizedShared; runtimePlugins: string[]; - getPublicPath?: string; implementation: any; manifest: ManifestOptions | boolean; dev?: boolean | PluginDevOptions; @@ -321,6 +322,11 @@ export function getNormalizeShareItem(key: string) { export function normalizeModuleFederationOptions( options: ModuleFederationOptions ): NormalizedModuleFederationOptions { + if (options.getPublicPath || options.publicPath) { + 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` + ); + } return (config = { exposes: normalizeExposes(options.exposes), filename: options.filename || 'remoteEntry-[hash]', @@ -332,7 +338,6 @@ export function normalizeModuleFederationOptions( shareScope: options.shareScope || 'default', shared: normalizeShared(options.shared), runtimePlugins: options.runtimePlugins || [], - getPublicPath: options.getPublicPath, implementation: options.implementation, manifest: normalizeManifest(options.manifest), dev: options.dev,