docs/ecosystem/create-qiankun.md
create-qiankun is a CLI scaffolding tool designed specifically for the qiankun micro-frontend framework. It helps developers quickly bootstrap example projects and get started with micro-frontend development efficiently.
npx create-qiankun@latest
yarn create qiankun@latest
pnpm dlx create-qiankun@latest
When you run create-qiankun, you'll be guided through an interactive setup process:
? Project name: āŗ my-qiankun-project
? Choose a way to create āŗ
⯠Create main application and sub applications
Just create main application
Just create sub applications
Options:
? Choose a framework for your main application āŗ
⯠React18+Webpack
Vue3+Webpack
React18+umi4
? Choose a route pattern for your main application āŗ
⯠hash
history
? Choose a framework for your sub application āŗ
Space to select. Return to submit.
āÆāÆ React18+Webpack
⯠Vue3+Webpack
⯠Vue2+Webpack
⯠React18+umi4
? Which package manager do you want to use? āŗ
⯠npm
yarn
pnpm
pnpm with workspace
| Template | Description | Features |
|---|---|---|
| React18+Webpack | React 18 with Webpack 5 | Modern React, TypeScript support, Hot reload |
| Vue3+Webpack | Vue 3 with Vue CLI | Composition API, TypeScript, Element Plus |
| React18+umi4 | Umi 4 framework | Built-in qiankun support, Ant Design Pro |
| Template | Description | Status | Notes |
|---|---|---|---|
| React18+Webpack | React 18 micro app | ā Stable | Production ready |
| Vue3+Webpack | Vue 3 micro app | ā Stable | Production ready |
| Vue2+Webpack | Vue 2 micro app | ā ļø Limited | Issues with pnpm workspace |
| React18+umi4 | Umi 4 micro app | ā Stable | Built-in micro app support |
| Vite+Vue3 | Vue 3 with Vite | š§ WIP | Under development |
| Vite+React18 | React 18 with Vite | š§ WIP | Under development |
my-qiankun-project/
āāā main-app/ # Main application
ā āāā src/
ā āāā package.json
ā āāā webpack.config.js
āāā react18-sub/ # React micro app
ā āāā src/
ā āāā package.json
ā āāā webpack.config.js
āāā vue3-sub/ # Vue micro app
ā āāā src/
ā āāā package.json
ā āāā vue.config.js
āāā package.json
my-qiankun-project/
āāā packages/
ā āāā main-app/ # Main application
ā āāā react18-sub/ # React micro app
ā āāā vue3-sub/ # Vue micro app
āāā package.json # Workspace configuration
āāā pnpm-workspace.yaml # Workspace definition
āāā scripts/
āāā checkPnpm.js # Package manager validation
The main application is automatically configured with:
// Main app micro app registration
import { registerMicroApps, start } from 'qiankun';
registerMicroApps([
{
name: 'react18-sub',
entry: '//localhost:8080',
container: '#subapp-viewport',
activeRule: '/react18-sub',
},
{
name: 'vue3-sub',
entry: '//localhost:8081',
container: '#subapp-viewport',
activeRule: '/vue3-sub',
}
]);
start();
Each micro application includes:
React Micro App:
// webpack.config.js
const { QiankunWebpackPlugin } = require('@qiankunjs/webpack-plugin');
module.exports = {
plugins: [
new QiankunWebpackPlugin()
]
};
Vue Micro App:
// vue.config.js
const { defineConfig } = require('@vue/cli-service');
const { QiankunWebpackPlugin } = require('@qiankunjs/webpack-plugin');
module.exports = defineConfig({
configureWebpack: {
plugins: [
new QiankunWebpackPlugin()
]
}
});
Automatic port assignment prevents conflicts:
{
"scripts": {
"dev": "PORT=8080 react-scripts start",
"check-port": "node scripts/checkPort.js"
}
}
// config/development.js
module.exports = {
microApps: [
{
name: 'react-app',
entry: '//localhost:8080',
activeRule: '/react-app'
}
]
};
// config/production.js
module.exports = {
microApps: [
{
name: 'react-app',
entry: '//app.example.com',
activeRule: '/react-app'
}
]
};
// Hash routing (default)
const router = createRouter({
history: createWebHashHistory(),
routes: [...]
});
// History routing
const router = createRouter({
history: createWebHistory(),
routes: [...]
});
# Start main application
cd main-app && npm run dev
# Start micro applications (in separate terminals)
cd react18-sub && npm run dev
cd vue3-sub && npm run dev
# Install all dependencies
pnpm install
# Start all applications concurrently
pnpm run dev
# Start specific application
pnpm --filter main-app run dev
pnpm --filter react18-sub run dev
The CLI automatically injects useful scripts:
{
"scripts": {
"dev": "concurrently \"npm run dev:main\" \"npm run dev:subs\"",
"dev:main": "cd main-app && npm run dev",
"dev:subs": "concurrently \"cd react18-sub && npm run dev\" \"cd vue3-sub && npm run dev\"",
"build": "npm run build:main && npm run build:subs",
"clean": "rimraf node_modules **/*/node_modules"
}
}
Skip the interactive prompts by providing arguments:
npx create-qiankun my-project CreateMainAndSubApp react18-main hash react18-webpack-sub,vue3-webpack-sub pnpm
Arguments order:
CreateMainApp | CreateSubApp | CreateMainAndSubApp)# Create multiple projects
for project in app1 app2 app3; do
npx create-qiankun $project CreateMainAndSubApp react18-main history react18-webpack-sub pnpm
done
You can extend the CLI with custom templates by contributing to the project or forking the repository.
npx create-qiankun my-micro-frontend-app
# Choose: Create main application and sub applications
# Main: React18+Webpack
# Routing: history
# Subs: React18+Webpack, Vue3+Webpack
# Package Manager: pnpm with workspace
Result:
npx create-qiankun enterprise-app
# Choose: Create main application and sub applications
# Main: React18+umi4
# Routing: history
# Subs: React18+umi4, Vue3+Webpack
# Package Manager: pnpm with workspace
Features:
# ā
Good: Descriptive project names
npx create-qiankun e-commerce-platform
npx create-qiankun admin-dashboard
# ā Bad: Generic names
npx create-qiankun app1
npx create-qiankun project
# For simple projects
npm / yarn
# For monorepo with multiple teams
pnpm with workspace
# Hash routing - simpler deployment
# History routing - better SEO, requires server configuration
The CLI automatically detects and resolves port conflicts. If you encounter issues:
# Check running processes
lsof -i :8080
# Kill conflicting processes
kill -9 $(lsof -t -i:8080)
# Clear node_modules and reinstall
pnpm run clean
pnpm install
# Check workspace configuration
cat pnpm-workspace.yaml
# Clear build cache
rm -rf dist/ build/ .cache/
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install
Known limitation: Vue 2 templates have compatibility issues with pnpm workspace. Use alternative approaches:
# Use regular pnpm instead
# Choose: pnpm (not pnpm with workspace)
# Or use yarn/npm for Vue 2 projects
After creating your project:
Want to add new templates or improve the CLI? Check out the GitHub repository and contribute to the packages/create-qiankun directory.