2.10.16 • Published 3 months ago

qiankun v2.10.16

Weekly downloads
2,590
License
MIT
Repository
github
Last release
3 months ago

qiankun(乾坤)

npm version coverage npm downloads Build Status

In Chinese traditional culture qian means heaven and kun stands for earth, so qiankun is the universe.

An implementation of Micro Frontends, based on single-spa, but made it production-ready.

🤔 Motivation

As we know what micro-frontends aims for:

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

An independent development experience is very important for a large system, especially with an enterprise application. But if you've tried to implement a micro-frontends architecture in such a system, you'll usually hurt your brain with such problems:

  • How to compose your independent sub apps into your main system?
  • How to guarantee your sub apps to be isolated by each other?
  • and so on...

We built an library to help you solve these glitch problems automatically without any mental burden of yours, then named it qiankun.

Probably the most complete micro-frontends solution you ever met🧐.

📦 Installation

$ yarn add qiankun  # or npm i qiankun -S

🔨 Getting Started

1. Create master framework with qiankun

import { registerMicroApps, start } from 'qiankun';

function render({ appContent, loading }) {
  const container = document.getElementById('container');
  ReactDOM.render(<Framework loading={loading} content={appContent} />, container);
}

function genActiveRule(routerPrefix) {
  return location => location.pathname.startsWith(routerPrefix);
}

registerMicroApps([
  {
    name: 'react app', // app name registered
    entry: '//localhost:7100',
    render,
    activeRule: genActiveRule('/react'),
  },
  {
    name: 'vue app',
    entry: { scripts: ['//localhost:7100/main.js'] },
    render,
    activeRule: genActiveRule('/vue'),
  },
]);

start();

2. Export the lifecycles from your sub app entry

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

export async function mount(props) {
  console.log(props);
  ReactDOM.render(<App />, document.getElementById('react15Root'));
}

export async function unmount() {
  ReactDOM.unmountComponentAtNode(document.getElementById('react15Root'));
}

For more lifecycle information, see single-spa lifecycles

3. Config your sub app bundler

While you wanna build a sub app to integrate to qiankun, pls make sure your bundler have the required configuration below:

webpack:

const packageName = require('./package.json').name;

module.exports = {
  output: {
    library: `${packageName}-[name]`,
    libraryTarget: 'umd',
    jsonpFunction: `webpackJsonp_${packageName}`,
  },
};

see https://webpack.js.org/configuration/output/#outputlibrary

parcel:

parcel serve entry.js --global myvariable

see https://en.parceljs.org/cli.html#expose-modules-as-umd

💿 Examples

$yarn
$yarn install:examples
$yarn start

Visit http://localhost:7099

npm.io

:sparkles: Features

📖 API

registerMicroApps

type RegistrableApp = {
  // name to identify your app
  name: string;
  // where your sub app served from, supported html entry and config entry
  entry: string | { scripts?: string[]; styles?: string[]; html?: string };
  // render function called around sub app lifecycle
  render: (props?: { appContent: string; loading: boolean }) => any;
  // when sub app active
  activeRule: (location: Location) => boolean;
  // props pass through to sub app
  props?: object;
};

type Lifecycle<T extends object> = (app: RegistrableApp<T>) => Promise<any>;
type LifeCycles<T extends object> = {
  beforeLoad?: Lifecycle<T> | Array<Lifecycle<T>>;
  beforeMount?: Lifecycle<T> | Array<Lifecycle<T>>;
  afterMount?: Lifecycle<T> | Array<Lifecycle<T>>;
  beforeUnmount?: Lifecycle<T> | Array<Lifecycle<T>>;
  afterUnmount?: Lifecycle<T> | Array<Lifecycle<T>>;
};

function registerMicroApps<T extends object = {}>(
  apps: Array<RegistrableApp<T>>,
  lifeCycles?: LifeCycles<T>,
  opts?: RegisterMicroAppsOpts,
): void;

