Git Product home page Git Product logo

qiankun's Introduction

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🧐.

✨ 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.

qiankun's People

Contributors

aladdin-add avatar gongshun avatar guibwl avatar gwuhaolin avatar howel52 avatar humorhan avatar ice-zjchen avatar kiloc avatar kuitos avatar liaohainan avatar liuye1296 avatar lsdsjy avatar lusyn avatar nieling1 avatar ohiamfine avatar peachscript avatar peterlevel1 avatar qiongshusheng avatar qtpalmtop avatar shijistar avatar sishen654 avatar stormslowly avatar ttys026 avatar wanghangit avatar wanghao1221 avatar whg4 avatar xiechao1211 avatar xinhailishi avatar xioozq avatar xrkffgg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qiankun's Issues

子应用挂载的顺序依赖

Background

主项目A:一个项目是主入口项目,负责加载其它子项目
子项目B:主要用来负责各个子项目的导航,现在用作后台管理菜单框架页面,中间区域用来挂载其它子项目
子项目C、D...等:依赖项目B的优先挂载,因为这些项目要等待B项目渲染完成后,需要挂载到B项目提供的dom元素上

Proposal

在注册子应用的时候,额外添加一个配置项如:mountOrder: number,用来描述和控制子项目挂载的顺序,或者是其它配置项如:mountDependency: appName,挂载依赖的项目等

Additional context

暂时没有想到

vue master

您好,请问有没有基于vue作为基座(main)的配置啊

clearInterval 是否可以做的更加灵活

What happens?

我们在 Master 中有一个强依赖 interval 的业务组件,用于发送心跳;当子应用切换时, interval 会被默认清理掉。

