Convert Figma logo to code with AI

umijs logoqiankun

📦 🚀 Blazing fast, simple and complete solution for micro frontends.

15,789
2,011
15,789
400

Top Related Projects

The router for easy microfrontends

Implementation examples of module federation , by the creators of module federation

12,939

Dynamic ES module loader

extending the microservice paradigms to web development

Quick Overview

Qiankun is a powerful micro-frontends solution for building large-scale, complex web applications. It allows developers to split their applications into smaller, more manageable pieces that can be developed, tested, and deployed independently, while still providing a seamless experience for end-users.

Pros

  • Supports multiple frameworks (React, Vue, Angular, etc.) within a single application
  • Provides out-of-the-box features like JavaScript sandbox and CSS isolation
  • Offers a simple and flexible API for integrating micro-apps
  • Enables gradual migration from monolithic applications to micro-frontends

Cons

  • Learning curve for developers new to micro-frontend architecture
  • Potential performance overhead due to multiple JavaScript runtimes
  • Complexity in managing shared dependencies and state across micro-apps
  • Limited support for server-side rendering in some scenarios

Code Examples

  1. Registering a micro-app:
import { registerMicroApps } from 'qiankun';

registerMicroApps([
  {
    name: 'app1',
    entry: '//localhost:8080',
    container: '#container',
    activeRule: '/app1',
  },
]);
  1. Starting the qiankun framework:
import { start } from 'qiankun';

