Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: qiankun plugin compatible with ssr runtime #12295

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/plugins/libs/qiankun/master/masterRuntimePlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ export async function render(oldRender: typeof noop) {
}

export function patchClientRoutes({ routes }: { routes: any[] }) {
if (typeof window === 'undefined') {
bravepg marked this conversation as resolved.
Show resolved Hide resolved
return;
}
const microAppRoutes = [].concat(
deepFilterLeafRoutes(routes),
deepFilterLeafRoutes(microAppRuntimeRoutes),
Expand Down
11 changes: 11 additions & 0 deletions packages/plugins/src/qiankun/master.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,15 @@ export { MicroAppWithMemoHistory } from './MicroAppWithMemoHistory';
`,
});
});

api.modifyConfig({
before: 'ssr',
bravepg marked this conversation as resolved.
Show resolved Hide resolved
fn: (memo) => {
if (memo.ssr) {
memo.externals ??= {};
memo.externals.qiankun = 'fs';
bravepg marked this conversation as resolved.
Show resolved Hide resolved
}
return memo;
},
});
};
9 changes: 6 additions & 3 deletions packages/plugins/src/qiankun/slave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ export interface IRuntimeConfig {
];
});

api.chainWebpack((config) => {
api.chainWebpack((config, { ssr }: any) => {
bravepg marked this conversation as resolved.
Show resolved Hide resolved
if (ssr) {
return;
}
assert(api.pkg.name, 'You should have name in package.json.');
// 默认不修改 library chunk 的 name,从而确保可以通过 window[appName] 访问到导出
// mfsu 关闭的时候才可以修改,否则可能导致配合 mfsu 时,子应用的 umd chunk 无法被正确加载
Expand Down Expand Up @@ -223,11 +226,11 @@ export interface IRuntimeConfig {

api.addEntryCode(() => [
`
export const bootstrap = qiankun_genBootstrap(render);
export const bootstrap = qiankun_genBootstrap(typeof window !== 'undefined' ? render : () => {});
bravepg marked this conversation as resolved.
Show resolved Hide resolved
export const mount = qiankun_genMount('${api.config.mountElementId}');
export const unmount = qiankun_genUnmount('${api.config.mountElementId}');
export const update = qiankun_genUpdate();
if (!window.__POWERED_BY_QIANKUN__) {
if (typeof window !== 'undefined' && !window.__POWERED_BY_QIANKUN__) {
bootstrap().then(mount);
}
`,
Expand Down
Loading