@empjs/share 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -36
- package/dist/adapter.cjs +1 -1
- package/dist/adapter.cjs.map +1 -1
- package/dist/adapter.d.cts +10 -3
- package/dist/adapter.d.ts +10 -3
- package/dist/adapter.js +1 -1
- package/dist/adapter.js.map +1 -1
- package/dist/index-CLt6ciOL.d.cts +21 -0
- package/dist/index-CLt6ciOL.d.ts +21 -0
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/rspack.cjs +2 -2
- package/dist/rspack.cjs.map +1 -1
- package/dist/rspack.d.cts +5 -4
- package/dist/rspack.d.ts +5 -4
- package/dist/rspack.js +2 -2
- package/dist/rspack.js.map +1 -1
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.d.cts +5 -7
- package/dist/runtime.d.ts +5 -7
- package/dist/runtime.js +1 -1
- package/dist/runtime.js.map +1 -1
- package/package.json +4 -5
- package/dist/react-BIjkQYoz.d.cts +0 -30
- package/dist/react-BIjkQYoz.d.ts +0 -30
package/README.md
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
>
|
|
4
4
|
使用方法
|
|
5
5
|
```js
|
|
6
|
-
import {pluginRspackEmpShare} from '@empjs/share'
|
|
7
|
-
// import pluginRspackEmpShare from '@empjs/share/rspack' // or
|
|
6
|
+
import {pluginRspackEmpShare} from '@empjs/share/rspack'
|
|
8
7
|
import {defineConfig} from '@empjs/cli'
|
|
9
8
|
export default defineConfig(store => {
|
|
10
9
|
return {
|
|
@@ -37,53 +36,48 @@ export default defineConfig(store => {
|
|
|
37
36
|
### 项目调用
|
|
38
37
|
|
|
39
38
|
```js
|
|
40
|
-
import React, {
|
|
41
|
-
import ReactDOM from
|
|
42
|
-
|
|
43
|
-
import {
|
|
39
|
+
import React, {useEffect, useState, version} from 'react'
|
|
40
|
+
import ReactDOM from 'react-dom'
|
|
41
|
+
import {CountComp as CountComp16, ShowCountComp as ShowCountComp16, Card} from './CountComp'
|
|
42
|
+
import {reactAdapter} from '@empjs/share/adapter' // 使用 react
|
|
43
|
+
import empRuntime from '@empjs/share/runtime' // runtime 加载器
|
|
44
|
+
const entry = process.env.mfhost as string
|
|
44
45
|
// 实例化远程 emp
|
|
45
46
|
empRuntime.init({
|
|
47
|
+
shared: reactAdapter.shared,
|
|
46
48
|
remotes: [
|
|
47
49
|
{
|
|
48
|
-
name:
|
|
49
|
-
entry
|
|
50
|
+
name: 'mfHost',
|
|
51
|
+
entry,
|
|
50
52
|
},
|
|
51
53
|
],
|
|
52
|
-
name:
|
|
53
|
-
})
|
|
54
|
+
name: 'federationRuntimeDemo',
|
|
55
|
+
})
|
|
54
56
|
// 封装 React 18的组件 以便插入到 React 16
|
|
55
|
-
const
|
|
57
|
+
const MfApp = reactAdapter.adapter(empRuntime.load('mfHost/App'))
|
|
58
|
+
const CountComp = reactAdapter.adapter(empRuntime.load('mfHost/CountComp'), 'CountComp')
|
|
59
|
+
|
|
56
60
|
// 创建 React 16 组件
|
|
57
61
|
const ParentComponent = () => {
|
|
58
|
-
const [count, setCount] = useState(0);
|
|
59
62
|
return (
|
|
60
|
-
<
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
>
|
|
67
|
-
<h1>React Version {React.version}!</h1>
|
|
68
|
-
<button onClick={() => setCount(count + 1)}>Click Count {count}</button>
|
|
69
|
-
</div>
|
|
70
|
-
);
|
|
71
|
-
};
|
|
63
|
+
<Card title={() => <>App Inject mfHost</>}>
|
|
64
|
+
<CountComp name="a" />
|
|
65
|
+
<CountComp16 />
|
|
66
|
+
</Card>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
72
69
|
// 封装 React 16的组件 以便插入到 React 18
|
|
73
|
-
const
|
|
74
|
-
ParentComponent,
|
|
75
|
-
"default",
|
|
76
|
-
React,
|
|
77
|
-
ReactDOM
|
|
78
|
-
);
|
|
79
|
-
//
|
|
70
|
+
const ParentComponentAdepter = reactAdapter.adapter(ParentComponent, 'default', React, ReactDOM)
|
|
80
71
|
const App = () => {
|
|
81
72
|
return (
|
|
82
73
|
<>
|
|
83
|
-
<h1>
|
|
84
|
-
<
|
|
74
|
+
<h1>App React Version {version}</h1>
|
|
75
|
+
<ShowCountComp16 />
|
|
76
|
+
<Card title="EMP From mfhost">
|
|
77
|
+
<MfApp component={ParentComponentAdepter} />
|
|
78
|
+
</Card>
|
|
85
79
|
</>
|
|
86
|
-
)
|
|
87
|
-
}
|
|
88
|
-
export default App
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
export default App
|
|
89
83
|
```
|
package/dist/adapter.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var c=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var x=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})},C=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of P(e))!v.call(t,i)&&i!==r&&c(t,i,{get:()=>e[i],enumerable:!(n=g(e,i))||n.enumerable});return t};var O=t=>C(c({},"__esModule",{value:!0}),t);var M={};x(M,{default:()=>w,reactAdapter:()=>l});module.exports=O(M);var m=t=>t?Number(t.split(".")[0]):0,d=t=>t&&Object.prototype.toString.call(t)==="[object Promise]";var y={},b=window,{EMPShareGlobalVal:p}=b||{};p&&p.frameworkLib&&(y=b[p.frameworkLib]);var u=class{libs={scope:"default",...y};constructor(e){e&&this.setup(e)}setup(e){e&&(typeof e=="string"&&(e=window[e]),this.libs={...this.libs,...e})}get shared(){let{React:e,ReactDOM:r,scope:n}=this.libs;return{react:{lib:()=>e,version:e.version,scope:n,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}},"react-dom":{lib:()=>r,version:r.version,scope:n,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}}}}adapter(e,r=this.libs.scope,n=this.libs.React,i=this.libs.ReactDOM){let h=m(n.version),f=this;class R extends n.Component{containerRef;root;constructor(s){super(s),this.containerRef=n.createRef()}componentDidMount(){this.mountOriginalComponent(!0)}componentDidUpdate(){this.mountOriginalComponent()}componentWillUnmount(){this.unMountOriginalComponent()}unMountOriginalComponent(){this.containerRef.current&&(h<18?i.unmountComponentAtNode(this.containerRef.current):this.root.unmount())}async mountOriginalComponent(s){d(e)&&(e=await e.then(o=>o[r]));let a=n.createElement(e,this.props);if(h<18)(s?i.render:i.hydrate)(a,this.containerRef.current);else if(s){let{createRoot:o}=f.libs;this.root=o(this.containerRef.current),this.root.render(a)}else{let{hydrateRoot:o}=f.libs;this.root=o(this.containerRef.current,a)}}render(){return n.createElement("div",{ref:this.containerRef})}}return R}},l=new u;var w=l;0&&(module.exports={reactAdapter});
|
|
2
2
|
//# sourceMappingURL=adapter.cjs.map
|
package/dist/adapter.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapter.ts","../src/helper/index.ts","../src/
|
|
1
|
+
{"version":3,"sources":["../src/adapter/index.ts","../src/helper/index.ts","../src/adapter/react.tsx"],"sourcesContent":["import reactAdapter from 'src/adapter/react'\nexport {reactAdapter}\nexport default reactAdapter\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","import {checkVersion, isPromise} from 'src/helper'\nimport type {EMPShareRuntimeAdapterReactType, InitOptionsType} from 'src/types'\n//\nlet globalLib = {}\nconst win: any = window\nconst {EMPShareGlobalVal} = win || {}\nif (EMPShareGlobalVal && EMPShareGlobalVal.frameworkLib) {\n globalLib = win[EMPShareGlobalVal.frameworkLib]\n}\n//\nexport class ReactAdapter {\n libs: EMPShareRuntimeAdapterReactType = {\n scope: 'default',\n ...globalLib,\n }\n constructor(op?: EMPShareRuntimeAdapterReactType) {\n if (op) this.setup(op)\n }\n public setup(o?: EMPShareRuntimeAdapterReactType | string) {\n if (o) {\n if (typeof o === 'string') o = window[o]\n this.libs = {...this.libs, ...(o as any)}\n }\n }\n get shared(): InitOptionsType['shared'] {\n const {React, ReactDOM, scope} = this.libs as EMPShareRuntimeAdapterReactType\n return {\n react: {\n lib: () => React,\n version: React.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n lib: () => ReactDOM,\n version: ReactDOM.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n }\n }\n adapter<P = any>(\n component: any,\n scope: string = this.libs.scope,\n React: any = this.libs.React,\n ReactDOM: any = this.libs.ReactDOM,\n ): P {\n const reactVersion = checkVersion(React.version)\n const self = this\n class WrappedComponent extends React.Component {\n public containerRef: any\n public root: any\n constructor(props: P) {\n super(props as any)\n this.containerRef = React.createRef()\n }\n\n componentDidMount() {\n this.mountOriginalComponent(true)\n }\n\n componentDidUpdate() {\n this.mountOriginalComponent()\n }\n\n componentWillUnmount() {\n this.unMountOriginalComponent()\n }\n unMountOriginalComponent() {\n if (!this.containerRef.current) return\n if (reactVersion < 18) {\n ReactDOM.unmountComponentAtNode(this.containerRef.current)\n } else {\n this.root.unmount()\n }\n }\n async mountOriginalComponent(shouldRender?: boolean) {\n if (isPromise(component))\n component = await component.then((m: any) => {\n return m[scope]\n })\n const element = React.createElement(component, this.props)\n if (reactVersion < 18) {\n const Render = shouldRender ? ReactDOM.render : ReactDOM.hydrate\n Render(element, this.containerRef.current)\n } else {\n if (shouldRender) {\n const {createRoot} = self.libs\n this.root = createRoot(this.containerRef.current!)\n this.root.render(element)\n } else {\n const {hydrateRoot} = self.libs\n this.root = hydrateRoot(this.containerRef.current!, element)\n }\n }\n }\n\n render() {\n return <div ref={this.containerRef} />\n }\n }\n return WrappedComponent as any\n }\n}\n\nexport default new ReactAdapter()\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,iBAAAC,IAAA,eAAAC,EAAAJ,GCiBO,IAAMK,EAAgBC,GAAqBA,EAAU,OAAOA,EAAQ,MAAM,GAAG,EAAE,CAAC,CAAC,EAAI,EAC/EC,EAAaC,GAAWA,GAAK,OAAO,UAAU,SAAS,KAAKA,CAAC,IAAM,mBCfhF,IAAIC,EAAY,CAAC,EACXC,EAAW,OACX,CAAC,kBAAAC,CAAiB,EAAID,GAAO,CAAC,EAChCC,GAAqBA,EAAkB,eACzCF,EAAYC,EAAIC,EAAkB,YAAY,GAGzC,IAAMC,EAAN,KAAmB,CACxB,KAAwC,CACtC,MAAO,UACP,GAAGH,CACL,EACA,YAAYI,EAAsC,CAC5CA,GAAI,KAAK,MAAMA,CAAE,CACvB,CACO,MAAMC,EAA8C,CACrDA,IACE,OAAOA,GAAM,WAAUA,EAAI,OAAOA,CAAC,GACvC,KAAK,KAAO,CAAC,GAAG,KAAK,KAAM,GAAIA,CAAS,EAE5C,CACA,IAAI,QAAoC,CACtC,GAAM,CAAC,MAAAC,EAAO,SAAAC,EAAU,MAAAC,CAAK,EAAI,KAAK,KACtC,MAAO,CACL,MAAO,CACL,IAAK,IAAMF,EACX,QAASA,EAAM,QACf,MAAAE,EACA,YAAa,CACX,UAAW,GACX,gBAAiB,IAAIF,EAAM,OAAO,EACpC,CACF,EACA,YAAa,CACX,IAAK,IAAMC,EACX,QAASA,EAAS,QAClB,MAAAC,EACA,YA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_exports","__export","adapter_default","react_default","__toCommonJS","checkVersion","version","isPromise","p","globalLib","win","EMPShareGlobalVal","ReactAdapter","op","o","React","ReactDOM","scope","component","reactVersion","checkVersion","self","WrappedComponent","props","shouldRender","isPromise","m","element","createRoot","hydrateRoot","react_default","adapter_default","react_default"]}
|
package/dist/adapter.d.cts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '@empjs/module-federation-runtime';
|
|
1
|
+
import { b as EMPShareRuntimeAdapterReactType, I as InitOptionsType } from './index-CLt6ciOL.cjs';
|
|
3
2
|
import '@module-federation/sdk';
|
|
3
|
+
import '@module-federation/enhanced/runtime';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
declare class ReactAdapter {
|
|
6
|
+
libs: EMPShareRuntimeAdapterReactType;
|
|
7
|
+
constructor(op?: EMPShareRuntimeAdapterReactType);
|
|
8
|
+
setup(o?: EMPShareRuntimeAdapterReactType | string): void;
|
|
9
|
+
get shared(): InitOptionsType['shared'];
|
|
10
|
+
adapter<P = any>(component: any, scope?: string, React?: any, ReactDOM?: any): P;
|
|
11
|
+
}
|
|
12
|
+
declare const _default: ReactAdapter;
|
|
6
13
|
|
|
7
14
|
export { _default as default, _default as reactAdapter };
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '@empjs/module-federation-runtime';
|
|
1
|
+
import { b as EMPShareRuntimeAdapterReactType, I as InitOptionsType } from './index-CLt6ciOL.js';
|
|
3
2
|
import '@module-federation/sdk';
|
|
3
|
+
import '@module-federation/enhanced/runtime';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
declare class ReactAdapter {
|
|
6
|
+
libs: EMPShareRuntimeAdapterReactType;
|
|
7
|
+
constructor(op?: EMPShareRuntimeAdapterReactType);
|
|
8
|
+
setup(o?: EMPShareRuntimeAdapterReactType | string): void;
|
|
9
|
+
get shared(): InitOptionsType['shared'];
|
|
10
|
+
adapter<P = any>(component: any, scope?: string, React?: any, ReactDOM?: any): P;
|
|
11
|
+
}
|
|
12
|
+
declare const _default: ReactAdapter;
|
|
6
13
|
|
|
7
14
|
export { _default as default, _default as reactAdapter };
|
package/dist/adapter.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
var h=n=>n?Number(n.split(".")[0]):0,f=n=>n&&Object.prototype.toString.call(n)==="[object Promise]";var m={},d=window,{EMPShareGlobalVal:c}=d||{};c&&c.frameworkLib&&(m=d[c.frameworkLib]);var p=class{libs={scope:"default",...m};constructor(e){e&&this.setup(e)}setup(e){e&&(typeof e=="string"&&(e=window[e]),this.libs={...this.libs,...e})}get shared(){let{React:e,ReactDOM:i,scope:t}=this.libs;return{react:{lib:()=>e,version:e.version,scope:t,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}},"react-dom":{lib:()=>i,version:i.version,scope:t,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}}}}adapter(e,i=this.libs.scope,t=this.libs.React,s=this.libs.ReactDOM){let u=h(t.version),l=this;class b extends t.Component{containerRef;root;constructor(o){super(o),this.containerRef=t.createRef()}componentDidMount(){this.mountOriginalComponent(!0)}componentDidUpdate(){this.mountOriginalComponent()}componentWillUnmount(){this.unMountOriginalComponent()}unMountOriginalComponent(){this.containerRef.current&&(u<18?s.unmountComponentAtNode(this.containerRef.current):this.root.unmount())}async mountOriginalComponent(o){f(e)&&(e=await e.then(r=>r[i]));let a=t.createElement(e,this.props);if(u<18)(o?s.render:s.hydrate)(a,this.containerRef.current);else if(o){let{createRoot:r}=l.libs;this.root=r(this.containerRef.current),this.root.render(a)}else{let{hydrateRoot:r}=l.libs;this.root=r(this.containerRef.current,a)}}render(){return t.createElement("div",{ref:this.containerRef})}}return b}},y=new p;var C=y;export{C as default,y as reactAdapter};
|
|
2
2
|
//# sourceMappingURL=adapter.js.map
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/helper/index.ts","../src/
|
|
1
|
+
{"version":3,"sources":["../src/helper/index.ts","../src/adapter/react.tsx","../src/adapter/index.ts"],"sourcesContent":["export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","import {checkVersion, isPromise} from 'src/helper'\nimport type {EMPShareRuntimeAdapterReactType, InitOptionsType} from 'src/types'\n//\nlet globalLib = {}\nconst win: any = window\nconst {EMPShareGlobalVal} = win || {}\nif (EMPShareGlobalVal && EMPShareGlobalVal.frameworkLib) {\n globalLib = win[EMPShareGlobalVal.frameworkLib]\n}\n//\nexport class ReactAdapter {\n libs: EMPShareRuntimeAdapterReactType = {\n scope: 'default',\n ...globalLib,\n }\n constructor(op?: EMPShareRuntimeAdapterReactType) {\n if (op) this.setup(op)\n }\n public setup(o?: EMPShareRuntimeAdapterReactType | string) {\n if (o) {\n if (typeof o === 'string') o = window[o]\n this.libs = {...this.libs, ...(o as any)}\n }\n }\n get shared(): InitOptionsType['shared'] {\n const {React, ReactDOM, scope} = this.libs as EMPShareRuntimeAdapterReactType\n return {\n react: {\n lib: () => React,\n version: React.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n lib: () => ReactDOM,\n version: ReactDOM.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n }\n }\n adapter<P = any>(\n component: any,\n scope: string = this.libs.scope,\n React: any = this.libs.React,\n ReactDOM: any = this.libs.ReactDOM,\n ): P {\n const reactVersion = checkVersion(React.version)\n const self = this\n class WrappedComponent extends React.Component {\n public containerRef: any\n public root: any\n constructor(props: P) {\n super(props as any)\n this.containerRef = React.createRef()\n }\n\n componentDidMount() {\n this.mountOriginalComponent(true)\n }\n\n componentDidUpdate() {\n this.mountOriginalComponent()\n }\n\n componentWillUnmount() {\n this.unMountOriginalComponent()\n }\n unMountOriginalComponent() {\n if (!this.containerRef.current) return\n if (reactVersion < 18) {\n ReactDOM.unmountComponentAtNode(this.containerRef.current)\n } else {\n this.root.unmount()\n }\n }\n async mountOriginalComponent(shouldRender?: boolean) {\n if (isPromise(component))\n component = await component.then((m: any) => {\n return m[scope]\n })\n const element = React.createElement(component, this.props)\n if (reactVersion < 18) {\n const Render = shouldRender ? ReactDOM.render : ReactDOM.hydrate\n Render(element, this.containerRef.current)\n } else {\n if (shouldRender) {\n const {createRoot} = self.libs\n this.root = createRoot(this.containerRef.current!)\n this.root.render(element)\n } else {\n const {hydrateRoot} = self.libs\n this.root = hydrateRoot(this.containerRef.current!, element)\n }\n }\n }\n\n render() {\n return <div ref={this.containerRef} />\n }\n }\n return WrappedComponent as any\n }\n}\n\nexport default new ReactAdapter()\n","import reactAdapter from 'src/adapter/react'\nexport {reactAdapter}\nexport default reactAdapter\n"],"mappings":"AAiBO,IAAMA,EAAgBC,GAAqBA,EAAU,OAAOA,EAAQ,MAAM,GAAG,EAAE,CAAC,CAAC,EAAI,EAC/EC,EAAaC,GAAWA,GAAK,OAAO,UAAU,SAAS,KAAKA,CAAC,IAAM,mBCfhF,IAAIC,EAAY,CAAC,EACXC,EAAW,OACX,CAAC,kBAAAC,CAAiB,EAAID,GAAO,CAAC,EAChCC,GAAqBA,EAAkB,eACzCF,EAAYC,EAAIC,EAAkB,YAAY,GAGzC,IAAMC,EAAN,KAAmB,CACxB,KAAwC,CACtC,MAAO,UACP,GAAGH,CACL,EACA,YAAYI,EAAsC,CAC5CA,GAAI,KAAK,MAAMA,CAAE,CACvB,CACO,MAAMC,EAA8C,CACrDA,IACE,OAAOA,GAAM,WA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AAAI,CAAU,EAAIP,EAAK,KAC1B,KAAK,KAAOO,EAAW,KAAK,aAAa,OAAQ,EACjD,KAAK,KAAK,OAAOD,CAAO,CAC1B,KAAO,CACL,GAAM,CAAC,YAAAE,CAAW,EAAIR,EAAK,KAC3B,KAAK,KAAOQ,EAAY,KAAK,aAAa,QAAUF,CAAO,CAC7D,CAEJ,CAEA,QAAS,CACP,OAAOZ,EAAA,cAAC,OAAI,IAAK,KAAK,aAAc,CACtC,CACF,CACA,OAAOO,CACT,CACF,EAEOQ,EAAQ,IAAIlB,EC7GnB,IAAOmB,EAAQC","names":["checkVersion","version","isPromise","p","globalLib","win","EMPShareGlobalVal","ReactAdapter","op","o","React","ReactDOM","scope","component","reactVersion","checkVersion","self","WrappedComponent","props","shouldRender","isPromise","m","element","createRoot","hydrateRoot","react_default","adapter_default","react_default"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import MFSDK from '@module-federation/sdk';
|
|
2
|
+
import MFRuntime__default from '@module-federation/enhanced/runtime';
|
|
3
|
+
|
|
4
|
+
type EMPShareRuntimeType = {
|
|
5
|
+
MFRuntime: Required<typeof MFRuntime__default>;
|
|
6
|
+
MFSDK: Required<typeof MFSDK>;
|
|
7
|
+
};
|
|
8
|
+
type EMPShareRuntimeAdapterReactType = {
|
|
9
|
+
React?: any;
|
|
10
|
+
ReactDOM?: any;
|
|
11
|
+
createRoot?: any;
|
|
12
|
+
hydrateRoot?: any;
|
|
13
|
+
scope: string;
|
|
14
|
+
};
|
|
15
|
+
type InitOptionsType = Parameters<typeof MFRuntime__default.init>[0];
|
|
16
|
+
type LoadRemoteType = Parameters<typeof MFRuntime__default.loadRemote>;
|
|
17
|
+
type EmpRuntimeOptions = {
|
|
18
|
+
showLog?: boolean;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type { EMPShareRuntimeType as E, InitOptionsType as I, LoadRemoteType as L, EmpRuntimeOptions as a, EMPShareRuntimeAdapterReactType as b };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import MFSDK from '@module-federation/sdk';
|
|
2
|
+
import MFRuntime__default from '@module-federation/enhanced/runtime';
|
|
3
|
+
|
|
4
|
+
type EMPShareRuntimeType = {
|
|
5
|
+
MFRuntime: Required<typeof MFRuntime__default>;
|
|
6
|
+
MFSDK: Required<typeof MFSDK>;
|
|
7
|
+
};
|
|
8
|
+
type EMPShareRuntimeAdapterReactType = {
|
|
9
|
+
React?: any;
|
|
10
|
+
ReactDOM?: any;
|
|
11
|
+
createRoot?: any;
|
|
12
|
+
hydrateRoot?: any;
|
|
13
|
+
scope: string;
|
|
14
|
+
};
|
|
15
|
+
type InitOptionsType = Parameters<typeof MFRuntime__default.init>[0];
|
|
16
|
+
type LoadRemoteType = Parameters<typeof MFRuntime__default.loadRemote>;
|
|
17
|
+
type EmpRuntimeOptions = {
|
|
18
|
+
showLog?: boolean;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type { EMPShareRuntimeType as E, InitOptionsType as I, LoadRemoteType as L, EmpRuntimeOptions as a, EMPShareRuntimeAdapterReactType as b };
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`);return
|
|
1
|
+
"use strict";var u=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var S=(t,e)=>{for(var n in e)u(t,n,{get:e[n],enumerable:!0})},P=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of k(e))!x.call(t,r)&&r!==n&&u(t,r,{get:()=>e[r],enumerable:!(o=h(e,r))||o.enumerable});return t};var M=t=>P(u({},"__esModule",{value:!0}),t);var H={};S(H,{default:()=>G,pluginRspackEmpShare:()=>f});module.exports=M(H);var E=require("@module-federation/enhanced/rspack");var y="EMP_SHARE_RUNTIME";var d=t=>`data:text/javascript,${t}`;var v=t=>{let e=[`import '${t}'`].join(`
|
|
2
|
+
`);return d(e)},m=class{options;constructor(e){this.options=e}apply(e){let{webpack:n}=e,{runtimeLib:o}=this.options;if(!o){let r=v("@empjs/share/library");new n.EntryPlugin(e.context,r,{name:void 0}).apply(e)}}};function R(t,e){return typeof t=="string"?`${t}/runtime${e==="development"?".development":""}.umd.js`:typeof t=="object"?e==="development"?t.dev:t.prod:""}var w=(t={})=>({name:"@empjs/share",async rsConfig(e){if(t.name){let o=e.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},t);delete o.empRuntime,e.chain.plugin("plugin-emp-share").use(E.ModuleFederationPlugin,[o])}let{empRuntime:n}=t;if(n){let o=[],r=n.framework||"react",{frameworkLib:b,runtimeLib:p}=n,l=n.runtimeGlobal||y,a=n.frameworkGlobal||"";if(n.injectGlobalValToHtml!==!1&&o.push({type:"script",value:`EMPShareGlobalVal={frameworkLib:'${a}',runtimeLib:'${l}',framework:'${r}'}`}),b){let i=R(b,e.mode);o.push({type:"js",value:i})}p?p==="useFrameworkLib"?l=a:o.push({type:"js",value:p}):e.chain.plugin("plugin-emp-share-framework").use(m,[n]),o.length>0&&e.injectHeadTags(o,"EMPShare");let g={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},s={};for(let[i,c]of Object.entries(g))s[i]=`${l}.${c}`;if(r==="react"&&a){let i={react:"React","react-dom":"ReactDOM"};for(let[c,j]of Object.entries(i))s[c]=`${a}.${j}`}n.setExternals&&n.setExternals(s),e.chain.merge({externals:s})}}}),f=w;var G=f;0&&(module.exports={pluginRspackEmpShare});
|
|
3
3
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/plugins/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/plugins/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts"],"sourcesContent":["import {default as pluginRspackEmpShare} from 'src/plugins/rspack'\nexport default pluginRspackEmpShare\nexport {pluginRspackEmpShare}\n","import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\nimport {getRuntimeLib} from './utils'\n//\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n if (o.name) {\n const op: any = store.deepAssign(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n delete op.empRuntime\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n const {empRuntime} = o\n if (empRuntime) {\n const injectHtml: any[] = []\n const framework = empRuntime.framework || 'react'\n const {frameworkLib, runtimeLib} = empRuntime\n //\n let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n const frameworkGlobal = empRuntime.frameworkGlobal || ''\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n type: 'script',\n value: `EMPShareGlobalVal={frameworkLib:'${frameworkGlobal}',runtimeLib:'${runtimeGlobal}',framework:'${framework}'}`,\n })\n }\n /**\n * frameworkLib & runtimeLib 的全局引用\n */\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n type: 'js',\n value: url,\n })\n }\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib') {\n runtimeGlobal = frameworkGlobal\n } else {\n // 插入 runtime\n injectHtml.push({type: 'js', value: runtimeLib})\n }\n if (injectHtml.length > 0) {\n store.injectHeadTags(injectHtml, 'EMPShare')\n }\n /**\n * 设置 externals\n */\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n },\n }\n}\n\nexport default pluginRspackEmpShare\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,yBAAAC,IAAA,eAAAC,EAAAJ,GCCA,IAAAK,EAAqC,8CCD9B,IAAMC,EAAkB,oBCAxB,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GCG9E,IAAMC,EAAuBC,GAAO,CAClC,IAAMC,EAAU,CAAC,WAAWD,CAAG,GAAG,EAAE,KAAK;AAAA,CAAI,EAC7C,OAAOE,EAAWD,CAAO,CAC3B,EACaE,EAAN,KAA8B,CACnC,QACA,YAAYC,EAA4B,CACtC,KAAK,QAAUA,CACjB,CACA,MAAMC,EAAoB,CACxB,GAAM,CAAC,QAAAC,CAAO,EAAID,EACZ,CAAC,WAAAE,CAAU,EAAI,KAAK,QAC1B,GAAI,CAACA,EAAY,CACf,IAAMC,EAAQT,EAAqB,sBAAsB,EACzD,IAAIO,EAAQ,YAAYD,EAAS,QAASG,EAAO,CAC/C,KAAM,MACR,CAAC,EAAE,MAAMH,CAAQ,CACnB,CACF,CACF,ECrBO,SAASI,EAAcC,EAA8CC,EAAc,CACxF,OAAI,OAAOD,GAAS,SAAiB,GAAGA,CAAI,WAAWC,IAAS,cAAgB,eAAiB,EAAE,UAC1F,OAAOD,GAAS,SACnBC,IAAS,cAAsBD,EAAK,IAC5BA,EAAK,KAEZ,EACT,CJDO,IAAME,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CACjC,GAAID,EAAE,KAAM,CACV,IAAME,EAAUD,EAAM,WACpB,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IO,CAAK,EAEhD,CACId,EAAW,cAAcA,EAAW,aAAaY,CAAS,EAG9Dd,EAAM,MAAM,MAAM,CAAC,UAAAc,CAAS,CAAC,CAC/B,CACF,CACF,GAGKI,EAAQpB,ED9Ff,IAAOqB,EAAQC","names":["src_exports","__export","src_default","rspack_default","__toCommonJS","import_rspack","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","pluginRspackEmpShare","o","store","op","empRuntime","injectHtml","framework","frameworkLib","runtimeLib","runtimeGlobal","shareGlobalName","frameworkGlobal","url","getRuntimeLib","EmpShareRemoteLibPlugin","externalRuntime","externals","key","value","externalReact","rspack_default","src_default","rspack_default"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pluginRspackEmpShare from './rspack.cjs';
|
|
2
2
|
import '@empjs/cli';
|
|
3
3
|
import '@module-federation/enhanced/rspack';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
export {
|
|
7
|
+
export { pluginRspackEmpShare as default, pluginRspackEmpShare };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pluginRspackEmpShare from './rspack.js';
|
|
2
2
|
import '@empjs/cli';
|
|
3
3
|
import '@module-federation/enhanced/rspack';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
export {
|
|
7
|
+
export { pluginRspackEmpShare as default, pluginRspackEmpShare };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{ModuleFederationPlugin as
|
|
2
|
-
`);return
|
|
1
|
+
import{ModuleFederationPlugin as j}from"@module-federation/enhanced/rspack";var f="EMP_SHARE_RUNTIME";var b=t=>`data:text/javascript,${t}`;var g=t=>{let e=[`import '${t}'`].join(`
|
|
2
|
+
`);return b(e)},m=class{options;constructor(e){this.options=e}apply(e){let{webpack:n}=e,{runtimeLib:o}=this.options;if(!o){let i=g("@empjs/share/library");new n.EntryPlugin(e.context,i,{name:void 0}).apply(e)}}};function y(t,e){return typeof t=="string"?`${t}/runtime${e==="development"?".development":""}.umd.js`:typeof t=="object"?e==="development"?t.dev:t.prod:""}var h=(t={})=>({name:"@empjs/share",async rsConfig(e){if(t.name){let o=e.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},t);delete o.empRuntime,e.chain.plugin("plugin-emp-share").use(j,[o])}let{empRuntime:n}=t;if(n){let o=[],i=n.framework||"react",{frameworkLib:u,runtimeLib:p}=n,l=n.runtimeGlobal||f,a=n.frameworkGlobal||"";if(n.injectGlobalValToHtml!==!1&&o.push({type:"script",value:`EMPShareGlobalVal={frameworkLib:'${a}',runtimeLib:'${l}',framework:'${i}'}`}),u){let r=y(u,e.mode);o.push({type:"js",value:r})}p?p==="useFrameworkLib"?l=a:o.push({type:"js",value:p}):e.chain.plugin("plugin-emp-share-framework").use(m,[n]),o.length>0&&e.injectHeadTags(o,"EMPShare");let R={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},s={};for(let[r,c]of Object.entries(R))s[r]=`${l}.${c}`;if(i==="react"&&a){let r={react:"React","react-dom":"ReactDOM"};for(let[c,E]of Object.entries(r))s[c]=`${a}.${E}`}n.setExternals&&n.setExternals(s),e.chain.merge({externals:s})}}}),d=h;var L=d;export{L as default,d as pluginRspackEmpShare};
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugins/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts","../src/index.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\nimport {getRuntimeLib} from './utils'\n//\nexport
|
|
1
|
+
{"version":3,"sources":["../src/plugins/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts","../src/index.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\nimport {getRuntimeLib} from './utils'\n//\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n if (o.name) {\n const op: any = store.deepAssign(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n delete op.empRuntime\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n const {empRuntime} = o\n if (empRuntime) {\n const injectHtml: any[] = []\n const framework = empRuntime.framework || 'react'\n const {frameworkLib, runtimeLib} = empRuntime\n //\n let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n const frameworkGlobal = empRuntime.frameworkGlobal || ''\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n type: 'script',\n value: `EMPShareGlobalVal={frameworkLib:'${frameworkGlobal}',runtimeLib:'${runtimeGlobal}',framework:'${framework}'}`,\n })\n }\n /**\n * frameworkLib & runtimeLib 的全局引用\n */\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n type: 'js',\n value: url,\n })\n }\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib') {\n runtimeGlobal = frameworkGlobal\n } else {\n // 插入 runtime\n injectHtml.push({type: 'js', value: runtimeLib})\n }\n if (injectHtml.length > 0) {\n store.injectHeadTags(injectHtml, 'EMPShare')\n }\n /**\n * 设置 externals\n */\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n },\n }\n}\n\nexport default pluginRspackEmpShare\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n","import {default as pluginRspackEmpShare} from 'src/plugins/rspack'\nexport default pluginRspackEmpShare\nexport {pluginRspackEmpShare}\n"],"mappings":"AACA,OAAQ,0BAAAA,MAA6B,qCCD9B,IAAMC,EAAkB,oBCAxB,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GCG9E,IAAMC,EAAuBC,GAAO,CAClC,IAAMC,EAAU,CAAC,WAAWD,CAAG,GAAG,EAAE,KAAK;AAAA,CAAI,EAC7C,OAAOE,EAAWD,CAAO,CAC3B,EACaE,EAAN,KAA8B,CACnC,QACA,YAAYC,EAA4B,CACtC,KAAK,QAAUA,CACjB,CACA,MAAMC,EAAoB,CACxB,GAAM,CAAC,QAAAC,CAAO,EAAID,EACZ,CAAC,WAAAE,CAAU,EAAI,KAAK,QAC1B,GAAI,CAACA,EAAY,CACf,IAAMC,EAAQT,EAAqB,sBAAsB,EACzD,IAAIO,EAAQ,YAAYD,EAAS,QAASG,EAAO,CAC/C,KAAM,MACR,CAAC,EAAE,MAAMH,CAAQ,CACnB,CACF,CACF,ECrBO,SAASI,EAAcC,EAA8CC,EAAc,CACxF,OAAI,OAAOD,GAAS,SAAiB,GAAGA,CAAI,WAAWC,IAAS,cAAgB,eAAiB,EAAE,UAC1F,OAAOD,GAAS,SACnBC,IAAS,cAAsBD,EAAK,IAC5BA,EAAK,KAEZ,EACT,CJDO,IAAME,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,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ACF,EAAKC,CAAK,IAAK,OAAO,QAAQC,CAAa,EACrDH,EAAUC,CAAG,EAAI,GAAGN,CAAe,IAAIO,CAAK,EAEhD,CACId,EAAW,cAAcA,EAAW,aAAaY,CAAS,EAG9Df,EAAM,MAAM,MAAM,CAAC,UAAAe,CAAS,CAAC,CAC/B,CACF,CACF,GAGKI,EAAQrB,EK9Ff,IAAOsB,EAAQC","names":["ModuleFederationPlugin","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","pluginRspackEmpShare","o","store","op","ModuleFederationPlugin","empRuntime","injectHtml","framework","frameworkLib","runtimeLib","runtimeGlobal","shareGlobalName","frameworkGlobal","url","getRuntimeLib","EmpShareRemoteLibPlugin","externalRuntime","externals","key","value","externalReact","rspack_default","src_default","rspack_default"]}
|
package/dist/rspack.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`);return
|
|
1
|
+
"use strict";var u=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var P=(t,e)=>{for(var n in e)u(t,n,{get:e[n],enumerable:!0})},S=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of k(e))!x.call(t,r)&&r!==n&&u(t,r,{get:()=>e[r],enumerable:!(o=h(e,r))||o.enumerable});return t};var M=t=>S(u({},"__esModule",{value:!0}),t);var G={};P(G,{default:()=>w,pluginRspackEmpShare:()=>E});module.exports=M(G);var R=require("@module-federation/enhanced/rspack");var b="EMP_SHARE_RUNTIME";var y=t=>`data:text/javascript,${t}`;var v=t=>{let e=[`import '${t}'`].join(`
|
|
2
|
+
`);return y(e)},m=class{options;constructor(e){this.options=e}apply(e){let{webpack:n}=e,{runtimeLib:o}=this.options;if(!o){let r=v("@empjs/share/library");new n.EntryPlugin(e.context,r,{name:void 0}).apply(e)}}};function d(t,e){return typeof t=="string"?`${t}/runtime${e==="development"?".development":""}.umd.js`:typeof t=="object"?e==="development"?t.dev:t.prod:""}var E=(t={})=>({name:"@empjs/share",async rsConfig(e){if(t.name){let o=e.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},t);delete o.empRuntime,e.chain.plugin("plugin-emp-share").use(R.ModuleFederationPlugin,[o])}let{empRuntime:n}=t;if(n){let o=[],r=n.framework||"react",{frameworkLib:f,runtimeLib:p}=n,l=n.runtimeGlobal||b,s=n.frameworkGlobal||"";if(n.injectGlobalValToHtml!==!1&&o.push({type:"script",value:`EMPShareGlobalVal={frameworkLib:'${s}',runtimeLib:'${l}',framework:'${r}'}`}),f){let i=d(f,e.mode);o.push({type:"js",value:i})}p?p==="useFrameworkLib"?l=s:o.push({type:"js",value:p}):e.chain.plugin("plugin-emp-share-framework").use(m,[n]),o.length>0&&e.injectHeadTags(o,"EMPShare");let j={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},a={};for(let[i,c]of Object.entries(j))a[i]=`${l}.${c}`;if(r==="react"&&s){let i={react:"React","react-dom":"ReactDOM"};for(let[c,g]of Object.entries(i))a[c]=`${s}.${g}`}n.setExternals&&n.setExternals(a),e.chain.merge({externals:a})}}}),w=E;0&&(module.exports={pluginRspackEmpShare});
|
|
3
3
|
//# sourceMappingURL=rspack.cjs.map
|
package/dist/rspack.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/plugins/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\nimport {getRuntimeLib} from './utils'\n//\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n if (o.name) {\n const op: any = store.deepAssign(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n delete op.empRuntime\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n const {empRuntime} = o\n if (empRuntime) {\n const injectHtml: any[] = []\n const framework = empRuntime.framework || 'react'\n const {frameworkLib, runtimeLib} = empRuntime\n //\n let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n const frameworkGlobal = empRuntime.frameworkGlobal || ''\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n type: 'script',\n value: `EMPShareGlobalVal={frameworkLib:'${frameworkGlobal}',runtimeLib:'${runtimeGlobal}',framework:'${framework}'}`,\n })\n }\n /**\n * frameworkLib & runtimeLib 的全局引用\n */\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n type: 'js',\n value: url,\n })\n }\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib') {\n runtimeGlobal = frameworkGlobal\n } else {\n // 插入 runtime\n injectHtml.push({type: 'js', value: runtimeLib})\n }\n if (injectHtml.length > 0) {\n store.injectHeadTags(injectHtml, 'EMPShare')\n }\n /**\n * 设置 externals\n */\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n },\n }\n}\n\nexport default pluginRspackEmpShare\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA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AAU,EAAIJ,EAE/BK,EAAgBL,EAAW,eAAiBM,EAC1CC,EAAkBP,EAAW,iBAAmB,GAYtD,GAX8BA,EAAW,wBAA0B,IAGjEC,EAAW,KAAK,CACd,KAAM,SACN,MAAO,oCAAoCM,CAAe,iBAAiBF,CAAa,gBAAgBH,CAAS,IACnH,CAAC,EAKCC,EAAc,CAChB,IAAMK,EAAMC,EAAcN,EAAcL,EAAM,IAAI,EAClDG,EAAW,KAAK,CACd,KAAM,KACN,MAAOO,CACT,CAAC,CACH,CACKJ,EAKIA,IAAe,kBACtBC,EAAgBE,EAGhBN,EAAW,KAAK,CAAC,KAAM,KAAM,MAAOG,CAAU,CAAC,EAP/CN,EAAM,MAAM,OAAO,4BAA4B,EAAE,IAAIY,EAAyB,CAACV,CAAU,CAAC,EASxFC,EAAW,OAAS,GACtBH,EAAM,eAAeG,EAAY,UAAU,EAK7C,IAAMU,EAAkB,CACtB,6BAA8B,YAC9B,yBAA0B,OAC5B,EACMC,EAAY,CAAC,EACnB,OAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQH,CAAe,EACvDC,EAAUC,CAAG,EAAI,GAAGR,CAAa,IAAIS,CAAK,GAE5C,GAAIZ,IAAc,SAAWK,EAAiB,CAC5C,IAAMQ,EAAgB,CACpB,MAAO,QACP,YAAa,UACf,EACA,OAAW,CAACF,EAAKC,CAAK,IAAK,OAAO,QAAQC,CAAa,EACrDH,EAAUC,CAAG,EAAI,GAAGN,CAAe,IAAIO,CAAK,EAEhD,CACId,EAAW,cAAcA,EAAW,aAAaY,CAAS,EAG9Dd,EAAM,MAAM,MAAM,CAAC,UAAAc,CAAS,CAAC,CAC/B,CACF,CACF,GAGKI,EAAQpB","names":["rspack_exports","__export","rspack_default","pluginRspackEmpShare","__toCommonJS","import_rspack","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","pluginRspackEmpShare","o","store","op","empRuntime","injectHtml","framework","frameworkLib","runtimeLib","runtimeGlobal","shareGlobalName","frameworkGlobal","url","getRuntimeLib","EmpShareRemoteLibPlugin","externalRuntime","externals","key","value","externalReact","rspack_default"]}
|
package/dist/rspack.d.cts
CHANGED
|
@@ -17,24 +17,25 @@ type EMPSHARERuntimeOptions = {
|
|
|
17
17
|
/**
|
|
18
18
|
* MFRuntime 远程地址
|
|
19
19
|
*/
|
|
20
|
-
runtimeLib?: string;
|
|
20
|
+
runtimeLib?: string | 'useFrameworkLib';
|
|
21
21
|
/**
|
|
22
22
|
* MFRuntime 全局命名
|
|
23
23
|
*/
|
|
24
24
|
runtimeGlobal?: string;
|
|
25
25
|
setExternals?: (o: any) => void;
|
|
26
|
+
injectGlobalValToHtml?: boolean;
|
|
26
27
|
/**
|
|
27
28
|
* 快捷设置 external 默认为 react
|
|
28
29
|
*/
|
|
29
|
-
framework?:
|
|
30
|
+
framework?: 'react' | 'vue2' | 'vue';
|
|
30
31
|
};
|
|
31
32
|
type EMPPluginShareType = ModuleFederationPluginOptions & {
|
|
32
33
|
empRuntime?: EMPSHARERuntimeOptions;
|
|
33
34
|
};
|
|
34
35
|
|
|
35
|
-
declare const
|
|
36
|
+
declare const pluginRspackEmpShare: (o?: EMPPluginShareType) => {
|
|
36
37
|
name: string;
|
|
37
38
|
rsConfig(store: GlobalStore): Promise<void>;
|
|
38
39
|
};
|
|
39
40
|
|
|
40
|
-
export {
|
|
41
|
+
export { pluginRspackEmpShare as default, pluginRspackEmpShare };
|
package/dist/rspack.d.ts
CHANGED
|
@@ -17,24 +17,25 @@ type EMPSHARERuntimeOptions = {
|
|
|
17
17
|
/**
|
|
18
18
|
* MFRuntime 远程地址
|
|
19
19
|
*/
|
|
20
|
-
runtimeLib?: string;
|
|
20
|
+
runtimeLib?: string | 'useFrameworkLib';
|
|
21
21
|
/**
|
|
22
22
|
* MFRuntime 全局命名
|
|
23
23
|
*/
|
|
24
24
|
runtimeGlobal?: string;
|
|
25
25
|
setExternals?: (o: any) => void;
|
|
26
|
+
injectGlobalValToHtml?: boolean;
|
|
26
27
|
/**
|
|
27
28
|
* 快捷设置 external 默认为 react
|
|
28
29
|
*/
|
|
29
|
-
framework?:
|
|
30
|
+
framework?: 'react' | 'vue2' | 'vue';
|
|
30
31
|
};
|
|
31
32
|
type EMPPluginShareType = ModuleFederationPluginOptions & {
|
|
32
33
|
empRuntime?: EMPSHARERuntimeOptions;
|
|
33
34
|
};
|
|
34
35
|
|
|
35
|
-
declare const
|
|
36
|
+
declare const pluginRspackEmpShare: (o?: EMPPluginShareType) => {
|
|
36
37
|
name: string;
|
|
37
38
|
rsConfig(store: GlobalStore): Promise<void>;
|
|
38
39
|
};
|
|
39
40
|
|
|
40
|
-
export {
|
|
41
|
+
export { pluginRspackEmpShare as default, pluginRspackEmpShare };
|
package/dist/rspack.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{ModuleFederationPlugin as
|
|
2
|
-
`);return
|
|
1
|
+
import{ModuleFederationPlugin as j}from"@module-federation/enhanced/rspack";var f="EMP_SHARE_RUNTIME";var b=t=>`data:text/javascript,${t}`;var E=t=>{let e=[`import '${t}'`].join(`
|
|
2
|
+
`);return b(e)},m=class{options;constructor(e){this.options=e}apply(e){let{webpack:n}=e,{runtimeLib:o}=this.options;if(!o){let i=E("@empjs/share/library");new n.EntryPlugin(e.context,i,{name:void 0}).apply(e)}}};function y(t,e){return typeof t=="string"?`${t}/runtime${e==="development"?".development":""}.umd.js`:typeof t=="object"?e==="development"?t.dev:t.prod:""}var g=(t={})=>({name:"@empjs/share",async rsConfig(e){if(t.name){let o=e.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},t);delete o.empRuntime,e.chain.plugin("plugin-emp-share").use(j,[o])}let{empRuntime:n}=t;if(n){let o=[],i=n.framework||"react",{frameworkLib:u,runtimeLib:p}=n,l=n.runtimeGlobal||f,s=n.frameworkGlobal||"";if(n.injectGlobalValToHtml!==!1&&o.push({type:"script",value:`EMPShareGlobalVal={frameworkLib:'${s}',runtimeLib:'${l}',framework:'${i}'}`}),u){let r=y(u,e.mode);o.push({type:"js",value:r})}p?p==="useFrameworkLib"?l=s:o.push({type:"js",value:p}):e.chain.plugin("plugin-emp-share-framework").use(m,[n]),o.length>0&&e.injectHeadTags(o,"EMPShare");let d={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},a={};for(let[r,c]of Object.entries(d))a[r]=`${l}.${c}`;if(i==="react"&&s){let r={react:"React","react-dom":"ReactDOM"};for(let[c,R]of Object.entries(r))a[c]=`${s}.${R}`}n.setExternals&&n.setExternals(a),e.chain.merge({externals:a})}}}),O=g;export{O as default,g as pluginRspackEmpShare};
|
|
3
3
|
//# sourceMappingURL=rspack.js.map
|
package/dist/rspack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugins/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\nimport {getRuntimeLib} from './utils'\n//\nexport
|
|
1
|
+
{"version":3,"sources":["../src/plugins/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\nimport {getRuntimeLib} from './utils'\n//\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n if (o.name) {\n const op: any = store.deepAssign(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n delete op.empRuntime\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n const {empRuntime} = o\n if (empRuntime) {\n const injectHtml: any[] = []\n const framework = empRuntime.framework || 'react'\n const {frameworkLib, runtimeLib} = empRuntime\n //\n let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n const frameworkGlobal = empRuntime.frameworkGlobal || ''\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n type: 'script',\n value: `EMPShareGlobalVal={frameworkLib:'${frameworkGlobal}',runtimeLib:'${runtimeGlobal}',framework:'${framework}'}`,\n })\n }\n /**\n * frameworkLib & runtimeLib 的全局引用\n */\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n type: 'js',\n value: url,\n })\n }\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib') {\n runtimeGlobal = frameworkGlobal\n } else {\n // 插入 runtime\n injectHtml.push({type: 'js', value: runtimeLib})\n }\n if (injectHtml.length > 0) {\n store.injectHeadTags(injectHtml, 'EMPShare')\n }\n /**\n * 设置 externals\n */\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n },\n }\n}\n\nexport default pluginRspackEmpShare\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n"],"mappings":"AACA,OAAQ,0BAAAA,MAA6B,qCCD9B,IAAMC,EAAkB,oBCAxB,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GCG9E,IAAMC,EAAuBC,GAAO,CAClC,IAAMC,EAA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,gBAAgBH,CAAS,IACnH,CAAC,EAKCC,EAAc,CAChB,IAAMK,EAAMC,EAAcN,EAAcN,EAAM,IAAI,EAClDI,EAAW,KAAK,CACd,KAAM,KACN,MAAOO,CACT,CAAC,CACH,CACKJ,EAKIA,IAAe,kBACtBC,EAAgBE,EAGhBN,EAAW,KAAK,CAAC,KAAM,KAAM,MAAOG,CAAU,CAAC,EAP/CP,EAAM,MAAM,OAAO,4BAA4B,EAAE,IAAIa,EAAyB,CAACV,CAAU,CAAC,EASxFC,EAAW,OAAS,GACtBJ,EAAM,eAAeI,EAAY,UAAU,EAK7C,IAAMU,EAAkB,CACtB,6BAA8B,YAC9B,yBAA0B,OAC5B,EACMC,EAAY,CAAC,EACnB,OAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQH,CAAe,EACvDC,EAAUC,CAAG,EAAI,GAAGR,CAAa,IAAIS,CAAK,GAE5C,GAAIZ,IAAc,SAAWK,EAAiB,CAC5C,IAAMQ,EAAgB,CACpB,MAAO,QACP,YAAa,UACf,EACA,OAAW,CAACF,EAAKC,CAAK,IAAK,OAAO,QAAQC,CAAa,EACrDH,EAAUC,CAAG,EAAI,GAAGN,CAAe,IAAIO,CAAK,EAEhD,CACId,EAAW,cAAcA,EAAW,aAAaY,CAAS,EAG9Df,EAAM,MAAM,MAAM,CAAC,UAAAe,CAAS,CAAC,CAC/B,CACF,CACF,GAGKI,EAAQrB","names":["ModuleFederationPlugin","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","pluginRspackEmpShare","o","store","op","ModuleFederationPlugin","empRuntime","injectHtml","framework","frameworkLib","runtimeLib","runtimeGlobal","shareGlobalName","frameworkGlobal","url","getRuntimeLib","EmpShareRemoteLibPlugin","externalRuntime","externals","key","value","externalReact","rspack_default"]}
|
package/dist/runtime.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var r=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var R=(t,i)=>{for(var e in i)r(t,e,{get:i[e],enumerable:!0})},T=(t,i,e,o)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of y(i))!h.call(t,n)&&n!==e&&r(t,n,{get:()=>i[n],enumerable:!(o=b(i,n))||o.enumerable});return t};var d=t=>T(r({},"__esModule",{value:!0}),t);var M={};R(M,{EMPRuntime:()=>s,default:()=>f});module.exports=d(M);function l(t,...i){for(let e of i)for(let o in e){let n=e[o],p=t[o];if(Object(n)==n&&Object(p)===p){t[o]=l(p,n);continue}t[o]=e[o]}return t}var a="EMP_SHARE_RUNTIME";var u=window[a]||{},c=window,{EMPShareGlobalVal:m}=c||{};m&&m.runtimeLib&&(u=c[m.runtimeLib]);var s=class{libs=u;initOptions;options={showLog:!1};shareGlobalName=a;constructor(i){i&&this.setup(i)}setup(i){if(i&&(typeof i=="string"&&(i=window[i]),this.libs=i),!this.libs.MFRuntime||!this.libs.MFSDK)throw new Error("MFRuntime and MFSDK Required!")}init(i={}){let e={name:"empRuntimeProject",remotes:[]};e=l(e,i),this.libs.MFRuntime.init(e)}load(...i){return this.libs.MFRuntime.loadRemote(...i)}register=this.libs?.MFRuntime.registerRemotes;preload=this.libs?.MFRuntime.preloadRemote;loadShare=this.libs?.MFRuntime.loadShare},f=new s;0&&(module.exports={EMPRuntime});
|
|
2
2
|
//# sourceMappingURL=runtime.cjs.map
|
package/dist/runtime.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/runtime.ts","../src/helper/index.ts","../src/helper/config.ts"
|
|
1
|
+
{"version":3,"sources":["../src/runtime/index.ts","../src/helper/index.ts","../src/helper/config.ts"],"sourcesContent":["import {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport type {EMPShareRuntimeType, EmpRuntimeOptions, InitOptionsType, LoadRemoteType} from 'src/types'\ntype EmpInitOptionsType = Partial<InitOptionsType>\nlet globalLib = window[shareGlobalName] || {}\n// 根据 injectGlobalValToHtml 提前把库赋值到 EMPRuntime\nconst win: any = window\nconst {EMPShareGlobalVal} = win || {}\nif (EMPShareGlobalVal && EMPShareGlobalVal.runtimeLib) {\n globalLib = win[EMPShareGlobalVal.runtimeLib]\n}\n\nexport class EMPRuntime {\n public libs: EMPShareRuntimeType = globalLib\n public initOptions!: InitOptionsType\n public options: EmpRuntimeOptions = {\n showLog: false,\n }\n public shareGlobalName = shareGlobalName\n // private isInit = false\n constructor(op?: EMPShareRuntimeType) {\n if (op) this.setup(op)\n }\n /**\n * 实例化 adapter libs\n */\n public setup(o?: EMPShareRuntimeType | string) {\n if (o) {\n if (typeof o === 'string') o = window[o]\n this.libs = o as any\n }\n if (!this.libs.MFRuntime || !this.libs.MFSDK) {\n throw new Error('MFRuntime and MFSDK Required!')\n }\n }\n public init(options: EmpInitOptionsType = {}) {\n // if (this.isInit) return\n let op: InitOptionsType = {\n name: 'empRuntimeProject',\n remotes: [],\n // plugins: [catchErrorNextPlugin(this.options.showLog)],\n }\n op = deepAssign<InitOptionsType>(op, options)\n this.libs.MFRuntime.init(op)\n // this.isInit = true\n }\n public load<T = any>(...args: LoadRemoteType) {\n return this.libs.MFRuntime.loadRemote<T>(...args) as Promise<T>\n }\n public register = this.libs?.MFRuntime.registerRemotes\n public preload = this.libs?.MFRuntime.preloadRemote\n public loadShare = this.libs?.MFRuntime.loadShare\n}\n//\nexport default new EMPRuntime()\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GCEO,SAASK,EAAcC,KAAgBC,EAAiB,CAC7D,QAAWC,KAAUD,EACnB,QAAWE,KAAKD,EAAQ,CACtB,IAAME,EAAKF,EAAOC,CAAC,EACjBE,EAAKL,EAAOG,CAAC,EACf,GAAI,OAAOC,CAAE,GAAKA,GAAM,OAAOC,CAAE,IAAMA,EAAI,CACzCL,EAAOG,CAAC,EAAIJ,EAAWM,EAAID,CAAE,EAC7B,QACF,CACAJ,EAAOG,CAAC,EAAID,EAAOC,CAAC,CACtB,CAEF,OAAOH,CACT,CCfO,IAAMM,EAAkB,oBFI/B,IAAIC,EAAY,OAAOC,CAAe,GAAK,CAAC,EAEtCC,EAAW,OACX,CAAC,kBAAAC,CAAiB,EAAID,GAAO,CAAC,EAChCC,GAAqBA,EAAkB,aACzCH,EAAYE,EAAIC,EAAkB,UAAU,GAGvC,IAAMC,EAAN,KAAiB,CACf,KAA4BJ,EAC5B,YACA,QAA6B,CAClC,QAAS,EACX,EACO,gBAAkBC,EAEzB,YAAYI,EAA0B,CAChCA,GAAI,KAAK,MAAMA,CAAE,CACvB,CAIO,MAAMC,EAAkC,CAK7C,GAJIA,IACE,OAAOA,GAAM,WAAUA,EAAI,OAAOA,CAAC,GACvC,KAAK,KAAOA,GAEV,CAAC,KAAK,KAAK,WAAa,CAAC,KAAK,KAAK,MACrC,MAAM,IAAI,MAAM,+BAA+B,CAEnD,CACO,KAAKC,EAA8B,CAAC,EAAG,CAE5C,IAAIF,EAAsB,CACxB,KAAM,oBACN,QAAS,CAAC,CAEZ,EACAA,EAAKG,EAA4BH,EAAIE,CAAO,EAC5C,KAAK,KAAK,UAAU,KAAKF,CAAE,CAE7B,CACO,QAAiBI,EAAsB,CAC5C,OAAO,KAAK,KAAK,UAAU,WAAc,GAAGA,CAAI,CAClD,CACO,SAAW,KAAK,MAAM,UAAU,gBAChC,QAAU,KAAK,MAAM,UAAU,cAC/B,UAAY,KAAK,MAAM,UAAU,SAC1C,EAEOC,EAAQ,IAAIN","names":["runtime_exports","__export","EMPRuntime","runtime_default","__toCommonJS","deepAssign","target","sources","source","k","vs","vt","shareGlobalName","globalLib","shareGlobalName","win","EMPShareGlobalVal","EMPRuntime","op","o","options","deepAssign","args","runtime_default"]}
|
package/dist/runtime.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import * as MFRuntime from '@
|
|
2
|
-
import { E as EMPShareRuntimeType, I as InitOptionsType, a as EmpRuntimeOptions, L as LoadRemoteType } from './
|
|
3
|
-
export { _ as reactAdapter } from './react-BIjkQYoz.cjs';
|
|
1
|
+
import * as MFRuntime from '@module-federation/enhanced/runtime';
|
|
2
|
+
import { E as EMPShareRuntimeType, I as InitOptionsType, a as EmpRuntimeOptions, L as LoadRemoteType } from './index-CLt6ciOL.cjs';
|
|
4
3
|
import '@module-federation/sdk';
|
|
5
4
|
|
|
6
5
|
type EmpInitOptionsType = Partial<InitOptionsType>;
|
|
@@ -8,13 +7,12 @@ declare class EMPRuntime {
|
|
|
8
7
|
libs: EMPShareRuntimeType;
|
|
9
8
|
initOptions: InitOptionsType;
|
|
10
9
|
options: EmpRuntimeOptions;
|
|
11
|
-
|
|
10
|
+
shareGlobalName: string;
|
|
12
11
|
constructor(op?: EMPShareRuntimeType);
|
|
13
12
|
/**
|
|
14
13
|
* 实例化 adapter libs
|
|
15
|
-
* @param EMP_ADAPTER
|
|
16
14
|
*/
|
|
17
|
-
setup(o?: EMPShareRuntimeType): void;
|
|
15
|
+
setup(o?: EMPShareRuntimeType | string): void;
|
|
18
16
|
init(options?: EmpInitOptionsType): void;
|
|
19
17
|
load<T = any>(...args: LoadRemoteType): Promise<T>;
|
|
20
18
|
register: typeof MFRuntime.registerRemotes;
|
|
@@ -23,4 +21,4 @@ declare class EMPRuntime {
|
|
|
23
21
|
}
|
|
24
22
|
declare const _default: EMPRuntime;
|
|
25
23
|
|
|
26
|
-
export { _default as default };
|
|
24
|
+
export { EMPRuntime, _default as default };
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import * as MFRuntime from '@
|
|
2
|
-
import { E as EMPShareRuntimeType, I as InitOptionsType, a as EmpRuntimeOptions, L as LoadRemoteType } from './
|
|
3
|
-
export { _ as reactAdapter } from './react-BIjkQYoz.js';
|
|
1
|
+
import * as MFRuntime from '@module-federation/enhanced/runtime';
|
|
2
|
+
import { E as EMPShareRuntimeType, I as InitOptionsType, a as EmpRuntimeOptions, L as LoadRemoteType } from './index-CLt6ciOL.js';
|
|
4
3
|
import '@module-federation/sdk';
|
|
5
4
|
|
|
6
5
|
type EmpInitOptionsType = Partial<InitOptionsType>;
|
|
@@ -8,13 +7,12 @@ declare class EMPRuntime {
|
|
|
8
7
|
libs: EMPShareRuntimeType;
|
|
9
8
|
initOptions: InitOptionsType;
|
|
10
9
|
options: EmpRuntimeOptions;
|
|
11
|
-
|
|
10
|
+
shareGlobalName: string;
|
|
12
11
|
constructor(op?: EMPShareRuntimeType);
|
|
13
12
|
/**
|
|
14
13
|
* 实例化 adapter libs
|
|
15
|
-
* @param EMP_ADAPTER
|
|
16
14
|
*/
|
|
17
|
-
setup(o?: EMPShareRuntimeType): void;
|
|
15
|
+
setup(o?: EMPShareRuntimeType | string): void;
|
|
18
16
|
init(options?: EmpInitOptionsType): void;
|
|
19
17
|
load<T = any>(...args: LoadRemoteType): Promise<T>;
|
|
20
18
|
register: typeof MFRuntime.registerRemotes;
|
|
@@ -23,4 +21,4 @@ declare class EMPRuntime {
|
|
|
23
21
|
}
|
|
24
22
|
declare const _default: EMPRuntime;
|
|
25
23
|
|
|
26
|
-
export { _default as default };
|
|
24
|
+
export { EMPRuntime, _default as default };
|
package/dist/runtime.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function p(
|
|
1
|
+
function p(e,...i){for(let t of i)for(let n in t){let o=t[n],s=e[n];if(Object(o)==o&&Object(s)===s){e[n]=p(s,o);continue}e[n]=t[n]}return e}var r="EMP_SHARE_RUNTIME";var m=window[r]||{},u=window,{EMPShareGlobalVal:l}=u||{};l&&l.runtimeLib&&(m=u[l.runtimeLib]);var a=class{libs=m;initOptions;options={showLog:!1};shareGlobalName=r;constructor(i){i&&this.setup(i)}setup(i){if(i&&(typeof i=="string"&&(i=window[i]),this.libs=i),!this.libs.MFRuntime||!this.libs.MFSDK)throw new Error("MFRuntime and MFSDK Required!")}init(i={}){let t={name:"empRuntimeProject",remotes:[]};t=p(t,i),this.libs.MFRuntime.init(t)}load(...i){return this.libs.MFRuntime.loadRemote(...i)}register=this.libs?.MFRuntime.registerRemotes;preload=this.libs?.MFRuntime.preloadRemote;loadShare=this.libs?.MFRuntime.loadShare},R=new a;export{a as EMPRuntime,R as default};
|
|
2
2
|
//# sourceMappingURL=runtime.js.map
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/helper/index.ts","../src/helper/config.ts","../src/
|
|
1
|
+
{"version":3,"sources":["../src/helper/index.ts","../src/helper/config.ts","../src/runtime/index.ts"],"sourcesContent":["export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","import {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport type {EMPShareRuntimeType, EmpRuntimeOptions, InitOptionsType, LoadRemoteType} from 'src/types'\ntype EmpInitOptionsType = Partial<InitOptionsType>\nlet globalLib = window[shareGlobalName] || {}\n// 根据 injectGlobalValToHtml 提前把库赋值到 EMPRuntime\nconst win: any = window\nconst {EMPShareGlobalVal} = win || {}\nif (EMPShareGlobalVal && EMPShareGlobalVal.runtimeLib) {\n globalLib = win[EMPShareGlobalVal.runtimeLib]\n}\n\nexport class EMPRuntime {\n public libs: EMPShareRuntimeType = globalLib\n public initOptions!: InitOptionsType\n public options: EmpRuntimeOptions = {\n showLog: false,\n }\n public shareGlobalName = shareGlobalName\n // private isInit = false\n constructor(op?: EMPShareRuntimeType) {\n if (op) this.setup(op)\n }\n /**\n * 实例化 adapter libs\n */\n public setup(o?: EMPShareRuntimeType | string) {\n if (o) {\n if (typeof o === 'string') o = window[o]\n this.libs = o as any\n }\n if (!this.libs.MFRuntime || !this.libs.MFSDK) {\n throw new Error('MFRuntime and MFSDK Required!')\n }\n }\n public init(options: EmpInitOptionsType = {}) {\n // if (this.isInit) return\n let op: InitOptionsType = {\n name: 'empRuntimeProject',\n remotes: [],\n // plugins: [catchErrorNextPlugin(this.options.showLog)],\n }\n op = deepAssign<InitOptionsType>(op, options)\n this.libs.MFRuntime.init(op)\n // this.isInit = true\n }\n public load<T = any>(...args: LoadRemoteType) {\n return this.libs.MFRuntime.loadRemote<T>(...args) as Promise<T>\n }\n public register = this.libs?.MFRuntime.registerRemotes\n public preload = this.libs?.MFRuntime.preloadRemote\n public loadShare = this.libs?.MFRuntime.loadShare\n}\n//\nexport default new EMPRuntime()\n"],"mappings":"AAEO,SAASA,EAAcC,KAAgBC,EAAiB,CAC7D,QAAWC,KAAUD,EACnB,QAAWE,KAAKD,EAAQ,CACtB,IAAME,EAAKF,EAAOC,CAAC,EACjBE,EAAKL,EAAOG,CAAC,EACf,GAAI,OAAOC,CAAE,GAAKA,GAAM,OAAOC,CAAE,IAAMA,EAAI,CACzCL,EAAOG,CAAC,EAAIJ,EAAWM,EAAID,CAAE,EAC7B,QACF,CACAJ,EAAOG,CAAC,EAAID,EAAOC,CAAC,CACtB,CAEF,OAAOH,CACT,CCfO,IAAMM,EAAkB,oBCI/B,IAAIC,EAAY,OAAOC,CAAe,GAAK,CAAC,EAEtCC,EAAW,OACX,CAAC,kBAAAC,CAAiB,EAAID,GAAO,CAAC,EAChCC,GAAqBA,EAAkB,aACzCH,EAAYE,EAAIC,EAAkB,UAAU,GAGvC,IAAMC,EAAN,KAAiB,CACf,KAA4BJ,EAC5B,YACA,QAA6B,CAClC,QAAS,EACX,EACO,gBAAkBC,EAEzB,YAAYI,EAA0B,CAChCA,GAAI,KAAK,MAAMA,CAAE,CACvB,CAIO,MAAMC,EAAkC,CAK7C,GAJIA,IACE,OAAOA,GAAM,WAAUA,EAAI,OAAOA,CAAC,GACvC,KAAK,KAAOA,GAEV,CAAC,KAAK,KAAK,WAAa,CAAC,KAAK,KAAK,MACrC,MAAM,IAAI,MAAM,+BAA+B,CAEnD,CACO,KAAKC,EAA8B,CAAC,EAAG,CAE5C,IAAIF,EAAsB,CACxB,KAAM,oBACN,QAAS,CAAC,CAEZ,EACAA,EAAKG,EAA4BH,EAAIE,CAAO,EAC5C,KAAK,KAAK,UAAU,KAAKF,CAAE,CAE7B,CACO,QAAiBI,EAAsB,CAC5C,OAAO,KAAK,KAAK,UAAU,WAAc,GAAGA,CAAI,CAClD,CACO,SAAW,KAAK,MAAM,UAAU,gBAChC,QAAU,KAAK,MAAM,UAAU,cAC/B,UAAY,KAAK,MAAM,UAAU,SAC1C,EAEOC,EAAQ,IAAIN","names":["deepAssign","target","sources","source","k","vs","vt","shareGlobalName","globalLib","shareGlobalName","win","EMPShareGlobalVal","EMPRuntime","op","o","options","deepAssign","args","runtime_default"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empjs/share",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "emp share and runtime",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -91,9 +91,8 @@
|
|
|
91
91
|
},
|
|
92
92
|
"author": "Ken",
|
|
93
93
|
"dependencies": {
|
|
94
|
-
"@
|
|
95
|
-
"@module-federation/
|
|
96
|
-
"@module-federation/sdk": "0.6.1",
|
|
94
|
+
"@module-federation/enhanced": "0.6.3",
|
|
95
|
+
"@module-federation/sdk": "0.6.3",
|
|
97
96
|
"core-js": "^3.37.0"
|
|
98
97
|
},
|
|
99
98
|
"devDependencies": {
|
|
@@ -101,7 +100,7 @@
|
|
|
101
100
|
"@swc/core": "^1.4.14",
|
|
102
101
|
"tsup": "^8.2.3",
|
|
103
102
|
"typescript": "^5.5.4",
|
|
104
|
-
"@empjs/cli": "3.1.0-rc.
|
|
103
|
+
"@empjs/cli": "3.1.0-rc.11"
|
|
105
104
|
},
|
|
106
105
|
"scripts": {
|
|
107
106
|
"dev": "tsup --watch",
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import MFRuntime__default from '@empjs/module-federation-runtime';
|
|
2
|
-
import MFSDK from '@module-federation/sdk';
|
|
3
|
-
|
|
4
|
-
type EMPShareRuntimeType = {
|
|
5
|
-
MFRuntime: Required<typeof MFRuntime__default>;
|
|
6
|
-
MFSDK: Required<typeof MFSDK>;
|
|
7
|
-
};
|
|
8
|
-
type EMPShareRuntimeAdapterReactType = {
|
|
9
|
-
React?: any;
|
|
10
|
-
ReactDOM?: any;
|
|
11
|
-
createRoot?: any;
|
|
12
|
-
hydrateRoot?: any;
|
|
13
|
-
scope: string;
|
|
14
|
-
};
|
|
15
|
-
type InitOptionsType = Parameters<typeof MFRuntime__default.init>[0];
|
|
16
|
-
type LoadRemoteType = Parameters<typeof MFRuntime__default.loadRemote>;
|
|
17
|
-
type EmpRuntimeOptions = {
|
|
18
|
-
showLog?: boolean;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
declare class ReactAdapter {
|
|
22
|
-
libs: EMPShareRuntimeAdapterReactType;
|
|
23
|
-
constructor(op?: EMPShareRuntimeAdapterReactType);
|
|
24
|
-
setup(o?: EMPShareRuntimeAdapterReactType | string): void;
|
|
25
|
-
get shared(): InitOptionsType['shared'];
|
|
26
|
-
adapter<P = any>(component: any, scope?: string, React?: any, ReactDOM?: any): P;
|
|
27
|
-
}
|
|
28
|
-
declare const _default: ReactAdapter;
|
|
29
|
-
|
|
30
|
-
export { type EMPShareRuntimeType as E, type InitOptionsType as I, type LoadRemoteType as L, _default as _, type EmpRuntimeOptions as a };
|
package/dist/react-BIjkQYoz.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import MFRuntime__default from '@empjs/module-federation-runtime';
|
|
2
|
-
import MFSDK from '@module-federation/sdk';
|
|
3
|
-
|
|
4
|
-
type EMPShareRuntimeType = {
|
|
5
|
-
MFRuntime: Required<typeof MFRuntime__default>;
|
|
6
|
-
MFSDK: Required<typeof MFSDK>;
|
|
7
|
-
};
|
|
8
|
-
type EMPShareRuntimeAdapterReactType = {
|
|
9
|
-
React?: any;
|
|
10
|
-
ReactDOM?: any;
|
|
11
|
-
createRoot?: any;
|
|
12
|
-
hydrateRoot?: any;
|
|
13
|
-
scope: string;
|
|
14
|
-
};
|
|
15
|
-
type InitOptionsType = Parameters<typeof MFRuntime__default.init>[0];
|
|
16
|
-
type LoadRemoteType = Parameters<typeof MFRuntime__default.loadRemote>;
|
|
17
|
-
type EmpRuntimeOptions = {
|
|
18
|
-
showLog?: boolean;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
declare class ReactAdapter {
|
|
22
|
-
libs: EMPShareRuntimeAdapterReactType;
|
|
23
|
-
constructor(op?: EMPShareRuntimeAdapterReactType);
|
|
24
|
-
setup(o?: EMPShareRuntimeAdapterReactType | string): void;
|
|
25
|
-
get shared(): InitOptionsType['shared'];
|
|
26
|
-
adapter<P = any>(component: any, scope?: string, React?: any, ReactDOM?: any): P;
|
|
27
|
-
}
|
|
28
|
-
declare const _default: ReactAdapter;
|
|
29
|
-
|
|
30
|
-
export { type EMPShareRuntimeType as E, type InitOptionsType as I, type LoadRemoteType as L, _default as _, type EmpRuntimeOptions as a };
|