start();
  1. Configuring a micro-app (in the micro-app's entry file):
import Vue from 'vue';
import App from './App.vue';

let instance = null;

function render(props = {}) {
  instance = new Vue({
    render: (h) => h(App),
  }).$mount('#app');
}

export async function bootstrap() {
  console.log('vue app bootstraped');
}

export async function mount(props) {
  console.log('props from main framework', props);
  render(props);
}

export async function unmount() {
  instance.$destroy();
  instance.$el.innerHTML = '';
  instance = null;
}

Getting Started

  1. Install qiankun:
npm install qiankun
  1. Register micro-apps in your main application:
import { registerMicroApps, start } from 'qiankun';

registerMicroApps([
  {
    name: 'app1',
    entry: '//localhost:8080',
    container: '#container',
    activeRule: '/app1',
  },
  // ... other micro-apps
]);

start();
  1. Configure your micro-apps to export lifecycle hooks (bootstrap, mount, unmount).

  2. Ensure your micro-app's webpack config is set up for qiankun (refer to documentation for details).

  3. Run your main application and micro-apps, and navigate to see them in action.

Competitor Comparisons

The router for easy microfrontends

Pros of single-spa

  • Framework-agnostic, supporting a wider range of technologies
  • More mature and established project with a larger community
  • Offers more flexibility and control over the micro-frontend architecture

Cons of single-spa

  • Steeper learning curve and more complex setup
  • Requires more manual configuration and boilerplate code
  • Less opinionated, which can lead to inconsistencies across projects

Code Comparison

single-spa:

import { registerApplication, start } from 'single-spa';

registerApplication({
  name: 'app1',
  app: () => import('./app1/main.js'),
  activeWhen: '/app1'
});

start();

qiankun:

import { registerMicroApps, start } from 'qiankun';

registerMicroApps([
  {
    name: 'app1',
    entry: '//localhost:8080',
    container: '#container',
    activeRule: '/app1',
  },
]);

start();

Both single-spa and qiankun are popular micro-frontend frameworks, but they have different approaches. single-spa offers more flexibility and supports a wider range of technologies, making it suitable for complex, diverse architectures. However, it requires more setup and configuration.

qiankun, built on top of single-spa, provides a more opinionated and streamlined approach, making it easier to get started with micro-frontends. It offers additional features like JavaScript sandbox and CSS isolation out of the box, but may be less flexible for highly customized setups.

Implementation examples of module federation , by the creators of module federation

Pros of module-federation-examples

  • Provides a wide range of examples for different Module Federation scenarios
  • Demonstrates integration with various frameworks and build tools
  • Offers more flexibility in terms of runtime dependencies and shared modules

Cons of module-federation-examples

  • Steeper learning curve due to its more complex implementation
  • Requires more configuration and setup compared to qiankun
  • May have higher runtime overhead in some scenarios

Code Comparison

qiankun:

registerMicroApps([
  {
    name: 'app1',
    entry: '//localhost:8080',
    container: '#container',
    activeRule: '/app1',
  },
]);

module-federation-examples:

new ModuleFederationPlugin({
  name: 'host',
  remotes: {
    app1: 'app1@http://localhost:3001/remoteEntry.js',
  },
  shared: ['react', 'react-dom'],
})

Summary

While qiankun offers a simpler setup and easier integration for micro-frontends, module-federation-examples provides more flexibility and a wider range of use cases. qiankun is better suited for quick implementation of micro-frontends, especially in React-based applications. On the other hand, module-federation-examples offers more advanced features and integration options, making it suitable for complex scenarios and diverse technology stacks.

12,939

Dynamic ES module loader

Pros of SystemJS

  • More mature and widely adopted project with a larger community
  • Supports loading various module formats (CommonJS, AMD, UMD) in addition to ES modules
  • Lighter weight and focused solely on module loading

Cons of SystemJS

  • Requires more manual configuration for complex micro-frontend setups
  • Lacks built-in sandbox isolation and communication mechanisms between micro-apps
  • Does not provide lifecycle management for micro-applications out of the box

Code Comparison

qiankun:

registerMicroApps([
  {
    name: 'app1',
    entry: '//localhost:8080',
    container: '#container',
    activeRule: '/app1',
  },
]);
start();

SystemJS:

System.import('./app1.js').then(function(module) {
  module.init();
});

Summary

qiankun is a comprehensive micro-frontend framework built on top of single-spa, offering features like sandboxing, prefetching, and lifecycle management. It provides a higher-level abstraction for micro-frontend architecture.

SystemJS, on the other hand, is a universal module loader that focuses on loading various module formats in the browser. It's more flexible but requires additional setup for implementing a full micro-frontend solution.

Choose qiankun for a more opinionated, out-of-the-box micro-frontend setup, or SystemJS for greater flexibility in module loading and custom micro-frontend implementations.

extending the microservice paradigms to web development

Pros of micro-frontends

  • Simpler implementation with less overhead
  • More flexible and framework-agnostic approach
  • Easier to integrate with existing projects

Cons of micro-frontends

  • Less comprehensive feature set compared to qiankun
  • Requires more manual configuration and setup
  • Limited built-in support for advanced scenarios

Code Comparison

micro-frontends:

import { registerApplication, start } from 'single-spa';

registerApplication(
  'app1',
  () => import('./app1/main.js'),
  location => location.pathname.startsWith('/app1')
);

start();

qiankun:

import { registerMicroApps, start } from 'qiankun';

registerMicroApps([
  {
    name: 'app1',
    entry: '//localhost:8080',
    container: '#container',
    activeRule: '/app1',
  },
]);

start();

Both repositories aim to implement micro-frontend architectures, but they differ in their approach and feature set. micro-frontends offers a more lightweight and flexible solution, while qiankun provides a more comprehensive and opinionated framework with additional features like sandbox isolation and prefetching. The choice between the two depends on project requirements, existing infrastructure, and desired level of control over the micro-frontend implementation.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

qiankun

npm version coverage npm downloads build status dumi

qiankun(乾坤)

In Chinese, qian(乾) means heaven and kun(坤) earth. qiankun is the universe.

Qiankun enables you and your teams to build next-generation and enterprise-ready web applications leveraging Micro Frontends. It is inspired by and based on single-spa.

🤔 Motivation

A quick recap about the concept of Micro Frontends:

Techniques, strategies and recipes for building a modern web app with multiple teams using different JavaScript frameworks. — Micro Frontends

Qiankun was birthed internally in our group during the time web app development by distributed teams had turned to complete chaos. We faced every problem micro frontend was conceived to solve, so naturally, it became part of our solution.

The path was never easy, we stepped on every challenge there could possibly be. Just to name a few:

  • In what form do micro-apps publish static resources?
  • How does the framework integrate individual micro-apps?
  • How to ensure that sub-applications are isolated from one another (development independence and deployment independence) and runtime sandboxed?
  • Performance issues? What about public dependencies?
  • The list goes on long ...

After solving these common problems of micro frontends and lots of polishing and testing, we extracted the minimal viable framework of our solution, and named it qiankun, as it can contain and serve anything. Not long after, it became the cornerstone of hundreds of our web applications in production, and we decided to open-source it to save you the suffering.

TLDR: Qiankun is probably the most complete micro-frontend solution you ever met🧐.

:sparkles: Features

Qiankun inherits many benefits from single-spa:

  • 📦 Micro-apps Independent Deployment
  • 🛴 Lazy Load
  • 📱 Technology Agnostic

And on top of these, it offers:

  • 💃 Elegant API
  • 💪 HTML Entry Access Mode
  • 🛡 Style Isolation
  • 🧳 JS Sandbox
  • ⚡ Prefetch Assets
  • 🔌 Umi Plugin Integration

📦 Installation

$ yarn add qiankun  # or npm i qiankun

📖 Documentation

You can find the Qiankun documentation on the website

Check out the Getting Started page for a quick overview.

The documentation is divided into several sections:

💿 Examples

Inside the examples folder, there is a sample Shell app and multiple mounted Micro FE apps. To get it running, first clone qiankun:

$ git clone https://github.com/umijs/qiankun.git
$ cd qiankun

Now install and run the example:

$ yarn install
$ yarn examples:install
$ yarn examples:start

Visit http://localhost:7099.

🎯 Roadmap

See Qiankun 3.0 Roadmap

👥 Contributors

Thanks to all the contributors!

contributors

🎁 Acknowledgements

📄 License

Qiankun is MIT licensed.

NPM DownloadsLast 30 Days