0.0.1 • Published 2 years ago

@jsbest/async-app v0.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Async-App 微前端加载器

介绍

async-app 是一个基于 react component 的 remote component 加载器,支持 webpack 打包 umd 或 var 格式。

简单使用

import React, { Component } from 'react';
import AsyncApp from '@ali/async-app';
export class App extends Component {
  render() {
    return (
      <div>
        <AsyncApp
          appName={'app'}
          componentName={'App'}
          includeOriginCss={false}
          entry={'https://gw.alipayobjects.com/os/acdn/m335cp/index.js'}
        />
      </div>
    );
  }
}

参数解释

参数渲染元素容器样式类型默认值
styleCSSPropertiesCSSProperties
className渲染元素容器 classNamestring
entry组件 CDN 资源或 React Componentstring | ReactNode
includeOriginCss是否自动加载 entry 同名的样式文件,如 entry 为:https://g.alicdn.com/group/project/0.0.1/app.js ,则会自动添加其同名的样式文件https://g.alicdn.com/group/project/0.0.1/app.cssbooleantrue
appName挂载到 window 上的 react 组件名string
componentName实际需要渲染的组件,若为空则渲染 appName,例如 entry 组件挂载入境为 window.appname={someComponent:{subComponent:()=>{}}},若需要渲染 subComponent,则需要配置此字段 componentName='someComponent.subComponent'string
loading自定义 loading 组件,可设置为 null 关闭 loadingReactNode
errorComponent错误时渲染组件可设置为 nul 关闭ReactNodeAsyncApp Error
mode加载器渲染方案'isolate'、'iframe'、'global''isolate'
shadowDom是否开启shadowDom模式进行渲染,默认true
beforeRender组件渲染前回调,可定制渲染组件,第一个参数为待渲染的组件,第二个为当前沙箱挂载的 app 实例(component,app)=>component
params需要传递到组件的 propsobject
dependencies依赖资源 cdn 地址string[]

example

1. antdv3 和 antdv4 混用

image.png

2. simple-demo

image.png