From 84aa2c60997d4dd94e655d3176cff24b3e880a2e Mon Sep 17 00:00:00 2001 From: Giorgio Boa <35845425+gioboa@users.noreply.github.com> Date: Thu, 3 Oct 2024 09:30:07 +0200 Subject: [PATCH] chore: add warn message for publicPath and getPublicPath (#108) --- src/plugins/pluginMFManifest.ts | 2 -- src/utils/logUtils.ts | 2 ++ src/utils/normalizeModuleFederationOptions.ts | 11 ++++++++--- 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 f7612f4..03467dc 100644 --- a/src/plugins/pluginMFManifest.ts +++ b/src/plugins/pluginMFManifest.ts @@ -63,7 +63,6 @@ const Manifest = (): Plugin[] => { types: { path: '', name: '' }, globalName: name, pluginVersion: '0.2.5', - publicPath, }, }) ); @@ -322,7 +321,6 @@ const Manifest = (): Plugin[] => { }, globalName: name, pluginVersion: '0.2.5', - 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 e3075fb..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,7 +244,8 @@ export type ModuleFederationOptions = { > | undefined; runtimePlugins?: string[]; - getPublicPath?: any; + publicPath?: string; + getPublicPath?: string; implementation?: any; manifest?: ManifestOptions | boolean; dev?: boolean | PluginDevOptions; @@ -262,7 +264,6 @@ export interface NormalizedModuleFederationOptions { shareScope: string; shared: NormalizedShared; runtimePlugins: string[]; - getPublicPath: any; 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,