start

function start(options: Options): void;

Options

paramdescriptiondefault
prefetchWhether to prefetch assets of sub apps after first sub app mountedtrue
jsSandboxWhile sandbox enabled, we could guarantee that sub apps is isolated with each otherstrue
singularOnly one sub app display at one runtime, that means a sub app will wait to mount until the before one unmountedtrue
fetchSet a custom fetch functionwindow.fetch

setDefaultMountApp

Set which sub app shoule be active by default after master loaded.

function setDefaultMountApp(defaultAppLink: string): void;

runAfterFirstMounted

function runAfterFirstMounted(effect: () => void): void;

🎯 Roadmap

  • Parcel apps integration (multiple sub apps displayed at the same time, but only one uses router at most)
  • Communication development kits between master and sub apps
  • Custom side effects hijacker
  • Nested Microfrontends

❓ FAQ

https://github.com/umijs/qiankun/wiki/FAQ

👬 Community

https://github.com/umijs/umi#community

🎁 Acknowledgements

  • single-spa What an awesome meta-framework for micro-frontends!
demo-qiankunjyswsdssdfdfdsafdtedsssswdswstao-provue2-viteviz-componentqiankun-baseqnlcdp@hakushin/dev-consoleyicorejsvue2-base@infinitebrahmanuniverse/nolb-qia@wu-web/micro-sdk@cloud-app-dev/micro-componentstemplate-back-stage@everything-registry/sub-chunk-2503vue-vault-provider-v2financial-reviewform-editor-clfriday-corefriday-microfui-viewftech-web-sdkkl-corehc-visit-doc-stationhlcs-webhuangyangcong-clone-qiankun-vuege-adminghx-testgs-portal-componentsguo-umijs-plugin-qiankunhaier-qiankun-mainh-biomedical-frameworkif-admin-layoutics-form-editorics-imedx-component-op-visitics-imedx-djl-groupics-imedx-iconics-assessment-formmetersphere-frontendmyvue_ces_uimy_micro_fronntnew-micro-componentsmediway-ui-myhmp-console-mainmika-mmd-tvmicro-ly-componentsm2-mfemonsterg-scriptsmopocketplugin-back-stage-template@redhare/app-materials@reskript/plugin-qiankunplugin-qiankun-fixedplugin-qiankun2poc-uiplugin-mm-qiankunplug2@rhg-enframe/plugpackage-plugin@porosjs/pluginsparsec-admin@projectproxima/components@projectproxima/plugin-debug@puffing/susu@pure-org/water-template-fawkesplatfrom-demo-tsplatform-core-libs-ngoms-qiankun-mainnpm-qiankun-parentnpmcomponentsreactsolight-componentolight-uinuxt-qiankun@aibeanw/test@tdit/it-spascrm-web-adminscrm-web-appsd-portal-componentsarktos-nextarktos-next-dev@bl-microapp/main-reactshy-microsimple-qksimple-react-qiankunronds-react-uirondsframeworkally-ui@aplun/container@winner3096/components@xdh/my@web-design/micro-app@wu-web/micro-base-sdk@wakeadmin/mapprc-lzbui@tuya-sat/sdf-main-sdk@typeclient/react-qiankunrapid-web-frameworkqn-lcdp@sigma-interactive/micro@umijs/plugin-qiankun
3.0.0-rc.19

3 months ago

3.0.0-rc.17

4 months ago

3.0.0-rc.16

4 months ago

3.0.0-rc.18

4 months ago

2.10.14

6 months ago

2.10.15

6 months ago

2.10.16

5 months ago

3.0.0-rc.13

5 months ago

3.0.0-rc.12

5 months ago

3.0.0-rc.15

5 months ago

3.0.0-rc.14

5 months ago

3.0.0-rc.6

6 months ago

3.0.0-rc.5

6 months ago

3.0.0-rc.11

6 months ago

