3.6.0 • Published 9 months ago
@empjs/share v3.6.0
EMP Share
pnpm add @empjs/share01 @empjs/share/rspack - Emp Share Plugin
使用方法
import {pluginRspackEmpShare} from '@empjs/share/rspack' import {defineConfig} from '@empjs/cli' export default defineConfig(store => { return { plugins: [ pluginRspackEmpShare({ name: 'mfHost', shared: { react: { singleton: true, requiredVersion: '18', }, 'react-dom': { singleton: true, requiredVersion: '18', }, }, exposes: { './App': './src/App', './CountComp': './src/CountComp', }, }), ], } })
02 @empjs/share/library - Module Federation SDK 封装
full.js为全量函数库、主要应对直接 老项目的桥接、通过window直接调用共享,包含:- MFRuntime
- MFSDK
- reactAdapter
- runtime
sdk.js为 SDK库包含MFRuntime与MFSDK,调用还是需要安装pnpm add @empjs/share/runtimesdkPolyfill.js为sdk+core-js
03 @empjs/share/runtime - 运行时引用
项目调用
import React, {useEffect, useState, version} from 'react'
import ReactDOM from 'react-dom'
import {CountComp as CountComp16, ShowCountComp as ShowCountComp16, Card} from './CountComp'
import {reactAdapter} from '@empjs/share/adapter' // 使用 react
import empRuntime from '@empjs/share/runtime' // runtime 加载器
const entry = process.env.mfhost as string
// 实例化远程 emp
empRuntime.init({
shared: reactAdapter.shared,
remotes: [
{
name: 'mfHost',
entry,
},
],
name: 'federationRuntimeDemo',
})
// 封装 React 18的组件 以便插入到 React 16
const MfApp = reactAdapter.adapter(empRuntime.load('mfHost/App'))
const CountComp = reactAdapter.adapter(empRuntime.load('mfHost/CountComp'), 'CountComp')
// 创建 React 16 组件
const ParentComponent = () => {
return (
<Card title={() => <>App Inject mfHost</>}>
<CountComp name="a" />
<CountComp16 />
</Card>
)
}
// 封装 React 16的组件 以便插入到 React 18
const ParentComponentAdepter = reactAdapter.adapter(ParentComponent, 'default', React, ReactDOM)
const App = () => {
return (
<>
<h1>App React Version {version}</h1>
<ShowCountComp16 />
<Card title="EMP From mfhost">
<MfApp component={ParentComponentAdepter} />
</Card>
</>
)
}
export default App3.6.1-beta.2
9 months ago
3.6.1-beta.1
9 months ago
3.6.0-beta.0
10 months ago
3.6.0-beta.1
10 months ago
3.6.0-beta.2
10 months ago
3.4.7
11 months ago
3.4.6
11 months ago
3.4.5
11 months ago
3.5.3
10 months ago
3.4.4
11 months ago
3.5.2
10 months ago
3.4.3
11 months ago
3.6.0
10 months ago
3.5.1
10 months ago
3.5.0
11 months ago
3.3.1-beta.1
1 year ago
3.3.3
1 year ago
3.3.2
1 year ago
3.3.0
1 year ago
3.2.0
1 year ago
3.1.14
1 year ago
3.1.13
1 year ago
3.1.12
1 year ago
3.1.10
1 year ago
3.1.8
1 year ago
3.1.7
1 year ago
3.1.6
1 year ago
3.1.5
1 year ago
3.1.3
1 year ago
3.1.2
1 year ago
3.1.1
1 year ago
3.1.0
1 year ago
0.1.0
1 year ago
0.0.2
1 year ago
0.0.1
1 year ago