Skip to content

Commit

Permalink
fix: #214 hack vite-plugin-top-level-await
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangHongEn committed Dec 15, 2024
1 parent aaa23f5 commit cc5a226
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/plugins/pluginProxyRemoteEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ export default function (): Plugin {
? viteConfig.server.host
: 'localhost';
return `
const {init} = await import("//${host}:${viteConfig.server?.port}${viteConfig.base + options.filename}")
init()
const remoteEntry = await import("//${host}:${viteConfig.server?.port}${viteConfig.base + options.filename}")
// __tla only serves as a hack for vite-plugin-top-level-await.
Promise.resolve(remoteEntry.__tla)
.then(remoteEntry.init).catch(remoteEntry.init)
`;
}
return code;
Expand Down
6 changes: 4 additions & 2 deletions src/virtualModules/virtualRemoteEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@ export const HOST_AUTO_INIT_TAG = '__H_A_I__';
const hostAutoInitModule = new VirtualModule('hostAutoInit', HOST_AUTO_INIT_TAG);
export function writeHostAutoInit() {
hostAutoInitModule.writeSync(`
import {init} from "${REMOTE_ENTRY_ID}"
init()
const remoteEntry = await import("${REMOTE_ENTRY_ID}")
// __tla only serves as a hack for vite-plugin-top-level-await.
Promise.resolve(remoteEntry.__tla)
.then(remoteEntry.init).catch(remoteEntry.init)
`);
}
export function getHostAutoInitImportId() {
Expand Down

0 comments on commit cc5a226

Please sign in to comment.