📝 修改版本描述问题
根据阿里巴巴微前端统一规范的完成适配的 qiankun 版本
19 年在阿里内部伴随各 BU 业务的发展,出现了 qiankun、icestark、alfa 等微前端框架,可满足各自温饱使用,但是周边生态建设很难相互使用,包括后续的互通使用,阿里巴巴前端委员会拉通各部们弄微前端的同学成立共建组,分成统一规范、推荐框架、管控治理、生态周边建设 4 个方向
目前微前端规范初版已完成编写,icestark 和 alfa 完成升级适配,为保证 qiankun 同学使用体验,暂不对框架本身进行大升级防止存量业务问题,故根据规范完成 qiankun 的上层接口规范适配,产出 qiankun-one 版本,供有需要的同学使用
$ npm i qiankun-one --save
import { IAppConfig, IAppManifest, IOptions, IApp } from 'qiankun-one' const appConfig: IAppConfig = { name: "wei-micro-app-example1", entry: [ "//wei.alicdn.com/micro-app-example/0.1.0/index.js", "//wei.alicdn.com/micro-app-example/0.1.0/index.css" ], activePath: '/demo1', // 传递下发的props props: { title: 'currentTitle' }, // 根据 string 运行时查找DOM节点 container: "#root-slave", }
import { setup, start } from 'qiankun-one'; import Sandbox from '@ali/sandbox'; setup({ appConfigs: [{ name: "wei-micro-app-example1", entry: [ "//wei.alicdn.com/micro-app-example/0.1.0/index.js", "//wei.alicdn.com/micro-app-example/0.1.0/index.css" ], activePath: '/demo1', // 传递下发的props props: { title: 'currentTitle' }, // 根据 string 运行时查找DOM节点 container: "#root-slave", }, { name: "wei-micro-app-example2", entry: { "scripts": [ "//wei.alicdn.com/micro-app-example/0.1.0/chunk-libs.js", "//wei.alicdn.com/micro-app-example/0.1.0/index.js" ], "styles": [ "//wei.alicdn.com/micro-app-example/0.1.0/chunk-libs.css", "//wei.alicdn.com/micro-app-example/0.1.0/index.css" ] }, activePath: '/demo2', }, { name: "wei-micro-app-example3", entry: "//wei.alicdn.com/micro-app-example/0.1.0/index.html", activePath: '/demo3', }], options: { sandbox: new Sandbox(), prefetch: true, // 生命周期钩子函数 beforeMount: (app) => {}, // ... }, }) start();
IConfig
IAppConfig[]
IOptions
String/[String, String]/<IAppManifest>
IActivePath
HTMLElement
Object
boolean/ISandbox
Boolean
String[]
import React, { useEffect, useRef } from 'react' import { createMicroApp } from 'qiankun-one'; interface IApp extends Required<IAppConfig> { load(): void; mount(container: HTMLElement, props?: object): void; unmount(): void; update(props?: object): void; } const APP = () => { const containerRef: React.MutableRefObject<any> = useRef(); useEffect(() => { const WidgetInstance: IApp = createMicroApp({ name: 'widgetName', container: containerRef.current, entry: [ "//wei.alicdn.com/micro-app-example/0.1.0/index.js", "//wei.alicdn.com/micro-app-example/0.1.0/index.css" ], }, { sandbox: true, prefetch: true }) WidgetInstance.load(); }, []) return (<div ref={containerRef}></div>) }
HTMLElement/Props
props
版权所有:中国计算机学会技术支持:开源发展技术委员会 京ICP备13000930号-9 京公网安备 11010802032778号
qiankun-one
与 qiankun 的关系
19 年在阿里内部伴随各 BU 业务的发展,出现了 qiankun、icestark、alfa 等微前端框架,可满足各自温饱使用,但是周边生态建设很难相互使用,包括后续的互通使用,阿里巴巴前端委员会拉通各部们弄微前端的同学成立共建组,分成统一规范、推荐框架、管控治理、生态周边建设 4 个方向
目前微前端规范初版已完成编写,icestark 和 alfa 完成升级适配,为保证 qiankun 同学使用体验,暂不对框架本身进行大升级防止存量业务问题,故根据规范完成 qiankun 的上层接口规范适配,产出 qiankun-one 版本,供有需要的同学使用
Usage
安装依赖
开始使用
API
路由配置化规范
注册及运行函数规范
IConfigIConfig - 微应用全局配置规范
IAppConfig[]IOptionsIAppConfig - app 配置规范
String/[String, String]/<IAppManifest>IActivePathHTMLElementObjectIOptions - 微应用配置规范
boolean/ISandboxBooleanIActivePathHTMLElementObjectIAppManifest - entry 配置规范
String[]String[]手动加载规范
注册函数规范
IConfig返回实例规范
HTMLElement/Propsprops