Child/sub-application functionality for lifecycle management and integration with framework applications.
Configuration interface for child applications in a micro-frontends architecture.
/**
* Configuration for child/sub-applications
*/
interface ChildConfig {
/** Called before sub-application is mounted */
mount?: (options?: LifecycleOptions) => Promise<void> | void;
/** Called after sub-application is unmounted */
unmount?: (options?: LifecycleOptions) => Promise<void> | void;
/** Called during bootstrap phase (qiankun compatibility) */
bootstrap?: (options?: any) => Promise<void> | void;
}Options passed to lifecycle methods containing container and custom properties.
/**
* Options passed to lifecycle methods
*/
interface LifecycleOptions {
/** DOM container element where the app will be mounted */
container: Element;
/** Additional custom properties from the framework */
customProps?: Record<string, any>;
}Helper function to define child configuration with optional function wrapper.
/**
* Helper function to define child configuration
* @param config - Child configuration object or function returning config
* @returns Resolved child configuration
*/
function defineChildConfig(config: ChildConfig | (() => ChildConfig)): ChildConfig;Usage Examples:
import { defineChildConfig } from '@ice/plugin-icestark/types';
// Basic lifecycle configuration
export const icestark = defineChildConfig({
mount: (options) => {
console.log('Child app mounting in container:', options?.container);
// Initialize child app resources
},
unmount: (options) => {
console.log('Child app unmounting from container:', options?.container);
// Clean up child app resources
},
});
// Advanced configuration with async operations
export const icestark = defineChildConfig(() => ({
bootstrap: async (props) => {
// Initialize shared libraries, global state, etc.
await initializeSharedResources();
},
mount: async (options) => {
const { container, customProps } = options || {};
// Setup child app with custom properties
if (customProps?.theme) {
setTheme(customProps.theme);
}
// Perform mount operations
await startChildApp(container);
},
unmount: async (options) => {
// Cleanup operations
await stopChildApp();
clearGlobalState();
},
}));The child runtime automatically handles:
The plugin automatically generates lifecycle functions that:
bootstrap, mount, and unmount methodsThe plugin generates these functions automatically:
/**
* Bootstrap lifecycle (qiankun compatibility)
* Automatically generated - calls user's bootstrap method
*/
export async function bootstrap(props: any): Promise<void>;
/**
* Mount lifecycle
* Automatically generated - handles React root creation and calls user's mount method
*/
export async function mount(props: any): Promise<void>;
/**
* Unmount lifecycle
* Automatically generated - handles React root cleanup and calls user's unmount method
*/
export async function unmount(props: any): Promise<void>;The child runtime resolves the rendering container in this order:
#ice-container within provided containerruntimeOptions if providedChild applications automatically receive framework context data through the FrameworkContext provider. This allows child apps to access:
The plugin automatically:
window.ICESTARK.library to the configured library nameChild applications only render when:
This prevents issues with multiple micro-frontend frameworks and ensures proper lifecycle management.