Back to Qiankun

Index

docs/index.md

2.10.162.8 KB
Original Source

📦 Installation

::: code-group

bash
npm install qiankun
bash
yarn add qiankun
bash
pnpm add qiankun

:::

🔨 Quick Start

Main Application

typescript
import { registerMicroApps, start } from 'qiankun';

// register micro apps
registerMicroApps([
  {
    name: 'reactApp',
    entry: '//localhost:7100',
    container: '#yourContainer',
    activeRule: '/yourActiveRule',
  },
  {
    name: 'vueApp',
    entry: { scripts: ['//localhost:7100/main.js'] },
    container: '#yourContainer2',
    activeRule: '/yourActiveRule2',
  },
]);

// start qiankun
start();

Micro Application

typescript
/**
 * bootstrap will only be called once when the micro application is initialized
 * mount will be called every time the micro application enters
 * unmount will be called every time the micro application leaves
 */
export async function bootstrap() {
  console.log('react app bootstraped');
}

export async function mount(props) {
  ReactDOM.render(<App />, props.container ? props.container.querySelector('#root') : document.getElementById('root'));
}

export async function unmount(props) {
  ReactDOM.unmountComponentAtNode(
    props.container ? props.container.querySelector('#root') : document.getElementById('root'),
  );
}

🌟 Why qiankun?

<div class="features-grid"> <div class="feature-card"> <h3>🎯 Zero Intrusion</h3> <p>Almost no intrusion to existing applications, only need to expose necessary lifecycle functions</p> </div> <div class="feature-card"> <h3>📱 All Scenarios</h3> <p>Supports both route-based and manual loading of micro applications</p> </div> <div class="feature-card"> <h3>🔒 Secure Isolation</h3> <p>Complete sandbox solution with JS isolation and CSS isolation</p> </div> <div class="feature-card"> <h3>⚡ High Performance</h3> <p>Supports preloading, caching and other performance optimization solutions</p> </div> </div>

👥 Community

GitHub DiscussionsDingTalk GroupWeChat Group
qiankun discussionsview group QR code
<style> .features-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; margin: 2rem 0; } .feature-card { padding: 1.5rem; border: 1px solid var(--vp-c-divider); border-radius: 8px; transition: border-color 0.25s; } .feature-card:hover { border-color: var(--vp-c-brand-1); } .feature-card h3 { margin: 0 0 0.5rem 0; font-size: 1.1rem; } .feature-card p { margin: 0; font-size: 0.9rem; color: var(--vp-c-text-2); line-height: 1.5; } </style>