Create Qiankun โ
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.
๐ Quick Start โ
Using npm โ
npx create-qiankun@latestUsing yarn โ
yarn create qiankun@latestUsing pnpm โ
pnpm dlx create-qiankun@latest๐ฏ Features โ
- Multiple Project Types: Choose between main app only, micro apps only, or complete setup
- Framework Support: React 18, Vue 3, Vue 2, and Umi 4 templates
- Routing Modes: Support for both hash and history routing patterns
- Package Manager Options: npm, yarn, pnpm, or pnpm workspace
- Auto Configuration: Automatic port conflict detection and startup scripts injection
- Monorepo Support: Built-in pnpm workspace setup for managing multiple applications
๐ Requirements โ
- Node.js: v18 or higher (recommended: use fnm for version management)
- Package Manager: npm, yarn, or pnpm
๐ฎ Interactive Setup โ
When you run create-qiankun, you'll be guided through an interactive setup process:
Step 1: Project Name โ
? Project name: โบ my-qiankun-projectStep 2: Project Type โ
? Choose a way to create โบ
โฏ Create main application and sub applications
Just create main application
Just create sub applicationsOptions:
- Create main application and sub applications: Complete setup with main app and multiple micro apps
- Just create main application: Only create the main (shell) application
- Just create sub applications: Only create micro applications
Step 3: Main Application Framework (if applicable) โ
? Choose a framework for your main application โบ
โฏ React18+Webpack
Vue3+Webpack
React18+umi4Step 4: Routing Pattern (if applicable) โ
? Choose a route pattern for your main application โบ
โฏ hash
historyStep 5: Sub Applications Framework (if applicable) โ
? Choose a framework for your sub application โบ
Space to select. Return to submit.
โฏโฏ React18+Webpack
โฏ Vue3+Webpack
โฏ Vue2+Webpack
โฏ React18+umi4Step 6: Package Manager โ
? Which package manager do you want to use? โบ
โฏ npm
yarn
pnpm
pnpm with workspace๐ฆ Available Templates โ
Main Application Templates โ
| 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 |
Sub Application Templates โ
| 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 |
๐๏ธ Project Structure โ
Single Project Structure โ
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.jsonPnpm Workspace Structure โ
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๐ง Generated Configuration โ
Main Application Configuration โ
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();Micro Application Configuration โ
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()
]
}
});Port Configuration โ
Automatic port assignment prevents conflicts:
{
"scripts": {
"dev": "PORT=8080 react-scripts start",
"check-port": "node scripts/checkPort.js"
}
}๐จ Customization Options โ
Environment-specific Configuration โ
// 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'
}
]
};Custom Routing โ
// Hash routing (default)
const router = createRouter({
history: createWebHashHistory(),
routes: [...]
});
// History routing
const router = createRouter({
history: createWebHistory(),
routes: [...]
});๐ Development Workflow โ
Single Package Manager โ
# 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 devPnpm Workspace โ
# 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 devGenerated Scripts โ
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"
}
}๐ง Advanced Usage โ
Command Line Arguments โ
Skip the interactive prompts by providing arguments:
npx create-qiankun my-project CreateMainAndSubApp react18-main hash react18-webpack-sub,vue3-webpack-sub pnpmArguments order:
- Project name
- Create kind (
CreateMainApp|CreateSubApp|CreateMainAndSubApp) - Main app template (if applicable)
- Routing pattern (if applicable)
- Sub app templates (comma-separated, if applicable)
- Package manager
Batch Creation โ
# Create multiple projects
for project in app1 app2 app3; do
npx create-qiankun $project CreateMainAndSubApp react18-main history react18-webpack-sub pnpm
doneCustom Templates โ
You can extend the CLI with custom templates by contributing to the project or forking the repository.
๐ฏ Project Examples โ
Complete React + Vue Setup โ
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 workspaceResult:
- Main React app with routing
- React 18 micro app
- Vue 3 micro app
- Automatic port assignment (3000, 8080, 8081)
- Workspace configuration
- Development scripts
Umi-based Monorepo โ
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 workspaceFeatures:
- Umi 4 main application with built-in qiankun support
- Umi 4 micro application
- Vue 3 micro application
- Ant Design Pro components
- TypeScript configuration
๐ Best Practices โ
1. Use Descriptive Names โ
# โ
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 project2. Choose Appropriate Package Manager โ
# For simple projects
npm / yarn
# For monorepo with multiple teams
pnpm with workspace3. Plan Your Routing Strategy โ
# Hash routing - simpler deployment
# History routing - better SEO, requires server configuration4. Consider Framework Compatibility โ
- React + Vue: Good for mixed teams
- Same Framework: Easier dependency management
- Umi: Best for enterprise applications
๐ Troubleshooting โ
Port Conflicts โ
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)Pnpm Workspace Issues โ
# Clear node_modules and reinstall
pnpm run clean
pnpm install
# Check workspace configuration
cat pnpm-workspace.yamlBuild Errors โ
# Clear build cache
rm -rf dist/ build/ .cache/
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm installVue 2 with Pnpm Workspace โ
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๐ Generated Project Features โ
Automatic Configuration โ
- Webpack optimization for micro-frontend builds
- CORS handling for cross-origin requests
- Public path configuration for different environments
- Development proxy setup for local development
Development Experience โ
- Hot module replacement in all applications
- Error boundaries for micro app failures
- Loading states during micro app transitions
- TypeScript support where applicable
Production Ready โ
- Build optimization for micro-frontend deployment
- Asset optimization and code splitting
- Environment configuration for different stages
- CI/CD friendly structure
๐ Next Steps โ
After creating your project:
- Explore the generated code to understand the structure
- Customize the configuration based on your needs
- Add more micro applications as your project grows
- Set up CI/CD pipelines for automated deployment
- Read the qiankun documentation for advanced features
๐ Related Documentation โ
- Core APIs - qiankun core APIs
- React Bindings - React UI bindings
- Vue Bindings - Vue UI bindings
- Webpack Plugin - Build tool configuration
๐ค Contributing โ
Want to add new templates or improve the CLI? Check out the GitHub repository and contribute to the packages/create-qiankun directory.
