@empjs/share 0.0.1 → 0.0.2

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
@@ -1,7 +1,6 @@
1
1
  # @empjs/share
2
-
3
- ## 01 Rspack Plugin
4
- > @empjs/share/rspack
2
+ ## 01 @empjs/share/rspack - Emp Share Plugin
3
+ >
5
4
  使用方法
6
5
  ```js
7
6
  import {pluginRspackEmpShare} from '@empjs/share'
@@ -30,17 +29,11 @@ export default defineConfig(store => {
30
29
  ],
31
30
  }
32
31
  })
33
-
34
-
35
32
  ```
36
33
 
37
- ## 02 Library
38
- > @empjs/share/library
39
-
40
- ## 03 Runtime
41
- > @empjs/share/runtime
42
-
34
+ ## 02 @empjs/share/library - Module Federation SDK 封装
43
35
 
36
+ ## 03 @empjs/share/runtime - 运行时引用
44
37
  ### 项目调用
45
38
 
46
39
  ```js
@@ -53,7 +46,7 @@ empRuntime.init({
53
46
  remotes: [
54
47
  {
55
48
  name: "mfHost",
56
- entry: `http://${process.env.lanIp}:8001/emp.js`,
49
+ entry: `http://localhost:8001/emp.js`,
57
50
  },
58
51
  ],
59
52
  name: "federationRuntimeDemo",
@@ -0,0 +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});
2
+ //# sourceMappingURL=adapter.cjs.map
@@ -0,0 +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,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K,aAAc,CACtC,CACF,CACA,OAAOO,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"]}
@@ -0,0 +1,7 @@
1
+ import { _ as _default } from './react-BIjkQYoz.cjs';
2
+ import '@empjs/module-federation-runtime';
3
+ import '@module-federation/sdk';
4
+
5
+
6
+
7
+ export { _default as default, _default as reactAdapter };
@@ -0,0 +1,7 @@
1
+ import { _ as _default } from './react-BIjkQYoz.js';
2
+ import '@empjs/module-federation-runtime';
3
+ import '@module-federation/sdk';
4
+
5
+
6
+
7
+ export { _default as default, _default as reactAdapter };
@@ -0,0 +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};
2
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +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,C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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,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"]}
package/dist/index.cjs CHANGED
@@ -1,109 +1,3 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- pluginRspackEmpShare: () => rspack_default
24
- });
25
- module.exports = __toCommonJS(src_exports);
26
-
27
- // src/plugin/rspack/index.ts
28
- var import_rspack = require("@module-federation/enhanced/rspack");
29
-
30
- // src/helper/config.ts
31
- var shareGlobalName = "EMP_SHARE_RUNTIME";
32
-
33
- // src/helper/index.ts
34
- var importJsVm = (content) => `data:text/javascript,${content}`;
35
-
36
- // src/plugin/rspack/plugin.ts
37
- var getShareRuntimeEntry = () => {
38
- const content = [`import '@empjs/share/library'`].join("\n");
39
- return importJsVm(content);
40
- };
41
- var EmpShareRuntimePlugin = class {
42
- constructor() {
43
- }
44
- apply(compiler) {
45
- const { webpack } = compiler;
46
- const entry = getShareRuntimeEntry();
47
- new webpack.EntryPlugin(compiler.context, entry, {
48
- name: void 0
49
- }).apply(compiler);
50
- }
51
- };
52
-
53
- // src/plugin/rspack/index.ts
54
- var rspack_default = (o = {}) => {
55
- return {
56
- name: "@empjs/share",
57
- async rsConfig(store) {
58
- console.log(o);
59
- if (o.name) {
60
- const op = store.deepAssign(
61
- {
62
- filename: "emp.js",
63
- manifest: false,
64
- dts: false,
65
- dev: {
66
- disableDynamicRemoteTypeHints: true
67
- }
68
- },
69
- o
70
- );
71
- delete op.empRuntime;
72
- store.chain.plugin("plugin-emp-share").use(import_rspack.ModuleFederationPlugin, [op]);
73
- }
74
- const { empRuntime } = o;
75
- if (empRuntime) {
76
- if (!empRuntime.runtimeLib) {
77
- store.chain.plugin("plugin-emp-runtime").use(EmpShareRuntimePlugin);
78
- }
79
- empRuntime.runtimeGlobal = empRuntime.frameworkGlobal || shareGlobalName;
80
- const externalRuntime = {
81
- "@module-federation/runtime": `MFRuntime`,
82
- "@module-federation/sdk": `MFSDK`
83
- };
84
- const externals = [];
85
- for (const [key, value] of Object.entries(externalRuntime)) {
86
- externals[key] = `${empRuntime.runtimeGlobal}.${value}`;
87
- }
88
- empRuntime.framework = empRuntime.framework || "react";
89
- empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || empRuntime.runtimeGlobal;
90
- if (empRuntime.framework === "react") {
91
- const externalReact = {
92
- react: `React`,
93
- "react-dom": `ReactDOM`
94
- };
95
- for (const [key, value] of Object.entries(externalReact)) {
96
- externals[key] = `${empRuntime.frameworkGlobal}.${value}`;
97
- }
98
- }
99
- if (empRuntime.setExternals) empRuntime.setExternals(externals);
100
- store.merge({ externals });
101
- }
102
- }
103
- };
104
- };
105
- // Annotate the CommonJS export names for ESM import in node:
106
- 0 && (module.exports = {
107
- pluginRspackEmpShare
108
- });
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});
109
3
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/plugin/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugin/rspack/plugin.ts"],"sourcesContent":["// export {default as runtime} from './mfRuntime'\nexport {default as pluginRspackEmpShare} from './rspack'\n","import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRuntimePlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\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-runtime').use(EmpShareRuntimePlugin)\n }\n empRuntime.runtimeGlobal = empRuntime.frameworkGlobal || 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 //\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 store.merge({externals})\n }\n },\n }\n}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nconst getShareRuntimeEntry = () => {\n const content = [`import '@empjs/share/library'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRuntimePlugin {\n constructor() {}\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const entry = getShareRuntimeEntry()\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,oBAAqC;;;ACD9B,IAAM,kBAAkB;;;ACAxB,IAAM,aAAa,CAAC,YAAoB,wBAAwB,OAAO;;;ACE9E,IAAM,uBAAuB,MAAM;AACjC,QAAM,UAAU,CAAC,+BAA+B,EAAE,KAAK,IAAI;AAC3D,SAAO,WA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ACpB,OAAO;AAAA,YACP,aAAa;AAAA,UACf;AACA,qBAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,aAAa,GAAG;AACxD,sBAAU,GAAG,IAAI,GAAG,WAAW,eAAe,IAAI,KAAK;AAAA,UACzD;AAAA,QACF;AAEA,YAAI,WAAW,aAAc,YAAW,aAAa,SAAS;AAC9D,cAAM,MAAM,EAAC,UAAS,CAAC;AAAA,MACzB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
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"]}
package/dist/index.d.cts CHANGED
@@ -1,3 +1,7 @@
1
- export { default as pluginRspackEmpShare } from './rspack.cjs';
1
+ import _default from './rspack.cjs';
2
2
  import '@empjs/cli';