3.0.0-rc.4

6 months ago

3.0.0-rc.10

6 months ago

3.0.0-rc.9

6 months ago

3.0.0-rc.8

6 months ago

3.0.0-rc.7

6 months ago

3.0.0-beta.0

7 months ago

3.0.0-rc.2

7 months ago

3.0.0-rc.1

7 months ago

3.0.0-rc.0

7 months ago

3.0.0-rc.3

7 months ago

3.0.0-alpha.6

8 months ago

3.0.0-alpha.3

8 months ago

3.0.0-alpha.2

8 months ago

3.0.0-alpha.5

8 months ago

3.0.0-alpha.4

8 months ago

2.10.10

10 months ago

2.10.11

10 months ago

2.10.12

9 months ago

2.10.13

8 months ago

2.10.9

10 months ago

3.0.0-alpha.1

12 months ago

3.0.0-alpha.0

12 months ago

2.10.7

11 months ago

2.10.8

11 months ago

2.10.6

12 months ago

2.9.2

1 year ago

2.9.1

1 year ago

2.9.3

1 year ago

2.10.1

1 year ago

2.10.2

1 year ago

2.10.0

1 year ago

2.10.5

1 year ago

2.10.3

1 year ago

2.10.4

1 year ago

2.9.0

1 year ago

2.8.3

2 years ago

2.8.2

2 years ago

2.8.4

1 year ago

2.8.1

2 years ago

2.8.0

2 years ago

2.7.5

2 years ago

2.7.2

2 years ago

2.7.1

2 years ago

2.7.4

2 years ago

2.7.3

2 years ago

2.7.0

2 years ago

2.6.1

2 years ago

2.6.0

2 years ago

2.6.3

2 years ago

2.6.2

2 years ago

2.5.1

3 years ago

2.5.0

3 years ago

2.4.10

3 years ago

2.4.9

3 years ago

2.4.8

3 years ago

2.4.7

3 years ago

2.4.6

3 years ago

2.4.5

3 years ago

2.4.4

3 years ago

2.4.3

3 years ago

2.4.1

3 years ago

2.4.2

3 years ago

1.5.2

3 years ago

2.4.0

3 years ago

2.3.6

3 years ago

2.3.5

3 years ago

2.3.4

3 years ago

2.3.3

3 years ago

2.3.2

3 years ago

2.3.1

3 years ago

2.3.0

3 years ago

2.2.3

3 years ago

2.2.2

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.2.0-1

4 years ago

2.2.0-0

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.26

4 years ago

2.0.25

4 years ago

2.0.24

4 years ago

2.0.23

4 years ago

2.0.22

4 years ago

2.0.21

4 years ago

2.0.20

4 years ago

2.0.19

4 years ago

2.0.18

4 years ago

2.0.17

4 years ago

2.0.17-3

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

2.0.17-2

4 years ago

2.0.17-1

4 years ago

2.0.17-0

4 years ago

2.0.16

4 years ago

2.0.15

4 years ago

2.0.15-0

4 years ago

2.0.14

4 years ago

2.0.13

4 years ago

2.0.12

4 years ago

2.0.12-2

4 years ago

2.0.12-1

4 years ago

2.0.12-0

4 years ago

2.0.11

4 years ago

2.0.10

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

1.4.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

2.0.0-4

4 years ago

2.0.0-3

4 years ago

2.0.0-2

4 years ago

2.0.0-1

4 years ago

2.0.0-0

4 years ago

1.4.5

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.15-0

4 years ago

1.3.14

4 years ago

1.3.13

4 years ago

1.3.12

4 years ago

1.3.11

4 years ago

1.3.10

4 years ago

1.3.10-1

4 years ago

1.3.10-0

4 years ago

1.3.9

4 years ago

1.3.8

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.3

4 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.12-0

5 years ago

1.1.11

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.6-1

5 years ago

1.1.6-0

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago