diff --git a/src/index.ts b/src/index.ts index e484ada..7254b10 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,7 +10,7 @@ import { normalizeModuleFederationOptions } from './utils/normalizeModuleFederationOptions'; import normalizeOptimizeDepsPlugin from './utils/normalizeOptimizeDeps'; -import { HOST_AUTO_INIT, WRAP_REMOTE_ENTRY_PATH } from './virtualModules/virtualRemoteEntry'; +import { HOST_AUTO_INIT_PATH, WRAP_REMOTE_ENTRY_PATH } from './virtualModules/virtualRemoteEntry'; function federation(mfUserOptions: ModuleFederationOptions): Plugin[] { const options = normalizeModuleFederationOptions(mfUserOptions); @@ -28,7 +28,7 @@ function federation(mfUserOptions: ModuleFederationOptions): Plugin[] { }), ...addEntry({ entryName: 'hostInit', - entryPath: HOST_AUTO_INIT, + entryPath: HOST_AUTO_INIT_PATH, }), pluginProxyRemoteEntry(), pluginProxyRemotes(options), diff --git a/src/plugins/pluginProxyRemoteEntry.ts b/src/plugins/pluginProxyRemoteEntry.ts index a6cafd2..ad20da7 100644 --- a/src/plugins/pluginProxyRemoteEntry.ts +++ b/src/plugins/pluginProxyRemoteEntry.ts @@ -1,7 +1,7 @@ import { createFilter } from '@rollup/pluginutils'; import { Plugin } from 'vite'; import { getNormalizeModuleFederationOptions } from '../utils/normalizeModuleFederationOptions'; -import { generateRemoteEntry, generateWrapHostInit, generateWrapRemoteEntry, HOST_AUTO_INIT, REMOTE_ENTRY_ID, WRAP_REMOTE_ENTRY_PATH } from '../virtualModules/virtualRemoteEntry'; +import { generateRemoteEntry, generateWrapHostInit, generateWrapRemoteEntry, HOST_AUTO_INIT_QUERY_STR, REMOTE_ENTRY_ID, WRAP_REMOTE_ENTRY_QUERY_STR } from '../virtualModules/virtualRemoteEntry'; const filter: (id: string) => boolean = createFilter(); @@ -21,13 +21,13 @@ export default function (): Plugin { }, async transform(code: string, id: string) { if (!filter(id)) return; - if (id === REMOTE_ENTRY_ID) { + if (id.includes(REMOTE_ENTRY_ID)) { return generateRemoteEntry(getNormalizeModuleFederationOptions()); } - if (id.includes(WRAP_REMOTE_ENTRY_PATH)) { + if (id.includes(WRAP_REMOTE_ENTRY_QUERY_STR)) { return generateWrapRemoteEntry(); } - if (id.includes(HOST_AUTO_INIT)) { + if (id.includes(HOST_AUTO_INIT_QUERY_STR)) { return generateWrapHostInit(); } }, diff --git a/src/virtualModules/virtualRemoteEntry.ts b/src/virtualModules/virtualRemoteEntry.ts index 0d73d38..d720483 100644 --- a/src/virtualModules/virtualRemoteEntry.ts +++ b/src/virtualModules/virtualRemoteEntry.ts @@ -96,7 +96,8 @@ export function generateRemoteEntry(options: NormalizedModuleFederationOptions): `; } -export const WRAP_REMOTE_ENTRY_PATH = emptyPath + '?__mf__wrapRemoteEntry__' +export const WRAP_REMOTE_ENTRY_QUERY_STR = "__mf__wrapRemoteEntry__" +export const WRAP_REMOTE_ENTRY_PATH = emptyPath + '?' + WRAP_REMOTE_ENTRY_QUERY_STR export function generateWrapRemoteEntry(): string { return ` import {init, get} from "${REMOTE_ENTRY_ID}" @@ -108,7 +109,8 @@ export function generateWrapRemoteEntry(): string { * Inject entry file, automatically init when used as host, * and will not inject remoteEntry */ -export const HOST_AUTO_INIT = emptyPath + '?__mf__isHostInit' +export const HOST_AUTO_INIT_QUERY_STR = "__mf__isHostInit" +export const HOST_AUTO_INIT_PATH = emptyPath + '?' + HOST_AUTO_INIT_QUERY_STR export function generateWrapHostInit(): string { return ` import {init} from "${REMOTE_ENTRY_ID}"