Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"biome": "biome"
},
"engines": {
"node": ">=16.0.0",
"node": ">=18.0.0",
"pnpm": ">=8"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/tsconfig/react.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": ["./base"],
"compilerOptions": {
"types": ["@empjs/cli/types/react"]
"types": ["@empjs/cli/types/react"],
"jsx": "react-jsx"
}
}
8 changes: 4 additions & 4 deletions packages/emp-module-federation/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@empjs/module-federation",
"version": "0.18.4-1",
"version": "0.18.4-2",
"description": "emp module-federation",
"license": "MIT",
"type": "module",
Expand Down Expand Up @@ -67,11 +67,11 @@
"node": ">=16.0.0"
},
"author": "Ken",
"devDependencies": {},
"dependencies": {
"@module-federation/sdk": "0.18.4",
"@module-federation/error-codes": "0.18.4",
"@module-federation/rspack": "0.18.4",
"@module-federation/runtime": "^0.18.4",
"@module-federation/runtime-core": "0.18.4",
"@module-federation/rspack": "0.18.4"
"@module-federation/sdk": "0.18.4"
}
}
1 change: 1 addition & 0 deletions packages/emp-module-federation/src/runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@module-federation/runtime'
2 changes: 1 addition & 1 deletion packages/emp-module-federation/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineConfig(({watch}) => {
return {
// entry: ['src/runtime/index.ts', 'src/sdk.ts', 'src/rspack.ts'],
entry: {
runtime: 'src/runtime/index.ts',
runtime: 'src/runtime.ts',
sdk: 'src/sdk.ts',
rspack: 'src/rspack.ts',
},
Expand Down
19 changes: 16 additions & 3 deletions packages/emp-share/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@empjs/share",
"version": "3.10.0",
"version": "3.10.0-beta.5",
"description": "emp share and runtime",
"license": "MIT",
"type": "module",
Expand Down Expand Up @@ -37,6 +37,16 @@
"default": "./dist/runtime.cjs"
}
},
"./mfRuntime": {
"import": {
"types": "./dist/mfRuntime.d.ts",
"default": "./dist/mfRuntime.js"
},
"require": {
"types": "./dist/mfRuntime.d.cts",
"default": "./dist/mfRuntime.cjs"
}
},
"./adapter": {
"import": {
"types": "./dist/adapter.d.ts",
Expand Down Expand Up @@ -76,6 +86,7 @@
"*": {
".": ["./dist/index.d.ts"],
"runtime": ["./dist/runtime.d.ts"],
"mfRuntime": ["./dist/mfRuntime.d.ts"],
"adapter": ["./dist/adapter.d.ts"],
"adapterVue": ["./dist/adapter.d.ts"],
"rspack": ["./dist/rspack.d.ts"],
Expand All @@ -95,8 +106,10 @@
},
"author": "Ken",
"dependencies": {
"core-js": "^3.45.1",
"@empjs/module-federation": "workspace:*"
"@module-federation/rspack": "0.18.4",
"@module-federation/runtime": "^0.18.4",
"@module-federation/sdk": "0.18.4",
"core-js": "^3.45.1"
},
"devDependencies": {
"@empjs/cli": "workspace:*",
Expand Down
7 changes: 4 additions & 3 deletions packages/emp-share/src/helper/moduleFederation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as MFRuntime from '@empjs/module-federation/runtime'
import * as MFSDK from '@empjs/module-federation/sdk'
import * as MFRuntime from '@module-federation/runtime'
import * as MFSDK from '@module-federation/sdk'
export {MFRuntime, MFSDK}

// export type FederationRuntimePlugin = MFRuntime.FederationRuntimePlugin
import type {ModuleFederationRuntimePlugin} from '@empjs/module-federation/runtime'
import type {ModuleFederationRuntimePlugin} from '@module-federation/runtime'
export type FederationRuntimePlugin = ModuleFederationRuntimePlugin
export type {ModuleFederationRuntimePlugin}
2 changes: 1 addition & 1 deletion packages/emp-share/src/helper/rspack.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {ModuleFederationPlugin} from '@empjs/module-federation/rspack'
export {ModuleFederationPlugin} from '@module-federation/rspack'
57 changes: 57 additions & 0 deletions packages/emp-share/src/runtime/index-bakup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {deepAssign} from 'src/helper'
import {shareGlobalName} from 'src/helper/config'
import type {EMPShareRuntimeType, EmpRuntimeOptions, InitOptionsType, LoadRemoteType} from 'src/types'

type EmpInitOptionsType = Partial<InitOptionsType>
let globalLib = window[shareGlobalName] || {}
// 根据 injectGlobalValToHtml 提前把库赋值到 EMPRuntime
const win: any = window
const {EMPShareGlobalVal} = win || {}
if (EMPShareGlobalVal && EMPShareGlobalVal.runtimeLib) {
globalLib = win[EMPShareGlobalVal.runtimeLib]
}

export class EMPRuntime {
public libs: EMPShareRuntimeType = globalLib
public initOptions!: InitOptionsType
public options: EmpRuntimeOptions = {
showLog: false,
}
public shareGlobalName = shareGlobalName
private isInit = false
constructor(op?: EMPShareRuntimeType) {
if (op) this.setup(op)
}
/**
* 实例化 adapter libs
*/
public setup(o?: EMPShareRuntimeType | string) {
if (o) {
if (typeof o === 'string') o = window[o]
this.libs = o as any
}
if (!this.libs.MFRuntime || !this.libs.MFSDK) {
throw new Error('MFRuntime and MFSDK Required!')
}
}
public init(options: EmpInitOptionsType = {}) {
if (this.isInit) return
let op: InitOptionsType = {
name: 'empRuntimeProject',
remotes: [],
// plugins: [catchErrorNextPlugin(this.options.showLog)],
}
op = deepAssign<InitOptionsType>(op, options)
this.libs.MFRuntime.init(op)
this.isInit = true
}
public load<T = any>(...args: LoadRemoteType) {
return this.libs.MFRuntime.loadRemote<T>(...args) as Promise<T>
}
public register = this.libs?.MFRuntime.registerRemotes
public preload = this.libs?.MFRuntime.preloadRemote
public loadShare = this.libs?.MFRuntime.loadShare
public preloadRemote = this.libs?.MFRuntime.preloadRemote
}
//
export default new EMPRuntime()
29 changes: 17 additions & 12 deletions packages/emp-share/src/runtime/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {ModuleFederation} from '@module-federation/runtime'
import {deepAssign} from 'src/helper'
import {shareGlobalName} from 'src/helper/config'
import type {EMPShareRuntimeType, EmpRuntimeOptions, InitOptionsType, LoadRemoteType} from 'src/types'
Expand All @@ -18,13 +19,10 @@ export class EMPRuntime {
showLog: false,
}
public shareGlobalName = shareGlobalName
private isInit = false
constructor(op?: EMPShareRuntimeType) {
if (op) this.setup(op)
}
/**
* 实例化 adapter libs
*/
public mfInstance?: ModuleFederation
public setup(o?: EMPShareRuntimeType | string) {
if (o) {
if (typeof o === 'string') o = window[o]
Expand All @@ -35,23 +33,30 @@ export class EMPRuntime {
}
}
public init(options: EmpInitOptionsType = {}) {
if (this.isInit) return
if (this.mfInstance) return this.mfInstance
let op: InitOptionsType = {
name: 'empRuntimeProject',
remotes: [],
// plugins: [catchErrorNextPlugin(this.options.showLog)],
}
op = deepAssign<InitOptionsType>(op, options)
this.libs.MFRuntime.init(op)
this.isInit = true
this.mfInstance = this.libs.MFRuntime.createInstance(op)
}
public load<T = any>(...args: LoadRemoteType) {
return this.libs.MFRuntime.loadRemote<T>(...args) as Promise<T>
return this.mfInstance?.loadRemote<T>(...args) as Promise<T>
}
public register(...args: Parameters<NonNullable<typeof this.mfInstance>['registerRemotes']>) {
return this.mfInstance?.registerRemotes(...args)
}
public preload(...args: Parameters<NonNullable<typeof this.mfInstance>['preloadRemote']>) {
return this.mfInstance?.preloadRemote(...args)
}
public loadShare(...args: Parameters<NonNullable<typeof this.mfInstance>['loadShare']>) {
return this.mfInstance?.loadShare(...args)
}
public preloadRemote(...args: Parameters<NonNullable<typeof this.mfInstance>['preloadRemote']>) {
return this.mfInstance?.preloadRemote(...args)
}
public register = this.libs?.MFRuntime.registerRemotes
public preload = this.libs?.MFRuntime.preloadRemote
public loadShare = this.libs?.MFRuntime.loadShare
public preloadRemote = this.libs?.MFRuntime.preloadRemote
}
//
export default new EMPRuntime()
1 change: 1 addition & 0 deletions packages/emp-share/src/runtime/mfRuntime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@module-federation/runtime'
1 change: 1 addition & 0 deletions packages/emp-share/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default defineConfig(({watch}): Options[] => {
entry: {
index: 'src/index.ts',
runtime: 'src/runtime/index.ts',
mfRuntime: 'src/runtime/mfRuntime.ts',
adapter: 'src/adapter/index.ts',
rspack: 'src/plugins/rspack/index.ts',
adapterVue: 'src/adapter/vue.ts',
Expand Down
15 changes: 12 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion projects/mf-app/emp.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {defineConfig} from '@empjs/cli'
import pluginReact from '@empjs/plugin-react'
import pluginRspackEmpShare, {externalReact} from '@empjs/share/rspack'
import getConfig from '../mf-host/emp.runtime'
export default defineConfig(store => {
// const ip = store.getLanIp()
// const {empRuntime, polyfillCdn} = getConfig(ip, store)
Expand Down Expand Up @@ -43,6 +42,9 @@ export default defineConfig(store => {
return o
},
},
dts: {
consumeTypes: true,
},
// experiments: {
// federationRuntime: 'hoisted',
// },
Expand Down
2 changes: 1 addition & 1 deletion projects/mf-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Bound from './Bound'
const App = () => (
<div className={css.main}>
<Bound name="MF-Host">
<Host from="fromMainAppName" nameformRemote="nameformRemote" />
<Host from="fromMainAppName" nameformRemote="nameformRemote" increment={1} />
</Bound>
<Bound name="MF-APP">
<h1>mf-app</h1>
Expand Down
14 changes: 7 additions & 7 deletions projects/mf-host/emp.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ export default defineConfig(store => {
// requiredVersion: '18',
// },
// },
experiments: {
asyncStartup: true,
},
// experiments: {
// asyncStartup: true,
// },
exposes: {
'./App': './src/App',
'./CountComp': './src/CountComp',
'./Section': './src/component/Section',
},
manifest: true,
// dts: {
// generateTypes: true,
// },
dts: {
generateTypes: true,
},
// dev: {
// disableHotTypesReload: false,
// disableDynamicRemoteTypeHints: false,
Expand Down Expand Up @@ -84,7 +84,7 @@ export default defineConfig(store => {
// },
},
debug: {
// showRsconfig: true,
// showRsconfig: 'log.json',
clearLog: false,
},
chain(config) {
Expand Down
3 changes: 2 additions & 1 deletion projects/mf-host/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type AppType = {
version?: string
component?: any
nameformRemote?: string
increment?: number
}
console.log('test console')

Expand All @@ -24,7 +25,7 @@ function App(o: AppType) {
{/* <ReactLogo /> */}
</a>
</div>
<h1>EMP 3.0 React {version} </h1>
<h1>EMP 3.0 React {version}</h1>
<ShowCountComp />
{o.from ? <p>{o.from}</p> : ''}
{o.nameformRemote ? <p>{o.nameformRemote}</p> : ''}
Expand Down
8 changes: 8 additions & 0 deletions projects/runtime-18-app/.mf/typesGenerate.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[2025-09-11T18:34:25.121] [WARN] Module Federation DTS - Connection closed with code 1006.
[2025-09-11T18:34:25.122] [INFO] Module Federation DTS - start reconnecting to server after 1s.
[2025-09-11T18:34:26.126] [INFO] Module Federation DTS - Publisher:runtime_app Trying to connect to ws://172.29.96.250:16322...
[2025-09-11T18:34:26.140] [FATAL] Module Federation DTS - Failed to connect to ws://172.29.96.250:16322...
[2025-09-11T18:34:26.141] [WARN] Module Federation DTS - Connection closed with code 1006.
[2025-09-11T18:34:26.141] [INFO] Module Federation DTS - start reconnecting to server after 1s.
[2025-09-11T18:34:26.218] [WARN] Module Federation DTS - Creating new background broker...
[2025-09-11T18:34:26.384] [INFO] StartBroker - startBroker... 6819
12 changes: 8 additions & 4 deletions projects/runtime-18-app/emp.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export default defineConfig(store => {
pluginRspackEmpShare({
name: `runtime_app`,
manifest: true,
experiments: {
asyncStartup: true,
},
// experiments: {
// asyncStartup: true,
// },
exposes: {
'./Title': './src/Title',
// './Title': './src/Title',
},
empRuntime: {
framework: {
Expand All @@ -26,6 +26,10 @@ export default defineConfig(store => {
},
setExternals: externalReact,
},
// dts: {
// generateTypes: false,
// consumeTypes: true,
// },
}),
],
build: {
Expand Down