@empjs/share 0.0.2 → 3.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 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, { useEffect, useState, version } from "react";
41
- import ReactDOM from "react-dom";
42
- // 引用runtime
43
- import { empRuntime, withReactAdapter } from "@empjs/share/runtime";
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: "mfHost",
49
- entry: `http://localhost:8001/emp.js`,
50
+ name: 'mfHost',
51
+ entry,
50
52
  },
51
53
  ],
52
- name: "federationRuntimeDemo",
53
- });
54
+ name: 'federationRuntimeDemo',
55
+ })
54
56
  // 封装 React 18的组件 以便插入到 React 16
55
- const RemoteApp = empRuntime.react.adapter(empRuntime.load("mfHost/App"));
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
- <div
61
- style={{
62
- border: "1px solid #eee",
63
- padding: "10px",
64
- background: "#f7f7f7",
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 ParentComponentAdapter = empRuntime.react.adapter(
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>app React Version {version}</h1>
84
- <RemoteApp component={ParentComponentAdapter} />
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 p=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var P=(t,e)=>{for(var r in e)p(t,r,{get:e[r],enumerable:!0})},v=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of R(e))!g.call(t,i)&&i!==r&&p(t,i,{get:()=>e[i],enumerable:!(n=b(e,i))||n.enumerable});return t};var x=t=>v(p({},"__esModule",{value:!0}),t);var O={};P(O,{default:()=>C,reactAdapter:()=>h});module.exports=x(O);function u(t,...e){for(let r of e)for(let n in r){let i=r[n],o=t[n];if(Object(i)==i&&Object(o)===o){t[n]=u(o,i);continue}t[n]=r[n]}return t}var f=t=>t?Number(t.split(".")[0]):0,d=t=>t&&Object.prototype.toString.call(t)==="[object Promise]";var l=class{libs={scope:"default"};constructor(e){e&&this.setup(e)}setup(e){e&&(typeof e=="string"&&(e=window[e]),this.libs=u(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 o=f(n.version),m=this;class y extends n.Component{containerRef;root;constructor(a){super(a),this.containerRef=n.createRef()}componentDidMount(){this.mountOriginalComponent(!0)}componentDidUpdate(){this.mountOriginalComponent()}componentWillUnmount(){this.unMountOriginalComponent()}unMountOriginalComponent(){this.containerRef.current&&(o<18?i.unmountComponentAtNode(this.containerRef.current):this.root.unmount())}async mountOriginalComponent(a){d(e)&&(e=await e.then(s=>s[r]));let c=n.createElement(e,this.props);if(o<18)(a?i.render:i.hydrate)(c,this.containerRef.current);else if(a){let{createRoot:s}=m.libs;this.root=s(this.containerRef.current),this.root.render(c)}else{let{hydrateRoot:s}=m.libs;this.root=s(this.containerRef.current,c)}}render(){return n.createElement("div",{ref:this.containerRef})}}return y}},h=new l;var C=h;0&&(module.exports={reactAdapter});
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
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/adapter.ts","../src/helper/index.ts","../src/adapters/react.tsx"],"sourcesContent":["import reactAdapter from 'src/adapters/react'\n\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, deepAssign, isPromise} from 'src/helper'\nimport type {EMPShareRuntimeAdapterReactType, InitOptionsType} from 'src/types'\nexport class ReactAdapter {\n libs: EMPShareRuntimeAdapterReactType = {\n scope: 'default',\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 = deepAssign(this.libs, o)\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,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,CAEO,IAAMM,EAAgBC,GAAqBA,EAAU,OAAOA,EAAQ,MAAM,GAAG,EAAE,CAAC,CAAC,EAAI,EAC/EC,EAAaC,GAAWA,GAAK,OAAO,UAAU,SAAS,KAAKA,CAAC,IAAM,mBChBzE,IAAMC,EAAN,KAAmB,CACxB,KAAwC,CACtC,MAAO,SACT,EACA,YAAYC,EAAsC,CAC5CA,GAAI,KAAK,MAAMA,CAAE,CACvB,CACO,MAAMC,EAA8C,CACrDA,IACE,OAAOA,GAAM,WAAUA,EAAI,OAAOA,CAAC,GACvC,KAAK,KAAOC,EAAW,KAAK,KAAMD,CAAC,EAEvC,CACA,IAAI,QAAoC,CACtC,GAAM,CAAC,MAAAE,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,CAC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OO,CACT,CACF,EAEOQ,EAAQ,IAAInB,EFnGnB,IAAOoB,EAAQC","names":["adapter_exports","__export","adapter_default","react_default","__toCommonJS","deepAssign","target","sources","source","k","vs","vt","checkVersion","version","isPromise","p","ReactAdapter","op","o","deepAssign","React","ReactDOM","scope","component","reactVersion","checkVersion","self","WrappedComponent","props","shouldRender","isPromise","m","element","createRoot","hydrateRoot","react_default","adapter_default","react_default"]}
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,mBC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AAO,EAEzD,KAAK,KAAK,QAAQ,EAEtB,CACA,MAAM,uBAAuBQ,EAAwB,CAC/CC,EAAUP,CAAS,IACrBA,EAAY,MAAMA,EAAU,KAAMQ,GACzBA,EAAET,CAAK,CACf,GACH,IAAMU,EAAUZ,EAAM,cAAcG,EAAW,KAAK,KAAK,EACzD,GAAIC,EAAe,IACFK,EAAeR,EAAS,OAASA,EAAS,SAClDW,EAAS,KAAK,aAAa,OAAO,UAErCH,EAAc,CAChB,GAAM,CAAC,WAAAI,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,EF7GnB,IAAOmB,EAAQC","names":["adapter_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"]}
@@ -1,7 +1,14 @@
1
- import { _ as _default } from './react-BIjkQYoz.cjs';
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 { _ as _default } from './react-BIjkQYoz.js';
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
- function p(n,...e){for(let r of e)for(let t in r){let i=r[t],o=n[t];if(Object(i)==i&&Object(o)===o){n[t]=p(o,i);continue}n[t]=r[t]}return n}var h=n=>n?Number(n.split(".")[0]):0,m=n=>n&&Object.prototype.toString.call(n)==="[object Promise]";var u=class{libs={scope:"default"};constructor(e){e&&this.setup(e)}setup(e){e&&(typeof e=="string"&&(e=window[e]),this.libs=p(this.libs,e))}get shared(){let{React:e,ReactDOM:r,scope:t}=this.libs;return{react:{lib:()=>e,version:e.version,scope:t,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}},"react-dom":{lib:()=>r,version:r.version,scope:t,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}}}}adapter(e,r=this.libs.scope,t=this.libs.React,i=this.libs.ReactDOM){let o=h(t.version),l=this;class d extends t.Component{containerRef;root;constructor(a){super(a),this.containerRef=t.createRef()}componentDidMount(){this.mountOriginalComponent(!0)}componentDidUpdate(){this.mountOriginalComponent()}componentWillUnmount(){this.unMountOriginalComponent()}unMountOriginalComponent(){this.containerRef.current&&(o<18?i.unmountComponentAtNode(this.containerRef.current):this.root.unmount())}async mountOriginalComponent(a){m(e)&&(e=await e.then(s=>s[r]));let c=t.createElement(e,this.props);if(o<18)(a?i.render:i.hydrate)(c,this.containerRef.current);else if(a){let{createRoot:s}=l.libs;this.root=s(this.containerRef.current),this.root.render(c)}else{let{hydrateRoot:s}=l.libs;this.root=s(this.containerRef.current,c)}}render(){return t.createElement("div",{ref:this.containerRef})}}return d}},f=new u;var v=f;export{v as default,f as reactAdapter};
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
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/helper/index.ts","../src/adapters/react.tsx","../src/adapter.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, deepAssign, isPromise} from 'src/helper'\nimport type {EMPShareRuntimeAdapterReactType, InitOptionsType} from 'src/types'\nexport class ReactAdapter {\n libs: EMPShareRuntimeAdapterReactType = {\n scope: 'default',\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 = deepAssign(this.libs, o)\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/adapters/react'\n\nexport {reactAdapter}\nexport default reactAdapter\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,CAEO,IAAMM,EAAgBC,GAAqBA,EAAU,OAAOA,EAAQ,MAAM,GAAG,EAAE,CAAC,CAAC,EAAI,EAC/EC,EAAaC,GAAWA,GAAK,OAAO,UAAU,SAAS,KAAKA,CAAC,IAAM,mBChBzE,IAAMC,EAAN,KAAmB,CACxB,KAAwC,CACtC,MAA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,EAAe,IACFK,EAAeR,EAAS,OAASA,EAAS,SAClDW,EAAS,KAAK,aAAa,OAAO,UAErCH,EAAc,CAChB,GAAM,CAAC,WAAAI,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,IAAInB,ECnGnB,IAAOoB,EAAQC","names":["deepAssign","target","sources","source","k","vs","vt","checkVersion","version","isPromise","p","ReactAdapter","op","o","deepAssign","React","ReactDOM","scope","component","reactVersion","checkVersion","self","WrappedComponent","props","shouldRender","isPromise","m","element","createRoot","hydrateRoot","react_default","adapter_default","react_default"]}
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,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,YAAa,CACX,UAAW,GACX,gBAAiB,IAAIF,EAAM,OAAO,EACpC,CACF,CACF,CACF,CACA,QACEG,EACAD,EAAgB,KAAK,KAAK,MAC1BF,EAAa,KAAK,KAAK,MACvBC,EAAgB,KAAK,KAAK,SACvB,CACH,IAAMG,EAAeC,EAAaL,EAAM,OAAO,EACzCM,EAAO,KACb,MAAMC,UAAyBP,EAAM,SAAU,CACtC,aACA,KACP,YAAYQ,EAAU,CACpB,MAAMA,CAAY,EAClB,KAAK,aAAeR,EAAM,UAAU,CACtC,CAEA,mBAAoB,CAClB,KAAK,uBAAuB,EAAI,CAClC,CAEA,oBAAqB,CACnB,KAAK,uBAAuB,CAC9B,CAEA,sBAAuB,CACrB,KAAK,yBAAyB,CAChC,CACA,0BAA2B,CACpB,KAAK,aAAa,UACnBI,EAAe,GACjBH,EAAS,uBAAuB,KAAK,aAAa,OAAO,EAEzD,KAAK,KAAK,QAAQ,EAEtB,CACA,MAAM,uBAAuBQ,EAAwB,CAC/CC,EAAUP,CAAS,IACrBA,EAAY,MAAMA,EAAU,KAAMQ,GACzBA,EAAET,CAAK,CACf,GACH,IAAMU,EAAUZ,EAAM,cAAcG,EAAW,KAAK,KAAK,EACzD,GAAIC,EAAe,IACFK,EAAeR,EAAS,OAASA,EAAS,SAClDW,EAAS,KAAK,aAAa,OAAO,UAErCH,EAAc,CAChB,GAAM,CAAC,WAAAI,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 l=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var g=(r,e)=>{for(var t in e)l(r,t,{get:e[t],enumerable:!0})},x=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of R(e))!E.call(r,n)&&n!==t&&l(r,n,{get:()=>e[n],enumerable:!(o=y(e,n))||o.enumerable});return r};var k=r=>x(l({},"__esModule",{value:!0}),r);var P={};g(P,{default:()=>h,pluginRspackEmpShare:()=>s});module.exports=k(P);var b=require("@module-federation/enhanced/rspack");var u="EMP_SHARE_RUNTIME";var c=r=>`data:text/javascript,${r}`;var j=r=>{let e=[`import '${r}'`].join(`
2
- `);return c(e)},a=class{options;constructor(e){this.options=e}apply(e){let{webpack:t}=e,{runtimeLib:o}=this.options;if(!o){let n=j("@empjs/share/library");new t.EntryPlugin(e.context,n,{name:void 0}).apply(e)}}};function f(r,e){return typeof r=="string"?`${r}/runtime${e==="development"?".development":""}.umd.js`:typeof r=="object"?e==="development"?r.dev:r.prod:""}var s=(r={})=>({name:"@empjs/share",async rsConfig(e){if(r.name){let o=e.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},r);delete o.empRuntime,e.chain.plugin("plugin-emp-share").use(b.ModuleFederationPlugin,[o])}let{empRuntime:t}=r;if(t){t.runtimeLib||e.chain.plugin("plugin-emp-share-framework").use(a,[t]),t.runtimeGlobal=t.runtimeGlobal||u;let o={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},n=[];for(let[i,p]of Object.entries(o))n[i]=`${t.runtimeGlobal}.${p}`;let m=[];if(t.frameworkLib){let i=f(t.frameworkLib,e.mode);m.push(i)}if(t.runtimeLib&&m.push(t.runtimeLib),m.length>0&&e.injectHeadTags({js:m},"EMPShare"),t.framework=t.framework||"react",t.frameworkGlobal=t.frameworkGlobal||t.runtimeGlobal,t.framework==="react"){let i={react:"React","react-dom":"ReactDOM"};for(let[p,d]of Object.entries(i))n[p]=`${t.frameworkGlobal}.${d}`}t.setExternals&&t.setExternals(n),e.chain.externals(n)}}});var h=s;0&&(module.exports={pluginRspackEmpShare});
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
@@ -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":["// export {default as runtime} from './mfRuntime'\nimport {default as pluginRspackEmpShare} from './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 default (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n // console.log(o)\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 if (!empRuntime.runtimeLib) {\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n //\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\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] = `${empRuntime.runtimeGlobal}.${value}`\n }\n // injectHeadTags\n const injectUrl: string[] = []\n if (empRuntime.frameworkLib) {\n const url = getRuntimeLib(empRuntime.frameworkLib, store.mode)\n injectUrl.push(url)\n }\n if (empRuntime.runtimeLib) {\n injectUrl.push(empRuntime.runtimeLib)\n }\n if (injectUrl.length > 0) {\n store.injectHeadTags({js: injectUrl}, 'EMPShare')\n }\n //\n empRuntime.framework = empRuntime.framework || 'react'\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || empRuntime.runtimeGlobal\n if (empRuntime.framework === 'react') {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${empRuntime.frameworkGlobal}.${value}`\n }\n }\n //\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n\n store.chain.externals(externals)\n }\n },\n }\n}\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,CJDA,IAAOE,EAAQ,CAACC,EAAwB,CAAC,KAChC,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAEjC,GAAID,EAAE,KAAM,CACV,IAAME,EAAUD,EAAM,WACpB,CACE,SAAU,SACV,SAAU,GACV,IAAK,GACL,IAAK,CACH,8BAA+B,EACjC,CACF,EACAD,CACF,EACA,OAAOE,EAAG,WACVD,EAAM,MAAM,OAAO,kBAAkB,EAAE,IAAI,yBAAwB,CAACC,CAAE,CAAC,CACzE,CACA,GAAM,CAAC,WAAAC,CAAU,EAAIH,EACrB,GAAIG,EAAY,CACTA,EAAW,YACdF,EAAM,MAAM,OAAO,4BAA4B,EAAE,IAAIG,EAAyB,CAACD,CAAU,CAAC,EAG5FA,EAAW,cAAgBA,EAAW,eAAiBE,EACvD,IAAMC,EAAkB,CACtB,6BAA8B,YAC9B,yBAA0B,OAC5B,EACMC,EAAY,CAAC,EACnB,OAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQH,CAAe,EACvDC,EAAUC,CAAG,EAAI,GAAGL,EAAW,aAAa,IAAIM,CAAK,GAGvD,IAAMC,EAAsB,CAAC,EAC7B,GAAIP,EAAW,aAAc,CAC3B,IAAMQ,EAAMC,EAAcT,EAAW,aAAcF,EAAM,IAAI,EAC7DS,EAAU,KAAKC,CAAG,CACpB,CAUA,GATIR,EAAW,YACbO,EAAU,KAAKP,EAAW,UAAU,EAElCO,EAAU,OAAS,GACrBT,EAAM,eAAe,CAAC,GAAIS,CAAS,EAAG,UAAU,EAGlDP,EAAW,UAAYA,EAAW,WAAa,QAC/CA,EAAW,gBAAkBA,EAAW,iBAAmBA,EAAW,cAClEA,EAAW,YAAc,QAAS,CACpC,IAAMU,EAAgB,CACpB,MAAO,QACP,YAAa,UACf,EACA,OAAW,CAACL,EAAKC,CAAK,IAAK,OAAO,QAAQI,CAAa,EACrDN,EAAUC,CAAG,EAAI,GAAGL,EAAW,eAAe,IAAIM,CAAK,EAE3D,CAEIN,EAAW,cAAcA,EAAW,aAAaI,CAAS,EAE9DN,EAAM,MAAM,UAAUM,CAAS,CACjC,CACF,CACF,GDtEF,IAAOO,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","rspack_default","o","store","op","empRuntime","EmpShareRemoteLibPlugin","shareGlobalName","externalRuntime","externals","key","value","injectUrl","url","getRuntimeLib","externalReact","src_default","rspack_default"]}
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,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KC,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,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 _default from './rspack.cjs';
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 { _default as default, _default as pluginRspackEmpShare };
7
+ export { pluginRspackEmpShare as default, pluginRspackEmpShare };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import _default from './rspack.js';
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 { _default as default, _default as pluginRspackEmpShare };
7
+ export { pluginRspackEmpShare as default, pluginRspackEmpShare };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import{ModuleFederationPlugin as d}from"@module-federation/enhanced/rspack";var l="EMP_SHARE_RUNTIME";var u=r=>`data:text/javascript,${r}`;var b=r=>{let t=[`import '${r}'`].join(`
2
- `);return u(t)},a=class{options;constructor(t){this.options=t}apply(t){let{webpack:e}=t,{runtimeLib:n}=this.options;if(!n){let o=b("@empjs/share/library");new e.EntryPlugin(t.context,o,{name:void 0}).apply(t)}}};function c(r,t){return typeof r=="string"?`${r}/runtime${t==="development"?".development":""}.umd.js`:typeof r=="object"?t==="development"?r.dev:r.prod:""}var p=(r={})=>({name:"@empjs/share",async rsConfig(t){if(r.name){let n=t.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},r);delete n.empRuntime,t.chain.plugin("plugin-emp-share").use(d,[n])}let{empRuntime:e}=r;if(e){e.runtimeLib||t.chain.plugin("plugin-emp-share-framework").use(a,[e]),e.runtimeGlobal=e.runtimeGlobal||l;let n={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},o=[];for(let[i,s]of Object.entries(n))o[i]=`${e.runtimeGlobal}.${s}`;let m=[];if(e.frameworkLib){let i=c(e.frameworkLib,t.mode);m.push(i)}if(e.runtimeLib&&m.push(e.runtimeLib),m.length>0&&t.injectHeadTags({js:m},"EMPShare"),e.framework=e.framework||"react",e.frameworkGlobal=e.frameworkGlobal||e.runtimeGlobal,e.framework==="react"){let i={react:"React","react-dom":"ReactDOM"};for(let[s,f]of Object.entries(i))o[s]=`${e.frameworkGlobal}.${f}`}e.setExternals&&e.setExternals(o),t.chain.externals(o)}}});var O=p;export{O as default,p as pluginRspackEmpShare};
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 default (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n // console.log(o)\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 if (!empRuntime.runtimeLib) {\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n //\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\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] = `${empRuntime.runtimeGlobal}.${value}`\n }\n // injectHeadTags\n const injectUrl: string[] = []\n if (empRuntime.frameworkLib) {\n const url = getRuntimeLib(empRuntime.frameworkLib, store.mode)\n injectUrl.push(url)\n }\n if (empRuntime.runtimeLib) {\n injectUrl.push(empRuntime.runtimeLib)\n }\n if (injectUrl.length > 0) {\n store.injectHeadTags({js: injectUrl}, 'EMPShare')\n }\n //\n empRuntime.framework = empRuntime.framework || 'react'\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || empRuntime.runtimeGlobal\n if (empRuntime.framework === 'react') {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${empRuntime.frameworkGlobal}.${value}`\n }\n }\n //\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n\n store.chain.externals(externals)\n }\n },\n }\n}\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","// export {default as runtime} from './mfRuntime'\nimport {default as pluginRspackEmpShare} from './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,E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BA,EAAW,cAClEA,EAAW,YAAc,QAAS,CACpC,IAAMU,EAAgB,CACpB,MAAO,QACP,YAAa,UACf,EACA,OAAW,CAACL,EAAKC,CAAK,IAAK,OAAO,QAAQI,CAAa,EACrDN,EAAUC,CAAG,EAAI,GAAGL,EAAW,eAAe,IAAIM,CAAK,EAE3D,CAEIN,EAAW,cAAcA,EAAW,aAAaI,CAAS,EAE9DP,EAAM,MAAM,UAAUO,CAAS,CACjC,CACF,CACF,GKtEF,IAAOO,EAAQC","names":["ModuleFederationPlugin","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","rspack_default","o","store","op","ModuleFederationPlugin","empRuntime","EmpShareRemoteLibPlugin","shareGlobalName","externalRuntime","externals","key","value","injectUrl","url","getRuntimeLib","externalReact","src_default","rspack_default"]}
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,EAA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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,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 p=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var g=(n,e)=>{for(var t in e)p(n,t,{get:e[t],enumerable:!0})},j=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of R(e))!E.call(n,r)&&r!==t&&p(n,r,{get:()=>e[r],enumerable:!(o=d(e,r))||o.enumerable});return n};var k=n=>j(p({},"__esModule",{value:!0}),n);var h={};g(h,{default:()=>b});module.exports=k(h);var f=require("@module-federation/enhanced/rspack");var l="EMP_SHARE_RUNTIME";var u=n=>`data:text/javascript,${n}`;var x=n=>{let e=[`import '${n}'`].join(`
2
- `);return u(e)},s=class{options;constructor(e){this.options=e}apply(e){let{webpack:t}=e,{runtimeLib:o}=this.options;if(!o){let r=x("@empjs/share/library");new t.EntryPlugin(e.context,r,{name:void 0}).apply(e)}}};function c(n,e){return typeof n=="string"?`${n}/runtime${e==="development"?".development":""}.umd.js`:typeof n=="object"?e==="development"?n.dev:n.prod:""}var b=(n={})=>({name:"@empjs/share",async rsConfig(e){if(n.name){let o=e.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},n);delete o.empRuntime,e.chain.plugin("plugin-emp-share").use(f.ModuleFederationPlugin,[o])}let{empRuntime:t}=n;if(t){t.runtimeLib||e.chain.plugin("plugin-emp-share-framework").use(s,[t]),t.runtimeGlobal=t.runtimeGlobal||l;let o={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},r=[];for(let[i,a]of Object.entries(o))r[i]=`${t.runtimeGlobal}.${a}`;let m=[];if(t.frameworkLib){let i=c(t.frameworkLib,e.mode);m.push(i)}if(t.runtimeLib&&m.push(t.runtimeLib),m.length>0&&e.injectHeadTags({js:m},"EMPShare"),t.framework=t.framework||"react",t.frameworkGlobal=t.frameworkGlobal||t.runtimeGlobal,t.framework==="react"){let i={react:"React","react-dom":"ReactDOM"};for(let[a,y]of Object.entries(i))r[a]=`${t.frameworkGlobal}.${y}`}t.setExternals&&t.setExternals(r),e.chain.externals(r)}}});
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
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/rspack.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 {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\n// export type ModuleFederationPluginOptions = ConstructorParameters<typeof ModuleFederationPlugin>[0]\n// export {ModuleFederationPlugin}\nexport {default} from './plugins/rspack'\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 default (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n // console.log(o)\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 if (!empRuntime.runtimeLib) {\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n //\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\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] = `${empRuntime.runtimeGlobal}.${value}`\n }\n // injectHeadTags\n const injectUrl: string[] = []\n if (empRuntime.frameworkLib) {\n const url = getRuntimeLib(empRuntime.frameworkLib, store.mode)\n injectUrl.push(url)\n }\n if (empRuntime.runtimeLib) {\n injectUrl.push(empRuntime.runtimeLib)\n }\n if (injectUrl.length > 0) {\n store.injectHeadTags({js: injectUrl}, 'EMPShare')\n }\n //\n empRuntime.framework = empRuntime.framework || 'react'\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || empRuntime.runtimeGlobal\n if (empRuntime.framework === 'react') {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${empRuntime.frameworkGlobal}.${value}`\n }\n }\n //\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n\n store.chain.externals(externals)\n }\n },\n }\n}\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,IAAA,eAAAC,EAAAH,GCCA,IAAAI,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,CJDA,IAAOE,EAAQ,CAACC,EAAwB,CAAC,KAChC,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAEjC,GAAID,EAAE,KAAM,CACV,IAAME,EAAUD,EAAM,WACpB,CACE,SAAU,SACV,SAAU,GACV,IAAK,GACL,IAAK,CACH,8BAA+B,EACjC,CACF,EACAD,CACF,EACA,OAAOE,EAAG,WACVD,EAAM,MAAM,OAAO,kBAAkB,EAAE,IAAI,yBAAwB,CAACC,CAAE,CAAC,CACzE,CACA,GAAM,CAAC,WAAAC,CAAU,EAAIH,EACrB,GAAIG,EAAY,CACTA,EAAW,YACdF,EAAM,MAAM,OAAO,4BAA4B,EAAE,IAAIG,EAAyB,CAACD,CAAU,CAAC,EAG5FA,EAAW,cAAgBA,EAAW,eAAiBE,EACvD,IAAMC,EAAkB,CACtB,6BAA8B,YAC9B,yBAA0B,OAC5B,EACMC,EAAY,CAAC,EACnB,OAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQH,CAAe,EACvDC,EAAUC,CAAG,EAAI,GAAGL,EAAW,aAAa,IAAIM,CAAK,GAGvD,IAAMC,EAAsB,CAAC,EAC7B,GAAIP,EAAW,aAAc,CAC3B,IAAMQ,EAAMC,EAAcT,EAAW,aAAcF,EAAM,IAAI,EAC7DS,EAAU,KAAKC,CAAG,CACpB,CAUA,GATIR,EAAW,YACbO,EAAU,KAAKP,EAAW,UAAU,EAElCO,EAAU,OAAS,GACrBT,EAAM,eAAe,CAAC,GAAIS,CAAS,EAAG,UAAU,EAGlDP,EAAW,UAAYA,EAAW,WAAa,QAC/CA,EAAW,gBAAkBA,EAAW,iBAAmBA,EAAW,cAClEA,EAAW,YAAc,QAAS,CACpC,IAAMU,EAAgB,CACpB,MAAO,QACP,YAAa,UACf,EACA,OAAW,CAACL,EAAKC,CAAK,IAAK,OAAO,QAAQI,CAAa,EACrDN,EAAUC,CAAG,EAAI,GAAGL,EAAW,eAAe,IAAIM,CAAK,EAE3D,CAEIN,EAAW,cAAcA,EAAW,aAAaI,CAAS,EAE9DN,EAAM,MAAM,UAAUM,CAAS,CACjC,CACF,CACF","names":["rspack_exports","__export","rspack_default","__toCommonJS","import_rspack","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","rspack_default","o","store","op","empRuntime","EmpShareRemoteLibPlugin","shareGlobalName","externalRuntime","externals","key","value","injectUrl","url","getRuntimeLib","externalReact"]}
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,aAAAE,EAAA,yBAAAC,IAAA,eAAAC,EAAAJ,GACA,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,CACE,SAAU,SACV,SAAU,GACV,IAAK,GAC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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?: string;
30
+ framework?: 'react' | 'vue2' | 'vue';
30
31
  };