3
3
  import '@module-federation/enhanced/rspack';
4
+
5
+
6
+
7
+ export { _default as default, _default as pluginRspackEmpShare };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
- export { default as pluginRspackEmpShare } from './rspack.js';
1
+ import _default from './rspack.js';
2
2
  import '@empjs/cli';
3
3
  import '@module-federation/enhanced/rspack';
4
+
5
+
6
+
7
+ export { _default as default, _default as pluginRspackEmpShare };
package/dist/index.js CHANGED
@@ -1,82 +1,3 @@
1
- // src/plugin/rspack/index.ts
2
- import { ModuleFederationPlugin } from "@module-federation/enhanced/rspack";
3
-
4
- // src/helper/config.ts
5
- var shareGlobalName = "EMP_SHARE_RUNTIME";
6
-
7
- // src/helper/index.ts
8
- var importJsVm = (content) => `data:text/javascript,${content}`;
9
-
10
- // src/plugin/rspack/plugin.ts
11
- var getShareRuntimeEntry = () => {
12
- const content = [`import '@empjs/share/library'`].join("\n");
13
- return importJsVm(content);
14
- };
15
- var EmpShareRuntimePlugin = class {
16
- constructor() {
17
- }
18
- apply(compiler) {
19
- const { webpack } = compiler;
20
- const entry = getShareRuntimeEntry();
21
- new webpack.EntryPlugin(compiler.context, entry, {
22
- name: void 0
23
- }).apply(compiler);
24
- }
25
- };
26
-
27
- // src/plugin/rspack/index.ts
28
- var rspack_default = (o = {}) => {
29
- return {
30
- name: "@empjs/share",
31
- async rsConfig(store) {
32
- console.log(o);
33
- if (o.name) {
34
- const op = store.deepAssign(
35
- {
36
- filename: "emp.js",
37
- manifest: false,
38
- dts: false,
39
- dev: {
40
- disableDynamicRemoteTypeHints: true
41
- }
42
- },
43
- o
44
- );
45
- delete op.empRuntime;
46
- store.chain.plugin("plugin-emp-share").use(ModuleFederationPlugin, [op]);
47
- }
48
- const { empRuntime } = o;
49
- if (empRuntime) {
50
- if (!empRuntime.runtimeLib) {
51
- store.chain.plugin("plugin-emp-runtime").use(EmpShareRuntimePlugin);
52
- }
53
- empRuntime.runtimeGlobal = empRuntime.frameworkGlobal || shareGlobalName;
54
- const externalRuntime = {
55
- "@module-federation/runtime": `MFRuntime`,
56
- "@module-federation/sdk": `MFSDK`
57
- };
58
- const externals = [];
59
- for (const [key, value] of Object.entries(externalRuntime)) {
60
- externals[key] = `${empRuntime.runtimeGlobal}.${value}`;
61
- }
62
- empRuntime.framework = empRuntime.framework || "react";
63
- empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || empRuntime.runtimeGlobal;
64
- if (empRuntime.framework === "react") {
65
- const externalReact = {
66
- react: `React`,
67
- "react-dom": `ReactDOM`
68
- };
69
- for (const [key, value] of Object.entries(externalReact)) {
70
- externals[key] = `${empRuntime.frameworkGlobal}.${value}`;
71
- }
72
- }
73
- if (empRuntime.setExternals) empRuntime.setExternals(externals);
74
- store.merge({ externals });
75
- }
76
- }
77
- };
78
- };
79
- export {
80
- rspack_default as pluginRspackEmpShare
81
- };
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};
82
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugin/rspack/plugin.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRuntimePlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\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-runtime').use(EmpShareRuntimePlugin)\n }\n empRuntime.runtimeGlobal = empRuntime.frameworkGlobal || 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 //\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 store.merge({externals})\n }\n },\n }\n}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nconst getShareRuntimeEntry = () => {\n const content = [`import '@empjs/share/library'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRuntimePlugin {\n constructor() {}\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const entry = getShareRuntimeEntry()\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n}\n"],"mappings":";AACA,SAAQ,8BAA6B;;;ACD9B,IAAM,kBAAkB;;;ACAxB,IAAM,aAAa,CAAC,YAAoB,wBAAwB,OAAO;;;ACE9E,IAAM,uBAAuB,MAAM;AACjC,QAAM,UAAU,CAAC,+BAA+B,EAAE,KAAK,IAAI;AAC3D,SAAO,WAAW,OAAO;AAC3B;AACO,IAAM,wBAAN,MAA4B;AAAA,EACjC,cAAc;AAAA,EAAC;AAAA,EACf,MAAM,UAAoB;AACxB,UAAM,EAAC,QAAO,IAAI;AAClB,UAA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,eAAe,IAAI,KAAK;AAAA,UACzD;AAAA,QACF;AAEA,YAAI,WAAW,aAAc,YAAW,aAAa,SAAS;AAC9D,cAAM,MAAM,EAAC,UAAS,CAAC;AAAA,MACzB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
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,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,IAAIE,EAAwB,CAACD,CAAE,CAAC,CACzE,CACA,GAAM,CAAC,WAAAE,CAAU,EAAIJ,EACrB,GAAII,EAAY,CACTA,EAAW,YACdH,EAAM,MAAM,OAAO,4BAA4B,EAAE,IAAII,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,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,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"]}
@@ -0,0 +1,30 @@
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 };
@@ -0,0 +1,30 @@
1
+ import MFRuntime__default from '@empjs/module-federation-runtime';
2
+ import MFSDK from '@module-federation/sdk';
3
+
4
+ type EMPShareRuntimeType = {
5
+ MFRuntime: Required<typeof MFRuntime__default>;
6
+ MFSDK: Required<typeof MFSDK>;
7
+ };
8
+ type EMPShareRuntimeAdapterReactType = {
9
+ React?: any;
10
+ ReactDOM?: any;
11
+ createRoot?: any;
12
+ hydrateRoot?: any;
13
+ scope: string;
14
+ };
15
+ type InitOptionsType = Parameters<typeof MFRuntime__default.init>[0];
16
+ type LoadRemoteType = Parameters<typeof MFRuntime__default.loadRemote>;
17
+ type EmpRuntimeOptions = {
18
+ showLog?: boolean;
19
+ };
20
+
21
+ declare class ReactAdapter {
22
+ libs: EMPShareRuntimeAdapterReactType;
23
+ constructor(op?: EMPShareRuntimeAdapterReactType);
24
+ setup(o?: EMPShareRuntimeAdapterReactType | string): void;
25
+ get shared(): InitOptionsType['shared'];
26
+ adapter<P = any>(component: any, scope?: string, React?: any, ReactDOM?: any): P;
27
+ }
28
+ declare const _default: ReactAdapter;
29
+
30
+ export { type EMPShareRuntimeType as E, type InitOptionsType as I, type LoadRemoteType as L, _default as _, type EmpRuntimeOptions as a };
package/dist/rspack.cjs CHANGED
@@ -1,105 +1,3 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/rspack.ts
21
- var rspack_exports = {};
22
- __export(rspack_exports, {
23
- default: () => rspack_default
24
- });
25
- module.exports = __toCommonJS(rspack_exports);
26
-
27
- // src/plugin/rspack/index.ts
28
- var import_rspack = require("@module-federation/enhanced/rspack");
29
-
30
- // src/helper/config.ts
31
- var shareGlobalName = "EMP_SHARE_RUNTIME";
32
-
33
- // src/helper/index.ts
34
- var importJsVm = (content) => `data:text/javascript,${content}`;
35
-
36
- // src/plugin/rspack/plugin.ts
37
- var getShareRuntimeEntry = () => {
38
- const content = [`import '@empjs/share/library'`].join("\n");
39
- return importJsVm(content);
40
- };
41
- var EmpShareRuntimePlugin = class {
42
- constructor() {
43
- }
44
- apply(compiler) {
45
- const { webpack } = compiler;
46
- const entry = getShareRuntimeEntry();
47
- new webpack.EntryPlugin(compiler.context, entry, {
48
- name: void 0
49
- }).apply(compiler);
50
- }
51
- };
52
-
53
- // src/plugin/rspack/index.ts
54
- var rspack_default = (o = {}) => {
55
- return {
56
- name: "@empjs/share",
57
- async rsConfig(store) {
58
- console.log(o);
59
- if (o.name) {
60
- const op = store.deepAssign(
61
- {
62
- filename: "emp.js",
63
- manifest: false,
64
- dts: false,
65
- dev: {
66
- disableDynamicRemoteTypeHints: true
67
- }
68
- },
69
- o
70
- );
71
- delete op.empRuntime;
72
- store.chain.plugin("plugin-emp-share").use(import_rspack.ModuleFederationPlugin, [op]);
73
- }
74
- const { empRuntime } = o;
75
- if (empRuntime) {
76
- if (!empRuntime.runtimeLib) {
77
- store.chain.plugin("plugin-emp-runtime").use(EmpShareRuntimePlugin);
78
- }
79
- empRuntime.runtimeGlobal = empRuntime.frameworkGlobal || shareGlobalName;
80
- const externalRuntime = {
81
- "@module-federation/runtime": `MFRuntime`,
82
- "@module-federation/sdk": `MFSDK`
83
- };
84
- const externals = [];
85
- for (const [key, value] of Object.entries(externalRuntime)) {
86
- externals[key] = `${empRuntime.runtimeGlobal}.${value}`;
87
- }
88
- empRuntime.framework = empRuntime.framework || "react";
89
- empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || empRuntime.runtimeGlobal;
90
- if (empRuntime.framework === "react") {
91
- const externalReact = {
92
- react: `React`,
93
- "react-dom": `ReactDOM`
94
- };
95
- for (const [key, value] of Object.entries(externalReact)) {
96
- externals[key] = `${empRuntime.frameworkGlobal}.${value}`;
97
- }
98
- }
99
- if (empRuntime.setExternals) empRuntime.setExternals(externals);
100
- store.merge({ externals });
101
- }
102
- }
103
- };
104
- };
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)}}});
105
3
  //# sourceMappingURL=rspack.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/rspack.ts","../src/plugin/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugin/rspack/plugin.ts"],"sourcesContent":["// import {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\n// export type ModuleFederationPluginOptions = ConstructorParameters<typeof ModuleFederationPlugin>[0]\n// export {ModuleFederationPlugin}\nexport {default} from './plugin/rspack'\n","import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRuntimePlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\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-runtime').use(EmpShareRuntimePlugin)\n }\n empRuntime.runtimeGlobal = empRuntime.frameworkGlobal || 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 //\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 store.merge({externals})\n }\n },\n }\n}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nconst getShareRuntimeEntry = () => {\n const content = [`import '@empjs/share/library'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRuntimePlugin {\n constructor() {}\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const entry = getShareRuntimeEntry()\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,oBAAqC;;;ACD9B,IAAM,kBAAkB;;;ACAxB,IAAM,aAAa,CAAC,YAAoB,wBAAwB,OAAO;;;ACE9E,IAAM,uBAAuB,MAAM;AACjC,QAAM,UAAU,CAAC,+BAA+B,EAAE,KAAK,IAAI;AAC3D,SAAO,WAAW,OAAO;AAC3B;AACO,IAAM,wBAAN,MAA4B;AAAA,EACjC,cAAc;AAAA,EAAC;AAAA,EACf,MAAM,UAAoB;AACxB,UAAM,EAAC,QAAO,IAAI;AAClB,UAAM,QAAQ,qBAAqB;AACnC,QAAI,QAAQ,YAAY,SAAS,SAAS,OAAO;AAAA,MAC/C,MAAM;AAAA,IACR,CAAC,EAAE,MAAM,QAAQ;AAAA,EACnB;AACF;;;AHTA,IAAO,iBAAQ,CAAC,IAAwB,CAAC,MAAM;AAC7C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,SAAS,OAAoB;AACjC,cAAQ,IAAI,CAAC;AACb,UAAI,EAAE,MAAM;AACV,cAAM,KAAU,MAAM;AAAA,UACpB;AAAA,YACE,UAAU;AAAA,YACV,UAAU;AAAA,YACV,KAAK;AAAA,YACL,KAAK;AAAA,cACH,+BAA+B;AAAA,YACjC;AAAA,UACF;AAAA,UACA;AAAA,QACF;AACA,eAAO,GAAG;AACV,cAAM,MAAM,OAAO,kBAAkB,EAAE,IAAI,sCAAwB,CAAC,EAAE,CAAC;AAAA,MACzE;AACA,YAAM,EAAC,WAAU,IAAI;AACrB,UAAI,YAAY;AACd,YAAI,CAAC,WAAW,YAAY;AAC1B,gBAAM,MAAM,OAAO,oBAAoB,EAAE,IAAI,qBAAqB;AAAA,QACpE;AACA,mBAAW,gBAAgB,WAAW,mBAAmB;AACzD,cAAM,kBAAkB;AAAA,UACtB,8BAA8B;AAAA,UAC9B,0BAA0B;AAAA,QAC5B;AACA,cAAM,YAAY,CAAC;AACnB,mBAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,eAAe,GAAG;AAC1D,oBAAU,GAAG,IAAI,GAAG,WAAW,aAAa,IAAI,KAAK;AAAA,QACvD;AAEA,mBAAW,YAAY,WAAW,aAAa;AAC/C,mBAAW,kBAAkB,WAAW,mBAAmB,WAAW;AACtE,YAAI,WAAW,cAAc,SAAS;AACpC,gBAAM,gBAAgB;AAAA,YACpB,OAAO;AAAA,YACP,aAAa;AAAA,UACf;AACA,qBAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,aAAa,GAAG;AACxD,sBAAU,GAAG,IAAI,GAAG,WAAW,eAAe,IAAI,KAAK;AAAA,UACzD;AAAA,QACF;AAEA,YAAI,WAAW,aAAc,YAAW,aAAa,SAAS;AAC9D,cAAM,MAAM,EAAC,UAAS,CAAC;AAAA,MACzB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
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,CAC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,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"]}