return function free() {
window.setInterval = rawWindowInterval;
window.setTimeout = rawWindowTimeout;
timerIds.forEach(async id => {
// 延迟 timeout 的清理,因为可能会有动画还没完成
await sleep(500);
window.clearTimeout(id);
});
intervalIds.forEach(id => {
window.clearInterval(id);
});

最小可复现仓库

https://github.com/howel52/qiankun/tree/bug/interval

interval-demo.gif

复现步骤,错误日志以及相关配置

点击 demo 中的 start interval,随后切换应用,interval 会被 clear

相关环境信息

  • Node 版本:v10
  • 操作系统:macOS

疑惑

我仿照着react16写了一个项目,但是一直给我报这个错误,为啥呢
Uncaught myReact app: Application 'myReact app' died in status LOADING_SOURCE_CODE: You need to export the functional lifecycles in myReact app entry

部署问题

本地运行是没问题的,但是把子应用从qiankun框架分离出来,主应用和子应用单独部署后,报错跨域问题。

Access to fetch at 'http://micro-sub-web.devapp.com/' from origin 'http://micro-web.devapp.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

而我在子应用中已经导出为umd模块了。
"start": "parcel serve ./src/index.html --global dvaapp --port 7103",
"build": "parcel build ./src/index.html --global dvaapp --public-url ./",
请问这个跨域是什么原因?如何解决呢?

npm run install:examples 报错

What happens?

> [email protected] install:examples C:\personal\qiankun
> npm run build && cd examples/main && npm i && cd ../react16 && npm i && cd ../react15 && npm i && cd ../vue && npm i


> [email protected] build C:\personal\qiankun
> npm run build:esm && npm run build:cjs

> [email protected] build:esm C:\personal\qiankun
> rimraf esm && tsc

src/hijackers/timer.ts:23:3 - error TS2322: Type '(...args: any[]) => any' is not assignable to type '((handler: TimerHandler, timeout?: number | undefined, ...arguments: any[]) => number) & typeof setTimeout'.
  Property '__promisify__' is missing in type '(...args: any[]) => any' but required in type 'typeof setTimeout'.

23   window.setTimeout = (...args: any[]) => {
     ~~~~~~~~~~~~~~~~~

  node_modules/@types/node/globals.d.ts:175:14
    175     function __promisify__(ms: number): Promise<void>;
                     ~~~~~~~~~~~~~
    '__promisify__' is declared here.

src/index.ts:55:11 - error TS2322: Type 'Window' is not assignable to type 'Window & typeof globalThis'.
  Type 'Window' is missing the following properties from type 'typeof globalThis': globalThis, eval, parseInt, parseFloat, and 715 more.

55           jsSandbox = sandbox.sandbox;
             ~~~~~~~~~


Found 2 errors.

Mini Showcase Repository(REQUIRED)

Provide a mini GitHub repository which can reproduce the issue.

How To Reproduce

Steps to reproduce the behavior:

  1. git clone
  2. npm i
  3. npm run install:examples

Expected behavior
1.install success

Context

  • Node Version: v10.15.0
  • Platform: window10

异步路由加载到head

当子应用的路由为异步加载,或者子应用中有异步组件时,异步加载的js或者css加载到了head部分,当子应用卸载时是没法卸载head部分的内容的,qiankun有什么解决方案吗

wepack vue-cli3

您好,主项目是parcel,接入的子项目是vue-cli3搭建的小项目,已经配置了output,报错,跨域的问题
image

关于 jsSandBox的bug

即使配置jsSandbox: false, 也没有用, 因为getSandBox的逻辑是在registerMicroApps, 此时jsSandBox 为true; 所以此配置无效;

关于路由的问题最近在采坑, 我们的项目同时使用了hashHistory和browserHistory, 在切换的时候发现与react-router-dom 有冲突, 无法正确识别, 找了下RR的issue 操作window.history好像不推荐;

我是直接在主应用调single-spa的singleSPANavigate的方法,不知道qiankun在内部推广的时候有没有好的建议啊

是否乾坤只适用于主流开发库(react/vue/angular)?

我们企业内部目前都是使用自研的框架(完全自研,也没有基于主流库做二次改造),我想使用它并不是来解决不同组使用不同的技术栈来共建的问题,而是我想使用它来解决业务逻辑层公用的问题,例如目前我们的app和微信内大量功能都是使用自研框架来实现,目前需要做网站端,为了公用核心逻辑层,是否乾坤可以使用在自研的框架中?

Who uses qiankun?[谁在用 qiankun] 🎉🎉🎉

Hi all! Curious to know who is using qiankun! It would be really appreciated if you:

  1. Share your company name
  2. Share your logo (in which case it might be used in the readme / frontpage etc)
  3. What kind of project? How large? (numbers of built/integrated with qiankun/@umijs/plugin-qiankun)
  4. If your project is open source or public, please share a link!

大家好!想知道是谁在用乾坤,如果您能分享以下信息,我们将会非常感谢:

  1. 分享公司名称
  2. 分享公司的 logo (可能会被用于首页或 readme 中展示)
  3. 什么样的项目?多大量级?(基于 qiankun/plugin-qiankun 或者集成到 qiankun 中的应用数)
  4. 如果你的项目是开源或公开的,请分享链接!

关于子应用挂载问题

目前使用qiankun时,通过路由从一个子应用跳转到另一个子应用时,是否可以两个子应用同时处于挂载状态,而其中一个不会被unmount掉

基于vue作为基座(main)的配置

背景

现在有四个vue项目,想整合起来,就是各个子项目可以开发,最后一个main总的项目运行,总项目中包含四个vue项目的路由,形成左侧菜单

目的

您好,请问有没有基于vue作为基座(main)的配置啊

子应用开发支持热更新?

看了下源码,是通过起多个web server的方式拉取子应用静态代码插入到主应用,那主应用如何监听子应用代码变更,执行代码自动插入呢?

webpack HotModuleReplacementPlugin只能监听单web server

[求助] 组件集成有没有好的建议?

开发中有一些场景,需要用到组件集成,请问有没有什么好的建议?

页面结构简化一下是这样的:

app1 page app2 page
或者 在同一个页面的不同区域要展示来自两个应用的内容

vue-cli3子项目接入

跨域问题

主项目用的是parcel,接入的子项目是vue-cli3搭建的小项目,已经配置了output,报错,问题如下图所示
image

@umijs/plugin-qiankun使用问题,求解答

@umijs/plugin-qiankun实例中,子应用app.js中@tmp/umi是什么模块,不明白。
会一直报下面错误:
VM44:1 Uncaught app1: Application 'app1' died in status LOADING_SOURCE_CODE: You need to export the functional lifecycles in app1 entry

各个子项目是否支持独立部署,独立运行?

旧的react项目接入到主项目中去,需要在入口文件处导出生命周期,这样挂载的过程就被放到了mount周期中去,导致子项目无法独立运行,只有通过主项目的入口才能正常访问。有没有办法可以保证既能顺利接入到主项目中,又能够作为一个独立的项目继续运行?

主应用获取不到cookie

What happens?

在项目启动后,打开f12,在application中是能看到cookie的,但是在项目中的主应用中打印document.cookie时获取不到,请问是什么原因?

最小可复现仓库

复现步骤,错误日志以及相关配置

相关环境信息

  • Node 版本
  • 操作系统

关于样式隔离

我们的场景是: 一个老项目还是antd1.x的, 而且是一些非常基础的功能, 暂时没有精力升级,
而新项目使用了antd3, 现在发现两者的样式会存在一些冲突, 感觉Example还是简单了些, 想问下在内部使用过程中,还有没有一些坑(经验)分享?

FAQ

使用上的一些问题在统一提到这里

parse js/css map

先感谢作者对上个问题的解决,现在遇到新的问题是parse map文件和字体图标decode失败,谢谢

image

是否考虑独立组件支持

我需要通过 URL 加载远程的项目,但是应用已经成型所以路由功能对我来说是多余且有害的。
或者我某个页面中需要加载多个远程项目。这个时候路由功能也较为难受。
我相信这不只是我一个人会遇到的问题。
如果可以支持将远程项目包装为组件。灵活性会增加很多。

一些小疑问

不错的项目!提一些小疑问:

  1. 支持angularjs 1.x的接入吗?
  2. 采用proxey做沙箱,是不是不考虑稍微低版本的不支持proxey语法的浏览器?
  3. 已经在阿里内部生产环境使用了吗?

[Feature Request] 区分 console 的宿主

Background

目前 Master 与 Slave 的 runtime log 都混在控制台里, 没有做区分, 无法直观的感受到某个 log 记录是哪个应用打的

Proposal

Proxy Console, 在 master runtime 里使用 console.log('foo'), 实际打印为 'Master: foo', 在 Salve runtime 下使用 console.log('bar'),实际打印为 '[SlaveName]: bar'

不过,该如何区分这个 Proxy 呢? 两者都是从同一 window 里拿的 Console,包括像 Sentry 类的工具也会复写 console.error,不知有没有好的解决方案。

子项目之间如何通信

子项目如何通信(背景:项目仅有一个页面,页面中的各个子组件需要单独部署,独立仓库,甚至使用不同的框架),请问用现在的qiankun框架能否满足需求,之前看过single-spa(没有找到比较合适的子项目通信方案),现在的qiankun是如何做子项目之间通信的呢?感谢

image

能否添加配置项,当路由跳转时才真正获取模块资源

感谢分享!感觉让微前端更简单的面向我们。
看了例子,注册app时就请求了所有的资源。如果模块注册过多时是否会造成一些资源浪费,我们的第一层路由就分出了很多模块,并且一个使用者可能只会应用到其中30%的模块,能否加个配置项当真正的选择到这个微应用时才开始请求它,消减去一些用户体验(我们是可以接受的,现在用的方式更加的糟糕)。

dva框架集成qiankun

你好,请问dva框架改如何写挂载函数?dva框架的入口文件index.js是这种形式的:
const app = dva();
app.router(require('./router').default);
app.start('#root');

ie 兼容性问题

我跑examples 在 ie 11 浏览器无法正常访问, 并且我看到代码中有用到 proxy, 请问对于 ie 是否有兼容计划

不支持iframe二次嵌套么?

复现步骤:简单使用一个<iframe src="http://localhost:7099"></iframe> 将主程序嵌入

保错

DOMException: Blocked a frame with origin "http://localhost:7099" from accessing a cross-origin frame.
    at baseGetTag (http://localhost:7099/main.e31bb0bc.js:32740:48)
    at isFunction (http://localhost:7099/main.e31bb0bc.js:41321:17)
    at Object.get (http://localhost:7099/main.e31bb0bc.js:47228:34)
    at Object.parcelRequire.node_modules/react-dom/lib/ReactDOM.js../ReactDOMComponentTree (eval at exec (http://localhost:7099/main.e31bb0bc.js:27521:11), <anonymous>:22165:48)
    at newRequire (eval at exec (http://localhost:7099/main.e31bb0bc.js:27521:11), <anonymous>:47:24)
    at localRequire (eval at exec (http://localhost:7099/main.e31bb0bc.js:27521:11), <anonymous>:53:14)
    at Object.parcelRequire.node_modules/react-dom/index.js../lib/ReactDOM (eval at exec (http://localhost:7099/main.e31bb0bc.js:27521:11), <anonymous>:22213:18)
    at newRequire (eval at exec (http://localhost:7099/main.e31bb0bc.js:27521:11), <anonymous>:47:24)
    at localRequire (eval at exec (http://localhost:7099/main.e31bb0bc.js:27521:11), <anonymous>:53:14)
    at Object.parcelRequire.index.js.antd/dist/antd.min.css (eval at exec (http://localhost:7099/main.e31bb0bc.js:27521:11), <anonymous>:112700:40)

我了解这是一个安全策略?除了将域统一之外,是否有解?

提供entry配置为scripts/styles/html的例子

目前例子中的三个都是直接使用了entry: ""的形式加载子应用。我大致扫了眼代码里面是有对entry: {scripts : [], styles: []}解析并加载的,但是自己试了下遇到一些问题。最好能官方提供一下例子,谢谢。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.