Skip to content

Commit

Permalink
fix: windows remoteEntry error (#48)
Browse files Browse the repository at this point in the history
Co-authored-by: 张洪恩 <[email protected]>
  • Loading branch information
zhangHongEn and 张洪恩 authored Aug 11, 2024
1 parent 6c2616f commit 10dfd75
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -28,7 +28,7 @@ function federation(mfUserOptions: ModuleFederationOptions): Plugin[] {
}),
...addEntry({
entryName: 'hostInit',
entryPath: HOST_AUTO_INIT,
entryPath: HOST_AUTO_INIT_PATH,
}),
pluginProxyRemoteEntry(),
pluginProxyRemotes(options),
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/pluginProxyRemoteEntry.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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();
}
},
Expand Down
6 changes: 4 additions & 2 deletions src/virtualModules/virtualRemoteEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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}"
Expand Down

0 comments on commit 10dfd75

Please sign in to comment.