31
32
  type EMPPluginShareType = ModuleFederationPluginOptions & {
32
33
  empRuntime?: EMPSHARERuntimeOptions;
33
34
  };
34
35
 
35
- declare const _default: (o?: EMPPluginShareType) => {
36
+ declare const pluginRspackEmpShare: (o?: EMPPluginShareType) => {
36
37
  name: string;
37
38
  rsConfig(store: GlobalStore): Promise<void>;
38
39
  };
39
40
 
40
- export { _default as default };
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?: string;
30
+ framework?: 'react' | 'vue2' | 'vue';
30
31
  };
31
32
  type EMPPluginShareType = ModuleFederationPluginOptions & {
32
33
  empRuntime?: EMPSHARERuntimeOptions;
33
34
  };
34
35
 
35
- declare const _default: (o?: EMPPluginShareType) => {
36
+ declare const pluginRspackEmpShare: (o?: EMPPluginShareType) => {
36
37
  name: string;
37
38
  rsConfig(store: GlobalStore): Promise<void>;
38
39
  };
39
40
 
40
- export { _default as default };
41
+ export { pluginRspackEmpShare as default, pluginRspackEmpShare };
package/dist/rspack.js CHANGED
@@ -1,3 +1,3 @@
1
- import{ModuleFederationPlugin as b}from"@module-federation/enhanced/rspack";var p="EMP_SHARE_RUNTIME";var l=n=>`data:text/javascript,${n}`;var f=n=>{let t=[`import '${n}'`].join(`
2
- `);return l(t)},s=class{options;constructor(t){this.options=t}apply(t){let{webpack:e}=t,{runtimeLib:r}=this.options;if(!r){let o=f("@empjs/share/library");new e.EntryPlugin(t.context,o,{name:void 0}).apply(t)}}};function u(n,t){return typeof n=="string"?`${n}/runtime${t==="development"?".development":""}.umd.js`:typeof n=="object"?t==="development"?n.dev:n.prod:""}var y=(n={})=>({name:"@empjs/share",async rsConfig(t){if(n.name){let r=t.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},n);delete r.empRuntime,t.chain.plugin("plugin-emp-share").use(b,[r])}let{empRuntime:e}=n;if(e){e.runtimeLib||t.chain.plugin("plugin-emp-share-framework").use(s,[e]),e.runtimeGlobal=e.runtimeGlobal||p;let r={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},o=[];for(let[i,a]of Object.entries(r))o[i]=`${e.runtimeGlobal}.${a}`;let m=[];if(e.frameworkLib){let i=u(e.frameworkLib,t.mode);m.push(i)}if(e.runtimeLib&&m.push(e.runtimeLib),m.length>0&&t.injectHeadTags({js:m},"EMPShare"),e.framework=e.framework||"react",e.frameworkGlobal=e.frameworkGlobal||e.runtimeGlobal,e.framework==="react"){let i={react:"React","react-dom":"ReactDOM"};for(let[a,c]of Object.entries(i))o[a]=`${e.frameworkGlobal}.${c}`}e.setExternals&&e.setExternals(o),t.chain.externals(o)}}});export{y as default};
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
@@ -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 default (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n // console.log(o)\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 if (!empRuntime.runtimeLib) {\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n //\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\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] = `${empRuntime.runtimeGlobal}.${value}`\n }\n // injectHeadTags\n const injectUrl: string[] = []\n if (empRuntime.frameworkLib) {\n const url = getRuntimeLib(empRuntime.frameworkLib, store.mode)\n injectUrl.push(url)\n }\n if (empRuntime.runtimeLib) {\n injectUrl.push(empRuntime.runtimeLib)\n }\n if (injectUrl.length > 0) {\n store.injectHeadTags({js: injectUrl}, 'EMPShare')\n }\n //\n empRuntime.framework = empRuntime.framework || 'react'\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || empRuntime.runtimeGlobal\n if (empRuntime.framework === 'react') {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${empRuntime.frameworkGlobal}.${value}`\n }\n }\n //\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n\n store.chain.externals(externals)\n }\n },\n }\n}\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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E,EACvD,IAAMC,EAAkB,CACtB,6BAA8B,YAC9B,yBAA0B,OAC5B,EACMC,EAAY,CAAC,EACnB,OAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQH,CAAe,EACvDC,EAAUC,CAAG,EAAI,GAAGL,EAAW,aAAa,IAAIM,CAAK,GAGvD,IAAMC,EAAsB,CAAC,EAC7B,GAAIP,EAAW,aAAc,CAC3B,IAAMQ,EAAMC,EAAcT,EAAW,aAAcH,EAAM,IAAI,EAC7DU,EAAU,KAAKC,CAAG,CACpB,CAUA,GATIR,EAAW,YACbO,EAAU,KAAKP,EAAW,UAAU,EAElCO,EAAU,OAAS,GACrBV,EAAM,eAAe,CAAC,GAAIU,CAAS,EAAG,UAAU,EAGlDP,EAAW,UAAYA,EAAW,WAAa,QAC/CA,EAAW,gBAAkBA,EAAW,iBAAmBA,EAAW,cAClEA,EAAW,YAAc,QAAS,CACpC,IAAMU,EAAgB,CACpB,MAAO,QACP,YAAa,UACf,EACA,OAAW,CAACL,EAAKC,CAAK,IAAK,OAAO,QAAQI,CAAa,EACrDN,EAAUC,CAAG,EAAI,GAAGL,EAAW,eAAe,IAAIM,CAAK,EAE3D,CAEIN,EAAW,cAAcA,EAAW,aAAaI,CAAS,EAE9DP,EAAM,MAAM,UAAUO,CAAS,CACjC,CACF,CACF","names":["ModuleFederationPlugin","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","rspack_default","o","store","op","ModuleFederationPlugin","empRuntime","EmpShareRemoteLibPlugin","shareGlobalName","externalRuntime","externals","key","value","injectUrl","url","getRuntimeLib","externalReact"]}
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,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,CACE,SAAU,SACV,SAAU,GACV,IAAK,GACL,IAAK,CACH,8BAA+B,EACjC,CACF,EACAD,CACF,EACA,OAAOE,EAAG,WACVD,EAAM,MAAM,OAAO,kBAAkB,EAAE,IAAIE,EAAwB,CAACD,CAAE,CAAC,CACzE,CACA,GAAM,CAAC,WAAAE,CAAU,EAAIJ,EACrB,GAAII,EAAY,CACd,IAAMC,EAAoB,CAAC,EACrBC,EAAYF,EAAW,WAAa,QACpC,CAAC,aAAAG,EAAc,WAAAC,CAAU,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,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 c=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var E=(t,e)=>{for(var i in e)c(t,i,{get:e[i],enumerable:!0})},x=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of P(e))!O.call(t,r)&&r!==i&&c(t,r,{get:()=>e[r],enumerable:!(n=M(e,r))||n.enumerable});return t};var S=t=>x(c({},"__esModule",{value:!0}),t);var I={};E(I,{default:()=>R,reactAdapter:()=>g});module.exports=S(I);function p(t,...e){for(let i of e)for(let n in i){let r=i[n],o=t[n];if(Object(r)==r&&Object(o)===o){t[n]=p(o,r);continue}t[n]=i[n]}return t}var f=t=>t?Number(t.split(".")[0]):0,d=t=>t&&Object.prototype.toString.call(t)==="[object Promise]";var y="EMP_SHARE_RUNTIME";var b=function(t=!1){return{name:"catch-error-next-plugin",errorLoadRemote(e){return t&&(console.log("[@emp/share]",e.id,e.lifecycle,e.from),console.error("[@emp/share]",e.error)),{}}}};var l=class{libs=p({},window[y]||{});initOptions;options={showLog:!1};isInit=!1;constructor(e){e&&this.setup(e)}setup(e){if(e&&(this.libs=e),!this.libs.MFRuntime||!this.libs.MFSDK)throw new Error("MFRuntime and MFSDK Required!")}init(e={}){if(this.isInit)return;let i={name:"empAdepterProject",remotes:[],plugins:[b(this.options.showLog)]};i=p(i,e),this.libs.MFRuntime.init(i),this.isInit=!0}load(...e){return this.libs.MFRuntime.loadRemote(...e)}register=this.libs.MFRuntime.registerRemotes;preload=this.libs.MFRuntime.preloadRemote;loadShare=this.libs.MFRuntime.loadShare},R=new l;var m=class{libs={scope:"default"};constructor(e){e&&this.setup(e)}setup(e){e&&(typeof e=="string"&&(e=window[e]),this.libs=p(this.libs,e))}get shared(){let{React:e,ReactDOM:i,scope:n}=this.libs;return{react:{lib:()=>e,version:e.version,scope:n,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}},"react-dom":{lib:()=>i,version:i.version,scope:n,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}}}}adapter(e,i=this.libs.scope,n=this.libs.React,r=this.libs.ReactDOM){let o=f(n.version),h=this;class T extends n.Component{containerRef;root;constructor(a){super(a),this.containerRef=n.createRef()}componentDidMount(){this.mountOriginalComponent(!0)}componentDidUpdate(){this.mountOriginalComponent()}componentWillUnmount(){this.unMountOriginalComponent()}unMountOriginalComponent(){this.containerRef.current&&(o<18?r.unmountComponentAtNode(this.containerRef.current):this.root.unmount())}async mountOriginalComponent(a){d(e)&&(e=await e.then(s=>s[i]));let u=n.createElement(e,this.props);if(o<18)(a?r.render:r.hydrate)(u,this.containerRef.current);else if(a){let{createRoot:s}=h.libs;this.root=s(this.containerRef.current),this.root.render(u)}else{let{hydrateRoot:s}=h.libs;this.root=s(this.containerRef.current,u)}}render(){return n.createElement("div",{ref:this.containerRef})}}return T}},g=new m;0&&(module.exports={reactAdapter});
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
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/runtime.ts","../src/helper/index.ts","../src/helper/config.ts","../src/runtimes/plugins.ts","../src/runtimes/index.ts","../src/adapters/react.tsx"],"sourcesContent":["export {default} from './runtimes'\nimport reactAdapter from './adapters/react'\nexport {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","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","import type {FederationRuntimePlugin} from '@module-federation/runtime'\nexport const catchErrorNextPlugin: (showLog?: boolean) => FederationRuntimePlugin = function (showLog = false) {\n return {\n name: 'catch-error-next-plugin',\n errorLoadRemote(o) {\n if (showLog) {\n console.log('[@emp/share]', o.id, o.lifecycle, o.from)\n console.error('[@emp/share]', o.error)\n }\n return {}\n },\n }\n}\n","import {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport type {EMPShareRuntimeType, EmpRuntimeOptions, InitOptionsType, LoadRemoteType} from 'src/types'\nimport {catchErrorNextPlugin} from './plugins'\ntype EmpInitOptionsType = Partial<InitOptionsType>\nexport class EMPRuntime {\n public libs: EMPShareRuntimeType = deepAssign({}, window[shareGlobalName] || {})\n public initOptions!: InitOptionsType\n public options: EmpRuntimeOptions = {\n showLog: false,\n }\n private isInit = false\n constructor(op?: EMPShareRuntimeType) {\n if (op) this.setup(op)\n }\n /**\n * 实例化 adapter libs\n * @param EMP_ADAPTER\n */\n public setup(o?: EMPShareRuntimeType) {\n if (o) {\n this.libs = o\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: 'empAdepterProject',\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","import {checkVersion, deepAssign, isPromise} from 'src/helper'\nimport type {EMPShareRuntimeAdapterReactType, InitOptionsType} from 'src/types'\nexport class ReactAdapter {\n libs: EMPShareRuntimeAdapterReactType = {\n scope: 'default',\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 = deepAssign(this.libs, o)\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,GCEO,SAASK,EAAcC,KAAgBC,EAAiB,CAC7D,QAAWC,KAAUD,EACnB,QAAWE,KAAKD,EAAQ,CACtB,IAAME,EAAKF,EAAOC,CAAC,EACjBE,EAAKL,EAAOG,CAAC,EACf,GAAI,OA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AK,KAAK,QAAQ,EAEtB,CACA,MAAM,uBAAuBQ,EAAwB,CAC/CC,EAAUP,CAAS,IACrBA,EAAY,MAAMA,EAAU,KAAMQ,GACzBA,EAAET,CAAK,CACf,GACH,IAAMU,EAAUZ,EAAM,cAAcG,EAAW,KAAK,KAAK,EACzD,GAAIC,EAAe,IACFK,EAAeR,EAAS,OAASA,EAAS,SAClDW,EAAS,KAAK,aAAa,OAAO,UAErCH,EAAc,CAChB,GAAM,CAAC,WAAAI,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,IAAInB","names":["runtime_exports","__export","runtimes_default","react_default","__toCommonJS","deepAssign","target","sources","source","k","vs","vt","checkVersion","version","isPromise","p","shareGlobalName","catchErrorNextPlugin","showLog","o","EMPRuntime","deepAssign","shareGlobalName","op","o","options","catchErrorNextPlugin","args","runtimes_default","ReactAdapter","op","o","deepAssign","React","ReactDOM","scope","component","reactVersion","checkVersion","self","WrappedComponent","props","shouldRender","isPromise","m","element","createRoot","hydrateRoot","react_default"]}
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,YAA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C,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"]}
@@ -1,6 +1,5 @@
1
- import * as MFRuntime from '@empjs/module-federation-runtime';
2
- import { E as EMPShareRuntimeType, I as InitOptionsType, a as EmpRuntimeOptions, L as LoadRemoteType } from './react-BIjkQYoz.cjs';
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
- private isInit;
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 '@empjs/module-federation-runtime';
2
- import { E as EMPShareRuntimeType, I as InitOptionsType, a as EmpRuntimeOptions, L as LoadRemoteType } from './react-BIjkQYoz.js';
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
- private isInit;
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(t,...e){for(let n of e)for(let i in n){let r=n[i],o=t[i];if(Object(r)==r&&Object(o)===o){t[i]=p(o,r);continue}t[i]=n[i]}return t}var h=t=>t?Number(t.split(".")[0]):0,f=t=>t&&Object.prototype.toString.call(t)==="[object Promise]";var d="EMP_SHARE_RUNTIME";var y=function(t=!1){return{name:"catch-error-next-plugin",errorLoadRemote(e){return t&&(console.log("[@emp/share]",e.id,e.lifecycle,e.from),console.error("[@emp/share]",e.error)),{}}}};var c=class{libs=p({},window[d]||{});initOptions;options={showLog:!1};isInit=!1;constructor(e){e&&this.setup(e)}setup(e){if(e&&(this.libs=e),!this.libs.MFRuntime||!this.libs.MFSDK)throw new Error("MFRuntime and MFSDK Required!")}init(e={}){if(this.isInit)return;let n={name:"empAdepterProject",remotes:[],plugins:[y(this.options.showLog)]};n=p(n,e),this.libs.MFRuntime.init(n),this.isInit=!0}load(...e){return this.libs.MFRuntime.loadRemote(...e)}register=this.libs.MFRuntime.registerRemotes;preload=this.libs.MFRuntime.preloadRemote;loadShare=this.libs.MFRuntime.loadShare},R=new c;var l=class{libs={scope:"default"};constructor(e){e&&this.setup(e)}setup(e){e&&(typeof e=="string"&&(e=window[e]),this.libs=p(this.libs,e))}get shared(){let{React:e,ReactDOM:n,scope:i}=this.libs;return{react:{lib:()=>e,version:e.version,scope:i,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}},"react-dom":{lib:()=>n,version:n.version,scope:i,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}}}}adapter(e,n=this.libs.scope,i=this.libs.React,r=this.libs.ReactDOM){let o=h(i.version),m=this;class b extends i.Component{containerRef;root;constructor(a){super(a),this.containerRef=i.createRef()}componentDidMount(){this.mountOriginalComponent(!0)}componentDidUpdate(){this.mountOriginalComponent()}componentWillUnmount(){this.unMountOriginalComponent()}unMountOriginalComponent(){this.containerRef.current&&(o<18?r.unmountComponentAtNode(this.containerRef.current):this.root.unmount())}async mountOriginalComponent(a){f(e)&&(e=await e.then(s=>s[n]));let u=i.createElement(e,this.props);if(o<18)(a?r.render:r.hydrate)(u,this.containerRef.current);else if(a){let{createRoot:s}=m.libs;this.root=s(this.containerRef.current),this.root.render(u)}else{let{hydrateRoot:s}=m.libs;this.root=s(this.containerRef.current,u)}}render(){return i.createElement("div",{ref:this.containerRef})}}return b}},g=new l;export{R as default,g as reactAdapter};
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
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/helper/index.ts","../src/helper/config.ts","../src/runtimes/plugins.ts","../src/runtimes/index.ts","../src/adapters/react.tsx"],"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 type {FederationRuntimePlugin} from '@module-federation/runtime'\nexport const catchErrorNextPlugin: (showLog?: boolean) => FederationRuntimePlugin = function (showLog = false) {\n return {\n name: 'catch-error-next-plugin',\n errorLoadRemote(o) {\n if (showLog) {\n console.log('[@emp/share]', o.id, o.lifecycle, o.from)\n console.error('[@emp/share]', o.error)\n }\n return {}\n },\n }\n}\n","import {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport type {EMPShareRuntimeType, EmpRuntimeOptions, InitOptionsType, LoadRemoteType} from 'src/types'\nimport {catchErrorNextPlugin} from './plugins'\ntype EmpInitOptionsType = Partial<InitOptionsType>\nexport class EMPRuntime {\n public libs: EMPShareRuntimeType = deepAssign({}, window[shareGlobalName] || {})\n public initOptions!: InitOptionsType\n public options: EmpRuntimeOptions = {\n showLog: false,\n }\n private isInit = false\n constructor(op?: EMPShareRuntimeType) {\n if (op) this.setup(op)\n }\n /**\n * 实例化 adapter libs\n * @param EMP_ADAPTER\n */\n public setup(o?: EMPShareRuntimeType) {\n if (o) {\n this.libs = o\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: 'empAdepterProject',\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","import {checkVersion, deepAssign, isPromise} from 'src/helper'\nimport type {EMPShareRuntimeAdapterReactType, InitOptionsType} from 'src/types'\nexport class ReactAdapter {\n libs: EMPShareRuntimeAdapterReactType = {\n scope: 'default',\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 = deepAssign(this.libs, o)\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":"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,CAEO,IAAMM,EAAgBC,GAAqBA,EAAU,OAAOA,EAAQ,MAAM,GAAG,EAAE,CAAC,CAAC,EAAI,EAC/EC,EAAaC,GAAWA,GA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GAAM,CAAC,WAAAI,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,IAAInB","names":["deepAssign","target","sources","source","k","vs","vt","checkVersion","version","isPromise","p","shareGlobalName","catchErrorNextPlugin","showLog","o","EMPRuntime","deepAssign","shareGlobalName","op","o","options","catchErrorNextPlugin","args","runtimes_default","ReactAdapter","op","o","deepAssign","React","ReactDOM","scope","component","reactVersion","checkVersion","self","WrappedComponent","props","shouldRender","isPromise","m","element","createRoot","hydrateRoot","react_default"]}
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.2",
3
+ "version": "3.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
- "@empjs/module-federation-runtime": "0.6.2",
95
- "@module-federation/enhanced": "0.6.1",
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.10"
103
+ "@empjs/cli": "3.1.0"
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 };
@@ -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 };