🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@empjs/adapter

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@empjs/adapter

emp share adapter

Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
0
-100%
Maintainers
2
Weekly downloads
 
Created
Source

@empjs/plugin-emp-runtime

配置

emp-config.js

import {defineConfig} from '@empjs/cli'
import pluginEmpRuntime from '@empjs/plugin-emp-runtime'

export default defineConfig(store => {
  return {
    plugins: [
        // runtimeHost 为当前 库地址
        pluginEmpRuntime({runtimeHost: `http://localhost:3011`}),
        ],
  }
})

项目调用

  • 参考项目 federation-runtime
import React, {useEffect, useState, version} from 'react'
import ReactDOM from 'react-dom'
// 引用runtime
import {empRuntime, withReactAdapter} from '@empjs/plugin-emp-runtime/runtime'
// 实例化远程 emp
empRuntime.init({
  remotes: [
    {
      name: 'mfHost',
      entry: `http://${process.env.lanIp}:8001/emp.js`,
    },
  ],
  name: 'federationRuntimeDemo',
})
// 封装 React 18的组件 以便插入到 React 16
const RemoteApp = withReactAdapter<any>(empRuntime.load('mfHost/App'))
// 创建 React 16 组件
const ParentComponent = () => {
  const [count, setCount] = useState(0)
  return (
    <div style={{border: '1px solid #eee', padding: '10px', background: '#f7f7f7'}}>
      <h1>React Version {React.version}!</h1>
      <button onClick={() => setCount(count + 1)}>Click Count {count}</button>
    </div>
  )
}
// 封装 React 16的组件 以便插入到 React 18
const ParentComponentAdepter = withReactAdapter(ParentComponent, React, ReactDOM)
const App = () => {
  return (
    <>
      <h1>app React Version {version}</h1>
      <RemoteApp component={ParentComponentAdepter} />
    </>
  )
}
export default App

FAQs

Package last updated on 01 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts