@empjs/share 3.1.1 → 3.1.3

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/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
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});
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 O={};S(O,{default:()=>H,pluginRspackEmpShare:()=>f});module.exports=M(O);var E=require("@module-federation/enhanced/rspack");var y="EMP_SHARE_RUNTIME";var d=t=>`data:text/javascript,${t}`;var w=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=w("@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 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(E.ModuleFederationPlugin,[o])}let{empRuntime:n}=t;if(n){let o=[],r=n.framework||"react",{frameworkLib:b,runtimeLib:p}=n,l=n.runtimeGlobal||y,s=n.frameworkGlobal||"";if(n.injectGlobalValToHtml!==!1&&o.push({type:"js",content:`EMPShareGlobalVal={frameworkLib:'${s}',runtimeLib:'${l}',framework:'${r}'}`}),b){let i=R(b,e.mode);o.push({type:"js",src:i})}p?p==="useFrameworkLib"?l=s:o.push({type:"js",src: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})}}}),f=G;var H=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":["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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,MAAOO,CACT,CAAC,CACH,CACKJ,EAKIA,IAAe,kBACtBC,EAAgBE,EAGhBN,EAAW,KAAK,CAAC,KAAM,KAAM,MAAOG,CAAU,CAAC,EAP/CN,EAAM,MAAM,OAAO,4BAA4B,EAAE,IAAIY,EAAyB,CAACV,CAAU,CAAC,EASxFC,EAAW,OAAS,GACtBH,EAAM,eAAeG,EAAY,UAAU,EAK7C,IAAMU,EAAkB,CACtB,6BAA8B,YAC9B,yBAA0B,OAC5B,EACMC,EAAY,CAAC,EACnB,OAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQH,CAAe,EACvDC,EAAUC,CAAG,EAAI,GAAGR,CAAa,IAAIS,CAAK,GAE5C,GAAIZ,IAAc,SAAWK,EAAiB,CAC5C,IAAMQ,EAAgB,CACpB,MAAO,QACP,YAAa,UACf,EACA,OAAW,CAACF,EAAKC,CAAK,IAAK,OAAO,QAAQC,CAAa,EACrDH,EAAUC,CAAG,EAAI,GAAGN,CAAe,IAAIO,CAAK,EAEhD,CACId,EAAW,cAAcA,EAAW,aAAaY,CAAS,EAG9Dd,EAAM,MAAM,MAAM,CAAC,UAAAc,CAAS,CAAC,CAC/B,CACF,CACF,GAGKI,EAAQpB,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"]}
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: 'js',\n content: `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 src: url,\n })\n }\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n //\n\n // store.chain.optimization.merge({\n // splitChunks: {\n // cacheGroups: {\n // moduleFederation: {\n // name: 'mfRuntime',\n // test: /[\\\\/]node_modules[\\\\/](@module-federation)[\\\\/]/,\n // priority: 0,\n // chunks: 'all',\n // },\n // },\n // },\n // })\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib') {\n runtimeGlobal = frameworkGlobal\n } else {\n // 插入 runtime\n injectHtml.push({type: 'js', src: 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,eAC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AKC,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,ED5Gf,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.js CHANGED
@@ -1,3 +1,3 @@
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};
1
+ import{ModuleFederationPlugin as g}from"@module-federation/enhanced/rspack";var f="EMP_SHARE_RUNTIME";var b=t=>`data:text/javascript,${t}`;var j=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=j("@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(g,[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:"js",content:`EMPShareGlobalVal={frameworkLib:'${s}',runtimeLib:'${l}',framework:'${i}'}`}),u){let r=y(u,e.mode);o.push({type:"js",src:r})}p?p==="useFrameworkLib"?l=s:o.push({type:"js",src: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"},a={};for(let[r,c]of Object.entries(R))a[r]=`${l}.${c}`;if(i==="react"&&s){let r={react:"React","react-dom":"ReactDOM"};for(let[c,E]of Object.entries(r))a[c]=`${s}.${E}`}n.setExternals&&n.setExternals(a),e.chain.merge({externals:a})}}}),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 const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n if (o.name) {\n const op: any = store.deepAssign(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n delete op.empRuntime\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n const {empRuntime} = o\n if (empRuntime) {\n const injectHtml: any[] = []\n const framework = empRuntime.framework || 'react'\n const {frameworkLib, runtimeLib} = empRuntime\n //\n let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n const frameworkGlobal = empRuntime.frameworkGlobal || ''\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n type: 'script',\n value: `EMPShareGlobalVal={frameworkLib:'${frameworkGlobal}',runtimeLib:'${runtimeGlobal}',framework:'${framework}'}`,\n })\n }\n /**\n * frameworkLib & runtimeLib 的全局引用\n */\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n type: 'js',\n value: url,\n })\n }\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib') {\n runtimeGlobal = frameworkGlobal\n } else {\n // 插入 runtime\n injectHtml.push({type: 'js', value: runtimeLib})\n }\n if (injectHtml.length > 0) {\n store.injectHeadTags(injectHtml, 'EMPShare')\n }\n /**\n * 设置 externals\n */\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n },\n }\n}\n\nexport default pluginRspackEmpShare\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n","import {default as pluginRspackEmpShare} from 'src/plugins/rspack'\nexport default pluginRspackEmpShare\nexport {pluginRspackEmpShare}\n"],"mappings":"AACA,OAAQ,0BAAAA,MAA6B,qCCD9B,IAAMC,EAAkB,oBCAxB,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GCG9E,IAAMC,EAAuBC,GAAO,CAClC,IAAMC,EAAU,CAAC,WAAWD,CAAG,GAAG,EAAE,KAAK;AAAA,CAAI,EAC7C,OAAOE,EAAWD,CAAO,CAC3B,EACaE,EAAN,KAA8B,CACnC,QACA,YAAYC,EAA4B,CACtC,KAAK,QAAUA,CACjB,CACA,MAAMC,EAAoB,CACxB,GAAM,CAAC,QAAAC,CAAO,EAAID,EACZ,CAAC,WAAAE,CAAU,EAAI,KAAK,QAC1B,GAAI,CAACA,EAAY,CACf,IAAMC,EAAQT,EAAqB,sBAAsB,EACzD,IAAIO,EAAQ,YAAYD,EAAS,QAASG,EAAO,CAC/C,KAAM,MACR,CAAC,EAAE,MAAMH,CAAQ,CACnB,CACF,CACF,ECrBO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C5B,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"]}
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: 'js',\n content: `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 src: url,\n })\n }\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n //\n\n // store.chain.optimization.merge({\n // splitChunks: {\n // cacheGroups: {\n // moduleFederation: {\n // name: 'mfRuntime',\n // test: /[\\\\/]node_modules[\\\\/](@module-federation)[\\\\/]/,\n // priority: 0,\n // chunks: 'all',\n // },\n // },\n // },\n // })\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib') {\n runtimeGlobal = frameworkGlobal\n } else {\n // 插入 runtime\n injectHtml.push({type: 'js', src: 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 pluginR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AC,CAAU,EAAIJ,EAE/BK,EAAgBL,EAAW,eAAiBM,EAC1CC,EAAkBP,EAAW,iBAAmB,GAYtD,GAX8BA,EAAW,wBAA0B,IAGjEC,EAAW,KAAK,CACd,KAAM,KACN,QAAS,oCAAoCM,CAAe,iBAAiBF,CAAa,gBAAgBH,CAAS,IACrH,CAAC,EAKCC,EAAc,CAChB,IAAMK,EAAMC,EAAcN,EAAcN,EAAM,IAAI,EAClDI,EAAW,KAAK,CACd,KAAM,KACN,IAAKO,CACP,CAAC,CACH,CACKJ,EAmBIA,IAAe,kBACtBC,EAAgBE,EAGhBN,EAAW,KAAK,CAAC,KAAM,KAAM,IAAKG,CAAU,CAAC,EArB7CP,EAAM,MAAM,OAAO,4BAA4B,EAAE,IAAIa,EAAyB,CAACV,CAAU,CAAC,EAuBxFC,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,EK5Gf,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 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});
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 H={};P(H,{default:()=>G,pluginRspackEmpShare:()=>j});module.exports=M(H);var R=require("@module-federation/enhanced/rspack");var b="EMP_SHARE_RUNTIME";var y=t=>`data:text/javascript,${t}`;var w=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=w("@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 j=(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:"js",content:`EMPShareGlobalVal={frameworkLib:'${s}',runtimeLib:'${l}',framework:'${r}'}`}),f){let i=d(f,e.mode);o.push({type:"js",src:i})}p?p==="useFrameworkLib"?l=s:o.push({type:"js",src:p}):e.chain.plugin("plugin-emp-share-framework").use(m,[n]),o.length>0&&e.injectHeadTags(o,"EMPShare");let E={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},a={};for(let[i,c]of Object.entries(E))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})}}}),G=j;0&&(module.exports={pluginRspackEmpShare});
3
3
  //# sourceMappingURL=rspack.cjs.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 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,MAAM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,kBACtBC,EAAgBE,EAGhBN,EAAW,KAAK,CAAC,KAAM,KAAM,MAAOG,CAAU,CAAC,EAP/CN,EAAM,MAAM,OAAO,4BAA4B,EAAE,IAAIY,EAAyB,CAACV,CAAU,CAAC,EASxFC,EAAW,OAAS,GACtBH,EAAM,eAAeG,EAAY,UAAU,EAK7C,IAAMU,EAAkB,CACtB,6BAA8B,YAC9B,yBAA0B,OAC5B,EACMC,EAAY,CAAC,EACnB,OAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQH,CAAe,EACvDC,EAAUC,CAAG,EAAI,GAAGR,CAAa,IAAIS,CAAK,GAE5C,GAAIZ,IAAc,SAAWK,EAAiB,CAC5C,IAAMQ,EAAgB,CACpB,MAAO,QACP,YAAa,UACf,EACA,OAAW,CAACF,EAAKC,CAAK,IAAK,OAAO,QAAQC,CAAa,EACrDH,EAAUC,CAAG,EAAI,GAAGN,CAAe,IAAIO,CAAK,EAEhD,CACId,EAAW,cAAcA,EAAW,aAAaY,CAAS,EAG9Dd,EAAM,MAAM,MAAM,CAAC,UAAAc,CAAS,CAAC,CAC/B,CACF,CACF,GAGKI,EAAQpB","names":["rspack_exports","__export","rspack_default","pluginRspackEmpShare","__toCommonJS","import_rspack","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","pluginRspackEmpShare","o","store","op","empRuntime","injectHtml","framework","frameworkLib","runtimeLib","runtimeGlobal","shareGlobalName","frameworkGlobal","url","getRuntimeLib","EmpShareRemoteLibPlugin","externalRuntime","externals","key","value","externalReact","rspack_default"]}
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: 'js',\n content: `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 src: url,\n })\n }\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n //\n\n // store.chain.optimization.merge({\n // splitChunks: {\n // cacheGroups: {\n // moduleFederation: {\n // name: 'mfRuntime',\n // test: /[\\\\/]node_modules[\\\\/](@module-federation)[\\\\/]/,\n // priority: 0,\n // chunks: 'all',\n // },\n // },\n // },\n // })\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib') {\n runtimeGlobal = frameworkGlobal\n } else {\n // 插入 runtime\n injectHtml.push({type: 'js', src: 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,GACL,IAAK,CACH,8BAA+B,EACjC,CACF,EACAD,CACF,EAC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AAM,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.js CHANGED
@@ -1,3 +1,3 @@
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};
1
+ import{ModuleFederationPlugin as E}from"@module-federation/enhanced/rspack";var f="EMP_SHARE_RUNTIME";var b=t=>`data:text/javascript,${t}`;var j=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=j("@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(E,[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:"js",content:`EMPShareGlobalVal={frameworkLib:'${s}',runtimeLib:'${l}',framework:'${i}'}`}),u){let r=y(u,e.mode);o.push({type:"js",src:r})}p?p==="useFrameworkLib"?l=s:o.push({type:"js",src: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})}}}),$=g;export{$ 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 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,IA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,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"]}
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: 'js',\n content: `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 src: url,\n })\n }\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n //\n\n // store.chain.optimization.merge({\n // splitChunks: {\n // cacheGroups: {\n // moduleFederation: {\n // name: 'mfRuntime',\n // test: /[\\\\/]node_modules[\\\\/](@module-federation)[\\\\/]/,\n // priority: 0,\n // chunks: 'all',\n // },\n // },\n // },\n // })\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib') {\n runtimeGlobal = frameworkGlobal\n } else {\n // 插入 runtime\n injectHtml.push({type: 'js', src: 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,CA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U,CAAC,EArB7CP,EAAM,MAAM,OAAO,4BAA4B,EAAE,IAAIa,EAAyB,CAACV,CAAU,CAAC,EAuBxFC,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"]}
@@ -0,0 +1,54 @@
1
+ import * as MFRuntime from '@module-federation/enhanced/runtime';
2
+ import MFRuntime__default from '@module-federation/enhanced/runtime';
3
+ export { MFRuntime };
4
+ import MFSDK__default from '@module-federation/sdk';
5
+ import * as MFSDK from '@module-federation/sdk';
6
+ export { MFSDK };
7
+
8
+ type EMPShareRuntimeType = {
9
+ MFRuntime: Required<typeof MFRuntime__default>;
10
+ MFSDK: Required<typeof MFSDK__default>;
11
+ };
12
+ type EMPShareRuntimeAdapterReactType = {
13
+ React?: any;
14
+ ReactDOM?: any;
15
+ createRoot?: any;
16
+ hydrateRoot?: any;
17
+ scope: string;
18
+ };
19
+ type InitOptionsType = Parameters<typeof MFRuntime__default.init>[0];
20
+ type LoadRemoteType = Parameters<typeof MFRuntime__default.loadRemote>;
21
+ type EmpRuntimeOptions = {
22
+ showLog?: boolean;
23
+ };
24
+
25
+ declare class ReactAdapter {
26
+ libs: EMPShareRuntimeAdapterReactType;
27
+ constructor(op?: EMPShareRuntimeAdapterReactType);
28
+ setup(o?: EMPShareRuntimeAdapterReactType | string): void;
29
+ get shared(): InitOptionsType['shared'];
30
+ adapter<P = any>(component: any, scope?: string, React?: any, ReactDOM?: any): P;
31
+ }
32
+ declare const _default: ReactAdapter;
33
+
34
+ type EmpInitOptionsType = Partial<InitOptionsType>;
35
+ declare class EMPRuntime {
36
+ libs: EMPShareRuntimeType;
37
+ initOptions: InitOptionsType;
38
+ options: EmpRuntimeOptions;
39
+ shareGlobalName: string;
40
+ constructor(op?: EMPShareRuntimeType);
41
+ /**
42
+ * 实例化 adapter libs
43
+ */
44
+ setup(o?: EMPShareRuntimeType | string): void;
45
+ init(options?: EmpInitOptionsType): void;
46
+ load<T = any>(...args: LoadRemoteType): Promise<T>;
47
+ register: typeof MFRuntime.registerRemotes;
48
+ preload: typeof MFRuntime.preloadRemote;
49
+ loadShare: typeof MFRuntime.loadShare;
50
+ }
51
+
52
+ declare const runtime: EMPRuntime;
53
+
54
+ export { _default as reactAdapter, runtime };