Skip to content

Commit

Permalink
feat: support external qiankun
Browse files Browse the repository at this point in the history
  • Loading branch information
bravepg committed Aug 12, 2024
1 parent 6d252c6 commit 0a1b9a2
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/ui-bindings/shared/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { AppConfiguration, MicroApp as MicroAppTypeDefinition, LifeCycles } from 'qiankun';
import { loadMicroApp } from 'qiankun';
import type { AppConfiguration, MicroApp as MicroAppTypeDefinition, LifeCycles, LifeCycleFn } from 'qiankun';
import { loadMicroApp as originLoadMicroApp } from 'qiankun';
import { mergeWith, concat, omit } from 'lodash';
import type { LifeCycleFn } from 'qiankun';

export type MicroAppType = {
_unmounting?: boolean;
Expand All @@ -20,6 +19,8 @@ export type SharedProps = {
// 仅开启 loader 时需要
wrapperClassName?: string;
className?: string;

externalQiankun?: boolean;
};

export type SharedSlots<T> = {
Expand All @@ -28,7 +29,7 @@ export type SharedSlots<T> = {
};

export const omitSharedProps = (props: Partial<SharedProps>) => {
return omit(props, ['wrapperClassName', 'className', 'lifeCycles', 'settings', 'entry', 'name']);
return omit(props, ['wrapperClassName', 'className', 'lifeCycles', 'settings', 'entry', 'name', 'externalQiankun']);
};

export async function mountMicroApp({
Expand Down Expand Up @@ -63,6 +64,14 @@ export async function mountMicroApp({
...(componentProps.settings || {}),
};

let loadMicroApp = originLoadMicroApp;
if (componentProps.externalQiankun) {
console.warn('the qiankun is external');
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
loadMicroApp = (window.qiankun as unknown)?.loadMicroApp as typeof originLoadMicroApp;
}

const microApp = loadMicroApp(
{
name: componentProps.name,
Expand Down

0 comments on commit 0a1b9a2

Please sign in to comment.