@empjs/share 3.1.13 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var f=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var w=(i,e)=>{for(var t in e)f(i,t,{get:e[t],enumerable:!0})},P=(i,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of k(e))!x.call(i,o)&&o!==t&&f(i,o,{get:()=>e[o],enumerable:!(s=S(e,o))||s.enumerable});return i};var M=i=>P(f({},"__esModule",{value:!0}),i);var T={};w(T,{default:()=>H,pluginRspackEmpShare:()=>h});module.exports=M(T);var d=require("@module-federation/enhanced/rspack");var y="EMP_SHARE_RUNTIME";var g=i=>`data:text/javascript,${i}`;var L=i=>{let e=[`import '${i}'`].join(`
2
- `);return g(e)},m=class{options;constructor(e){this.options=e}apply(e){let{webpack:t}=e,{runtimeLib:s}=this.options;if(!s){let o=L("@empjs/share/library");new t.EntryPlugin(e.context,o,{name:void 0}).apply(e)}}};function j(i,e){return typeof i=="string"?`${i}/runtime${e==="development"?".development":""}.umd.js`:typeof i=="object"?e==="development"?i.dev:i.prod:""}var R=/^([0-9a-zA-Z_\s]+)@(.*)/,c=class{op;store;injectHtml=[];externalsLib=[];constructor(e,t){this.op=e||{},this.store=t}setup(){this.setMF(),this.injectGlobalVal(),this.injectFramework(),this.setShareLib(),this.setRuntimeLib(),this.injectToHtml(),this.setExternal()}injectToHtml(){let{store:e,injectHtml:t}=this;t.length>0&&e.injectTags(t,"EMPShare")}injectFramework(){if(!this.op.empRuntime||!this.op.empRuntime.frameworkLib)return;let{store:e,injectHtml:t}=this,{frameworkLib:s}=this.op.empRuntime;if(s){let o=j(s,e.mode);t.push({attributes:{src:o},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:t}=this;e.framework=Object.hasOwn(e,"framework")?e.framework:"react",e.runtimeGlobal=e.runtimeGlobal||y,e.frameworkGlobal=e.frameworkGlobal||(e.shareLib?"window":""),e.injectGlobalValToHtml!==!1&&t.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${e.frameworkGlobal}',runtimeLib:'${e.runtimeGlobal}',framework:'${e.framework}'}`})}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:t}=this,{empRuntime:s}=this.op,{framework:o,shareLib:n,runtimeGlobal:r,frameworkGlobal:a}=s,b={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},p={};for(let[l,u]of Object.entries(b))p[l]=`${r}.${u}`;if(o==="react"&&!n&&a){let l={react:"React","react-dom":"ReactDOM"};for(let[u,E]of Object.entries(l))p[u]=`${a}.${E}`}n&&t.map(l=>{l.type==="js"&&l.module&&l.global&&(p[l.module]=`${a}.${l.global}`)}),s.setExternals&&s.setExternals(p),e.chain.merge({externals:p})}setRuntimeLib(){if(!this.op.empRuntime)return;let{runtimeLib:e,shareLib:t}=this.op.empRuntime,{store:s,injectHtml:o}=this,{empRuntime:n}=this.op;e?e==="useFrameworkLib"&&!t||o.push({tagName:"script",pos:"head",attributes:{src:e}}):s.chain.plugin("plugin-emp-share-framework").use(m,[n])}setMF(){let e=this.op,{store:t}=this;if(e.name){let s=t.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},e);t.chain.plugin("plugin-emp-share").use(d.ModuleFederationPlugin,[s])}}setShareLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{externalsLib:t,injectHtml:s}=this;if(e&&typeof e=="object"){for(let[o,n]of Object.entries(e)){let r={};if(r.module=o,typeof n=="string"){let a=n.match(R)||[];a.length>0?(r.global=a[1],r.entry=a[2],r.type="js",t.push(r),r={}):(r.global="",r.entry=n,r.type="js",t.push(r),r={})}else Array.isArray(n)?n.map(a=>{if(!a)return;if(a.split("?")[0].endsWith(".css"))r.entry=a,r.type="css";else{let p=a.match(R)||[];p.length>0?(r.global=p[1],r.entry=p[2],r.type="js"):(r.global="",r.entry=a,r.type="js")}t.push(r),r={}}):typeof n=="object"&&n.entry&&(r.entry=n.entry,r.global=n.global,r.type=n.type,t.push(r),r={})}t.map(o=>{o.type==="js"?s.push({attributes:{src:o.entry},tagName:"script"}):o.type==="css"&&s.push({attributes:{href:o.entry,rel:"stylesheet"},tagName:"link"})})}}};var G=(i={})=>({name:"@empjs/share",async rsConfig(e){new c(i,e).setup()}}),h=G;var H=h;0&&(module.exports={pluginRspackEmpShare});
1
+ "use strict";var f=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var w=(i,e)=>{for(var t in e)f(i,t,{get:e[t],enumerable:!0})},P=(i,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of k(e))!x.call(i,s)&&s!==t&&f(i,s,{get:()=>e[s],enumerable:!(o=S(e,s))||o.enumerable});return i};var M=i=>P(f({},"__esModule",{value:!0}),i);var T={};w(T,{default:()=>H,pluginRspackEmpShare:()=>h});module.exports=M(T);var d=require("@module-federation/enhanced/rspack");var y="EMP_SHARE_RUNTIME";var g=i=>`data:text/javascript,${i}`;var L=i=>{let e=[`import '${i}'`].join(`
2
+ `);return g(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:t}=e,{runtimeLib:o}=this.options;if(!o){let s=L("@empjs/share/library");new t.EntryPlugin(e.context,s,{name:void 0}).apply(e)}}};function j(i,e){return typeof i=="string"?`${i}/runtime${e==="development"?".development":""}.umd.js`:typeof i=="object"?e==="development"?i.dev:i.prod:""}var R=/^([0-9a-zA-Z_\s]+)@(.*)/,c=class{op;store;injectHtml=[];externalsLib=[];constructor(e,t){this.op=e||{},this.store=t}setup(){this.setMF(),this.injectGlobalVal(),this.injectFramework(),this.setShareLib(),this.setRuntimeLib(),this.injectToHtml(),this.setExternal()}injectToHtml(){let{store:e,injectHtml:t}=this;t.length>0&&e.injectTags(t,"EMPShare")}injectFramework(){if(!this.op.empRuntime||!this.op.empRuntime.frameworkLib)return;let{store:e,injectHtml:t}=this,{frameworkLib:o}=this.op.empRuntime;if(o){let s=j(o,e.mode);t.push({attributes:{src:s},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:t}=this;e.framework=Object.hasOwn(e,"framework")?e.framework:"react",e.runtimeGlobal=e.runtimeGlobal||y,e.frameworkGlobal=e.frameworkGlobal||(e.shareLib?"window":""),e.injectGlobalValToHtml!==!1&&t.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${e.frameworkGlobal}',runtimeLib:'${e.runtimeGlobal}',framework:'${e.framework}'}`})}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:t}=this,{empRuntime:o}=this.op,{framework:s,shareLib:n,runtimeGlobal:r,frameworkGlobal:a}=o,b={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},p={};for(let[m,u]of Object.entries(b))p[m]=`${r}.${u}`;if(s==="react"&&!n&&a){let m={react:"React","react-dom":"ReactDOM"};for(let[u,E]of Object.entries(m))p[u]=`${a}.${E}`}n&&t.map(m=>{m.type==="js"&&m.module&&m.global&&(p[m.module]=`${a}.${m.global}`)}),o.setExternals&&o.setExternals(p),e.chain.merge({externals:p})}setRuntimeLib(){if(!this.op.empRuntime)return;let{runtimeLib:e,shareLib:t}=this.op.empRuntime,{store:o,injectHtml:s}=this,{empRuntime:n}=this.op;e?e==="useFrameworkLib"&&!t||s.push({tagName:"script",pos:"head",attributes:{src:e}}):o.chain.plugin("plugin-emp-share-framework").use(l,[n])}setMF(){let e=this.op,{store:t}=this;if(e.name){let o=t.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},e);o.empRuntime&&delete o.empRuntime,t.chain.plugin("plugin-emp-share").use(d.ModuleFederationPlugin,[o])}}setShareLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{externalsLib:t,injectHtml:o}=this;if(e&&typeof e=="object"){for(let[s,n]of Object.entries(e)){let r={};if(r.module=s,typeof n=="string"){let a=n.match(R)||[];a.length>0?(r.global=a[1],r.entry=a[2],r.type="js",t.push(r),r={}):(r.global="",r.entry=n,r.type="js",t.push(r),r={})}else Array.isArray(n)?n.map(a=>{if(!a)return;if(a.split("?")[0].endsWith(".css"))r.entry=a,r.type="css";else{let p=a.match(R)||[];p.length>0?(r.global=p[1],r.entry=p[2],r.type="js"):(r.global="",r.entry=a,r.type="js")}t.push(r),r={}}):typeof n=="object"&&n.entry&&(r.entry=n.entry,r.global=n.global,r.type=n.type,t.push(r),r={})}t.map(s=>{s.type==="js"?o.push({attributes:{src:s.entry},tagName:"script"}):s.type==="css"&&o.push({attributes:{href:s.entry,rel:"stylesheet"},tagName:"link"})})}}};var G=(i={})=>({name:"@empjs/share",async rsConfig(e){new c(i,e).setup()}}),h=G;var H=h;0&&(module.exports={pluginRspackEmpShare});
3
3
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/plugins/rspack/share.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts","../src/plugins/rspack/index.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, ExternalsItemType, ModuleFederationPluginOptions} from './types'\nimport {getRuntimeLib} from './utils'\nconst exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\nexport class EmpShare {\n private op: EMPPluginShareType\n private store: GlobalStore\n /**\n * 注入资源\n */\n private injectHtml: any[] = []\n /**\n * 兼容 shareLib\n */\n private externalsLib: ExternalsItemType[] = []\n constructor(op: EMPPluginShareType, store: GlobalStore) {\n this.op = op || {}\n this.store = store\n }\n setup() {\n this.setMF() // 设置 MF 配置\n this.injectGlobalVal() // 插入全局变量 方便emp外的项目调用\n this.injectFramework() // 插入ui框架库\n this.setShareLib() //兼容 emp Sharelib的共享模型设置\n this.setRuntimeLib() // 设置 MF SDK\n this.injectToHtml() //触发插入动作\n this.setExternal() // 设置 external 降低包体\n }\n private injectToHtml() {\n const {store, injectHtml} = this\n if (injectHtml.length > 0) {\n store.injectTags(injectHtml, 'EMPShare')\n }\n }\n private injectFramework() {\n if (!this.op.empRuntime || !this.op.empRuntime.frameworkLib) return\n const {store, injectHtml} = this\n const {frameworkLib} = this.op.empRuntime\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n })\n }\n }\n private injectGlobalVal() {\n if (!this.op.empRuntime) return\n const {empRuntime} = this.op\n const {injectHtml} = this\n empRuntime.framework = Object.hasOwn(empRuntime, 'framework') ? empRuntime.framework : 'react'\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || (empRuntime.shareLib ? 'window' : '')\n\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${empRuntime.frameworkGlobal}',runtimeLib:'${empRuntime.runtimeGlobal}',framework:'${empRuntime.framework}'}`,\n })\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {framework, shareLib, runtimeGlobal, frameworkGlobal} = empRuntime\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' && !shareLib && 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 (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${frameworkGlobal}.${v.global}`\n }\n })\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n private setRuntimeLib() {\n if (!this.op.empRuntime) return\n\n const {runtimeLib, shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions>(\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 }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\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","import type {GlobalStore} from '@empjs/cli'\nimport {EmpShare} from './share'\nimport type {EMPPluginShareType} from './types'\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n const empShare = new EmpShare(o, store)\n empShare.setup()\n },\n }\n}\nexport default pluginRspackEmpShare\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,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KACrBf,EAAa,KAAKe,CAAa,EAC/BA,EAAgB,CAAC,EAErB,MAAW,MAAM,QAAQL,CAAC,EACxBA,EAAE,IAAIO,GAAM,CACV,GAAI,CAACA,EAAI,OAET,GADcA,EAAG,MAAM,GAAG,EAAE,CAAC,EAAE,SAAS,MAAM,EAE5CF,EAAc,MAAQE,EACtBF,EAAc,KAAO,UAChB,CACL,IAAMC,EAAUC,EAAG,MAAM3B,CAAG,GAAK,CAAC,EAC9B0B,EAAG,OAAS,GACdD,EAAc,OAASC,EAAG,CAAC,EAC3BD,EAAc,MAAQC,EAAG,CAAC,EAC1BD,EAAc,KAAO,OAErBA,EAAc,OAAS,GACvBA,EAAc,MAAQE,EACtBF,EAAc,KAAO,KAEzB,CACAf,EAAa,KAAKe,CAAa,EAC/BA,EAAgB,CAAC,CACnB,CAAC,EACQ,OAAOL,GAAM,UAAYA,EAAE,QACpCK,EAAc,MAAQL,EAAE,MACxBK,EAAc,OAASL,EAAE,OACzBK,EAAc,KAAOL,EAAE,KACvBV,EAAa,KAAKe,CAAa,EAC/BA,EAAgB,CAAC,EAErB,CAEAf,EAAa,IAAIU,GAAK,CAChBA,EAAE,OAAS,KACbhB,EAAW,KAAK,CACd,WAAY,CACV,IAAKgB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBhB,EAAW,KAAK,CACd,WAAY,CACV,KAAMgB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EKpNO,IAAMQ,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAChB,IAAIC,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ,ENXf,IAAOK,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","exp","EmpShare","op","store","injectHtml","frameworkLib","url","getRuntimeLib","empRuntime","shareGlobalName","externalsLib","framework","shareLib","runtimeGlobal","frameworkGlobal","externalRuntime","externals","key","value","externalReact","v","runtimeLib","EmpShareRemoteLibPlugin","o","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default","src_default","rspack_default"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/plugins/rspack/share.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts","../src/plugins/rspack/index.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, ExternalsItemType, ModuleFederationPluginOptions} from './types'\nimport {getRuntimeLib} from './utils'\nconst exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\nexport class EmpShare {\n private op: EMPPluginShareType\n private store: GlobalStore\n /**\n * 注入资源\n */\n private injectHtml: any[] = []\n /**\n * 兼容 shareLib\n */\n private externalsLib: ExternalsItemType[] = []\n constructor(op: EMPPluginShareType, store: GlobalStore) {\n this.op = op || {}\n this.store = store\n }\n setup() {\n this.setMF() // 设置 MF 配置\n this.injectGlobalVal() // 插入全局变量 方便emp外的项目调用\n this.injectFramework() // 插入ui框架库\n this.setShareLib() //兼容 emp Sharelib的共享模型设置\n this.setRuntimeLib() // 设置 MF SDK\n this.injectToHtml() //触发插入动作\n this.setExternal() // 设置 external 降低包体\n }\n private injectToHtml() {\n const {store, injectHtml} = this\n if (injectHtml.length > 0) {\n store.injectTags(injectHtml, 'EMPShare')\n }\n }\n private injectFramework() {\n if (!this.op.empRuntime || !this.op.empRuntime.frameworkLib) return\n const {store, injectHtml} = this\n const {frameworkLib} = this.op.empRuntime\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n })\n }\n }\n private injectGlobalVal() {\n if (!this.op.empRuntime) return\n const {empRuntime} = this.op\n const {injectHtml} = this\n empRuntime.framework = Object.hasOwn(empRuntime, 'framework') ? empRuntime.framework : 'react'\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || (empRuntime.shareLib ? 'window' : '')\n\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${empRuntime.frameworkGlobal}',runtimeLib:'${empRuntime.runtimeGlobal}',framework:'${empRuntime.framework}'}`,\n })\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {framework, shareLib, runtimeGlobal, frameworkGlobal} = empRuntime\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' && !shareLib && 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 (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${frameworkGlobal}.${v.global}`\n }\n })\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n private setRuntimeLib() {\n if (!this.op.empRuntime) return\n\n const {runtimeLib, shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions & {empRuntime: any}>(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n if (op.empRuntime) {\n delete op.empRuntime\n }\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\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","import type {GlobalStore} from '@empjs/cli'\nimport {EmpShare} from './share'\nimport type {EMPPluginShareType} from './types'\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n const empShare = new EmpShare(o, store)\n empShare.setup()\n },\n }\n}\nexport default pluginRspackEmpShare\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,CJFA,IAAME,EAAM,0BACCC,EAAN,KAAe,CACZ,GACA,MAIA,WAAoB,CAAC,EAIrB,aAAoC,CAA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S,GACvBA,EAAc,MAAQE,EACtBF,EAAc,KAAO,KAEzB,CACAf,EAAa,KAAKe,CAAa,EAC/BA,EAAgB,CAAC,CACnB,CAAC,EACQ,OAAOL,GAAM,UAAYA,EAAE,QACpCK,EAAc,MAAQL,EAAE,MACxBK,EAAc,OAASL,EAAE,OACzBK,EAAc,KAAOL,EAAE,KACvBV,EAAa,KAAKe,CAAa,EAC/BA,EAAgB,CAAC,EAErB,CAEAf,EAAa,IAAIU,GAAK,CAChBA,EAAE,OAAS,KACbhB,EAAW,KAAK,CACd,WAAY,CACV,IAAKgB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBhB,EAAW,KAAK,CACd,WAAY,CACV,KAAMgB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EKtNO,IAAMQ,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAChB,IAAIC,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ,ENXf,IAAOK,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","exp","EmpShare","op","store","injectHtml","frameworkLib","url","getRuntimeLib","empRuntime","shareGlobalName","externalsLib","framework","shareLib","runtimeGlobal","frameworkGlobal","externalRuntime","externals","key","value","externalReact","v","runtimeLib","EmpShareRemoteLibPlugin","o","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default","src_default","rspack_default"]}
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import{ModuleFederationPlugin as E}from"@module-federation/enhanced/rspack";var h="EMP_SHARE_RUNTIME";var b=n=>`data:text/javascript,${n}`;var d=n=>{let e=[`import '${n}'`].join(`
2
- `);return b(e)},m=class{options;constructor(e){this.options=e}apply(e){let{webpack:r}=e,{runtimeLib:i}=this.options;if(!i){let s=d("@empjs/share/library");new r.EntryPlugin(e.context,s,{name:void 0}).apply(e)}}};function y(n,e){return typeof n=="string"?`${n}/runtime${e==="development"?".development":""}.umd.js`:typeof n=="object"?e==="development"?n.dev:n.prod:""}var g=/^([0-9a-zA-Z_\s]+)@(.*)/,c=class{op;store;injectHtml=[];externalsLib=[];constructor(e,r){this.op=e||{},this.store=r}setup(){this.setMF(),this.injectGlobalVal(),this.injectFramework(),this.setShareLib(),this.setRuntimeLib(),this.injectToHtml(),this.setExternal()}injectToHtml(){let{store:e,injectHtml:r}=this;r.length>0&&e.injectTags(r,"EMPShare")}injectFramework(){if(!this.op.empRuntime||!this.op.empRuntime.frameworkLib)return;let{store:e,injectHtml:r}=this,{frameworkLib:i}=this.op.empRuntime;if(i){let s=y(i,e.mode);r.push({attributes:{src:s},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:r}=this;e.framework=Object.hasOwn(e,"framework")?e.framework:"react",e.runtimeGlobal=e.runtimeGlobal||h,e.frameworkGlobal=e.frameworkGlobal||(e.shareLib?"window":""),e.injectGlobalValToHtml!==!1&&r.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${e.frameworkGlobal}',runtimeLib:'${e.runtimeGlobal}',framework:'${e.framework}'}`})}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:r}=this,{empRuntime:i}=this.op,{framework:s,shareLib:o,runtimeGlobal:t,frameworkGlobal:a}=i,f={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},p={};for(let[l,u]of Object.entries(f))p[l]=`${t}.${u}`;if(s==="react"&&!o&&a){let l={react:"React","react-dom":"ReactDOM"};for(let[u,R]of Object.entries(l))p[u]=`${a}.${R}`}o&&r.map(l=>{l.type==="js"&&l.module&&l.global&&(p[l.module]=`${a}.${l.global}`)}),i.setExternals&&i.setExternals(p),e.chain.merge({externals:p})}setRuntimeLib(){if(!this.op.empRuntime)return;let{runtimeLib:e,shareLib:r}=this.op.empRuntime,{store:i,injectHtml:s}=this,{empRuntime:o}=this.op;e?e==="useFrameworkLib"&&!r||s.push({tagName:"script",pos:"head",attributes:{src:e}}):i.chain.plugin("plugin-emp-share-framework").use(m,[o])}setMF(){let e=this.op,{store:r}=this;if(e.name){let i=r.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},e);r.chain.plugin("plugin-emp-share").use(E,[i])}}setShareLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{externalsLib:r,injectHtml:i}=this;if(e&&typeof e=="object"){for(let[s,o]of Object.entries(e)){let t={};if(t.module=s,typeof o=="string"){let a=o.match(g)||[];a.length>0?(t.global=a[1],t.entry=a[2],t.type="js",r.push(t),t={}):(t.global="",t.entry=o,t.type="js",r.push(t),t={})}else Array.isArray(o)?o.map(a=>{if(!a)return;if(a.split("?")[0].endsWith(".css"))t.entry=a,t.type="css";else{let p=a.match(g)||[];p.length>0?(t.global=p[1],t.entry=p[2],t.type="js"):(t.global="",t.entry=a,t.type="js")}r.push(t),t={}}):typeof o=="object"&&o.entry&&(t.entry=o.entry,t.global=o.global,t.type=o.type,r.push(t),t={})}r.map(s=>{s.type==="js"?i.push({attributes:{src:s.entry},tagName:"script"}):s.type==="css"&&i.push({attributes:{href:s.entry,rel:"stylesheet"},tagName:"link"})})}}};var S=(n={})=>({name:"@empjs/share",async rsConfig(e){new c(n,e).setup()}}),j=S;var F=j;export{F as default,j as pluginRspackEmpShare};
2
+ `);return b(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:r}=e,{runtimeLib:i}=this.options;if(!i){let s=d("@empjs/share/library");new r.EntryPlugin(e.context,s,{name:void 0}).apply(e)}}};function y(n,e){return typeof n=="string"?`${n}/runtime${e==="development"?".development":""}.umd.js`:typeof n=="object"?e==="development"?n.dev:n.prod:""}var g=/^([0-9a-zA-Z_\s]+)@(.*)/,c=class{op;store;injectHtml=[];externalsLib=[];constructor(e,r){this.op=e||{},this.store=r}setup(){this.setMF(),this.injectGlobalVal(),this.injectFramework(),this.setShareLib(),this.setRuntimeLib(),this.injectToHtml(),this.setExternal()}injectToHtml(){let{store:e,injectHtml:r}=this;r.length>0&&e.injectTags(r,"EMPShare")}injectFramework(){if(!this.op.empRuntime||!this.op.empRuntime.frameworkLib)return;let{store:e,injectHtml:r}=this,{frameworkLib:i}=this.op.empRuntime;if(i){let s=y(i,e.mode);r.push({attributes:{src:s},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:r}=this;e.framework=Object.hasOwn(e,"framework")?e.framework:"react",e.runtimeGlobal=e.runtimeGlobal||h,e.frameworkGlobal=e.frameworkGlobal||(e.shareLib?"window":""),e.injectGlobalValToHtml!==!1&&r.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${e.frameworkGlobal}',runtimeLib:'${e.runtimeGlobal}',framework:'${e.framework}'}`})}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:r}=this,{empRuntime:i}=this.op,{framework:s,shareLib:o,runtimeGlobal:t,frameworkGlobal:a}=i,f={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},p={};for(let[m,u]of Object.entries(f))p[m]=`${t}.${u}`;if(s==="react"&&!o&&a){let m={react:"React","react-dom":"ReactDOM"};for(let[u,R]of Object.entries(m))p[u]=`${a}.${R}`}o&&r.map(m=>{m.type==="js"&&m.module&&m.global&&(p[m.module]=`${a}.${m.global}`)}),i.setExternals&&i.setExternals(p),e.chain.merge({externals:p})}setRuntimeLib(){if(!this.op.empRuntime)return;let{runtimeLib:e,shareLib:r}=this.op.empRuntime,{store:i,injectHtml:s}=this,{empRuntime:o}=this.op;e?e==="useFrameworkLib"&&!r||s.push({tagName:"script",pos:"head",attributes:{src:e}}):i.chain.plugin("plugin-emp-share-framework").use(l,[o])}setMF(){let e=this.op,{store:r}=this;if(e.name){let i=r.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},e);i.empRuntime&&delete i.empRuntime,r.chain.plugin("plugin-emp-share").use(E,[i])}}setShareLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{externalsLib:r,injectHtml:i}=this;if(e&&typeof e=="object"){for(let[s,o]of Object.entries(e)){let t={};if(t.module=s,typeof o=="string"){let a=o.match(g)||[];a.length>0?(t.global=a[1],t.entry=a[2],t.type="js",r.push(t),t={}):(t.global="",t.entry=o,t.type="js",r.push(t),t={})}else Array.isArray(o)?o.map(a=>{if(!a)return;if(a.split("?")[0].endsWith(".css"))t.entry=a,t.type="css";else{let p=a.match(g)||[];p.length>0?(t.global=p[1],t.entry=p[2],t.type="js"):(t.global="",t.entry=a,t.type="js")}r.push(t),t={}}):typeof o=="object"&&o.entry&&(t.entry=o.entry,t.global=o.global,t.type=o.type,r.push(t),t={})}r.map(s=>{s.type==="js"?i.push({attributes:{src:s.entry},tagName:"script"}):s.type==="css"&&i.push({attributes:{href:s.entry,rel:"stylesheet"},tagName:"link"})})}}};var S=(n={})=>({name:"@empjs/share",async rsConfig(e){new c(n,e).setup()}}),j=S;var F=j;export{F as default,j as pluginRspackEmpShare};
3
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugins/rspack/share.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts","../src/plugins/rspack/index.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, ExternalsItemType, ModuleFederationPluginOptions} from './types'\nimport {getRuntimeLib} from './utils'\nconst exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\nexport class EmpShare {\n private op: EMPPluginShareType\n private store: GlobalStore\n /**\n * 注入资源\n */\n private injectHtml: any[] = []\n /**\n * 兼容 shareLib\n */\n private externalsLib: ExternalsItemType[] = []\n constructor(op: EMPPluginShareType, store: GlobalStore) {\n this.op = op || {}\n this.store = store\n }\n setup() {\n this.setMF() // 设置 MF 配置\n this.injectGlobalVal() // 插入全局变量 方便emp外的项目调用\n this.injectFramework() // 插入ui框架库\n this.setShareLib() //兼容 emp Sharelib的共享模型设置\n this.setRuntimeLib() // 设置 MF SDK\n this.injectToHtml() //触发插入动作\n this.setExternal() // 设置 external 降低包体\n }\n private injectToHtml() {\n const {store, injectHtml} = this\n if (injectHtml.length > 0) {\n store.injectTags(injectHtml, 'EMPShare')\n }\n }\n private injectFramework() {\n if (!this.op.empRuntime || !this.op.empRuntime.frameworkLib) return\n const {store, injectHtml} = this\n const {frameworkLib} = this.op.empRuntime\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n })\n }\n }\n private injectGlobalVal() {\n if (!this.op.empRuntime) return\n const {empRuntime} = this.op\n const {injectHtml} = this\n empRuntime.framework = Object.hasOwn(empRuntime, 'framework') ? empRuntime.framework : 'react'\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || (empRuntime.shareLib ? 'window' : '')\n\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${empRuntime.frameworkGlobal}',runtimeLib:'${empRuntime.runtimeGlobal}',framework:'${empRuntime.framework}'}`,\n })\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {framework, shareLib, runtimeGlobal, frameworkGlobal} = empRuntime\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' && !shareLib && 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 (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${frameworkGlobal}.${v.global}`\n }\n })\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n private setRuntimeLib() {\n if (!this.op.empRuntime) return\n\n const {runtimeLib, shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions>(\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 }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\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","import type {GlobalStore} from '@empjs/cli'\nimport {EmpShare} from './share'\nimport type {EMPPluginShareType} from './types'\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n const empShare = new EmpShare(o, store)\n empShare.setup()\n },\n }\n}\nexport default pluginRspackEmpShare\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,CAC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in","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","exp","EmpShare","op","store","injectHtml","frameworkLib","url","getRuntimeLib","empRuntime","shareGlobalName","externalsLib","framework","shareLib","runtimeGlobal","frameworkGlobal","externalRuntime","externals","key","value","externalReact","v","runtimeLib","EmpShareRemoteLibPlugin","o","ModuleFederationPlugin","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default","src_default","rspack_default"]}
1
+ {"version":3,"sources":["../src/plugins/rspack/share.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts","../src/plugins/rspack/index.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, ExternalsItemType, ModuleFederationPluginOptions} from './types'\nimport {getRuntimeLib} from './utils'\nconst exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\nexport class EmpShare {\n private op: EMPPluginShareType\n private store: GlobalStore\n /**\n * 注入资源\n */\n private injectHtml: any[] = []\n /**\n * 兼容 shareLib\n */\n private externalsLib: ExternalsItemType[] = []\n constructor(op: EMPPluginShareType, store: GlobalStore) {\n this.op = op || {}\n this.store = store\n }\n setup() {\n this.setMF() // 设置 MF 配置\n this.injectGlobalVal() // 插入全局变量 方便emp外的项目调用\n this.injectFramework() // 插入ui框架库\n this.setShareLib() //兼容 emp Sharelib的共享模型设置\n this.setRuntimeLib() // 设置 MF SDK\n this.injectToHtml() //触发插入动作\n this.setExternal() // 设置 external 降低包体\n }\n private injectToHtml() {\n const {store, injectHtml} = this\n if (injectHtml.length > 0) {\n store.injectTags(injectHtml, 'EMPShare')\n }\n }\n private injectFramework() {\n if (!this.op.empRuntime || !this.op.empRuntime.frameworkLib) return\n const {store, injectHtml} = this\n const {frameworkLib} = this.op.empRuntime\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n })\n }\n }\n private injectGlobalVal() {\n if (!this.op.empRuntime) return\n const {empRuntime} = this.op\n const {injectHtml} = this\n empRuntime.framework = Object.hasOwn(empRuntime, 'framework') ? empRuntime.framework : 'react'\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || (empRuntime.shareLib ? 'window' : '')\n\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${empRuntime.frameworkGlobal}',runtimeLib:'${empRuntime.runtimeGlobal}',framework:'${empRuntime.framework}'}`,\n })\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {framework, shareLib, runtimeGlobal, frameworkGlobal} = empRuntime\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' && !shareLib && 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 (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${frameworkGlobal}.${v.global}`\n }\n })\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n private setRuntimeLib() {\n if (!this.op.empRuntime) return\n\n const {runtimeLib, shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions & {empRuntime: any}>(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n if (op.empRuntime) {\n delete op.empRuntime\n }\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\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","import type {GlobalStore} from '@empjs/cli'\nimport {EmpShare} from './share'\nimport type {EMPPluginShareType} from './types'\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n const empShare = new EmpShare(o, store)\n empShare.setup()\n },\n }\n}\nexport default pluginRspackEmpShare\n","import {default as pluginRspackEmpShare} from 'src/plugins/rspack'\nexport default pluginRspackEmpShare\nexport {pluginRspackEmpShare}\n"],"mappings":"AACA,OAAQ,0BAAAA,MAA6B,qCCD9B,IAAMC,EAAkB,oBCAxB,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GCG9E,IAAMC,EAAuBC,GAAO,CAClC,IAAMC,EAAU,CAAC,WAAWD,CAAG,GAAG,EAAE,KAAK;AAAA,CAAI,EAC7C,OAAOE,EAAWD,CAAO,CAC3B,EACaE,EAAN,KAA8B,CACnC,QACA,YAAYC,EAA4B,CACtC,KAAK,QAAUA,CACjB,CACA,MAAMC,EAAoB,CACxB,GAAM,CAAC,QAAAC,CAAO,EAAID,EACZ,CAAC,WAAAE,CAAU,EAAI,KAAK,QAC1B,GAAI,CAACA,EAAY,CACf,IAAMC,EAAQT,EAAqB,sBAAsB,EACzD,IAAIO,EAAQ,YAAYD,EAAS,QAASG,EAAO,CAC/C,KAAM,MACR,CAAC,EAAE,MAAMH,CAAQ,CACnB,CACF,CACF,ECrBO,SAASI,EAAcC,EAA8CC,EAAc,CACxF,OAAI,OAAOD,GAAS,SAAiB,GAAGA,CAAI,WAAWC,IAAS,cAAgB,eAAiB,EAAE,UAC1F,OAAOD,GAAS,SACnBC,IAAS,cAAsBD,EAAK,IAC5BA,EAAK,KAEZ,EACT,CJFA,IAAME,EAAM,0BACCC,EAAN,KAAe,CACZ,GACA,MAIA,WAAoB,CAAC,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,KAAO,OAErBA,EAAc,OAAS,GACvBA,EAAc,MAAQE,EACtBF,EAAc,KAAO,KAEzB,CACAhB,EAAa,KAAKgB,CAAa,EAC/BA,EAAgB,CAAC,CACnB,CAAC,EACQ,OAAON,GAAM,UAAYA,EAAE,QACpCM,EAAc,MAAQN,EAAE,MACxBM,EAAc,OAASN,EAAE,OACzBM,EAAc,KAAON,EAAE,KACvBV,EAAa,KAAKgB,CAAa,EAC/BA,EAAgB,CAAC,EAErB,CAEAhB,EAAa,IAAIU,GAAK,CAChBA,EAAE,OAAS,KACbhB,EAAW,KAAK,CACd,WAAY,CACV,IAAKgB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBhB,EAAW,KAAK,CACd,WAAY,CACV,KAAMgB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EKtNO,IAAMS,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAChB,IAAIC,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ,ECXf,IAAOK,EAAQC","names":["ModuleFederationPlugin","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","exp","EmpShare","op","store","injectHtml","frameworkLib","url","getRuntimeLib","empRuntime","shareGlobalName","externalsLib","framework","shareLib","runtimeGlobal","frameworkGlobal","externalRuntime","externals","key","value","externalReact","v","runtimeLib","EmpShareRemoteLibPlugin","o","ModuleFederationPlugin","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default","src_default","rspack_default"]}
package/dist/rspack.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var f=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var w=(i,e)=>{for(var t in e)f(i,t,{get:e[t],enumerable:!0})},P=(i,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of k(e))!x.call(i,o)&&o!==t&&f(i,o,{get:()=>e[o],enumerable:!(s=S(e,o))||s.enumerable});return i};var M=i=>P(f({},"__esModule",{value:!0}),i);var H={};w(H,{default:()=>G,pluginRspackEmpShare:()=>d});module.exports=M(H);var R=require("@module-federation/enhanced/rspack");var b="EMP_SHARE_RUNTIME";var y=i=>`data:text/javascript,${i}`;var L=i=>{let e=[`import '${i}'`].join(`
2
- `);return y(e)},m=class{options;constructor(e){this.options=e}apply(e){let{webpack:t}=e,{runtimeLib:s}=this.options;if(!s){let o=L("@empjs/share/library");new t.EntryPlugin(e.context,o,{name:void 0}).apply(e)}}};function g(i,e){return typeof i=="string"?`${i}/runtime${e==="development"?".development":""}.umd.js`:typeof i=="object"?e==="development"?i.dev:i.prod:""}var j=/^([0-9a-zA-Z_\s]+)@(.*)/,c=class{op;store;injectHtml=[];externalsLib=[];constructor(e,t){this.op=e||{},this.store=t}setup(){this.setMF(),this.injectGlobalVal(),this.injectFramework(),this.setShareLib(),this.setRuntimeLib(),this.injectToHtml(),this.setExternal()}injectToHtml(){let{store:e,injectHtml:t}=this;t.length>0&&e.injectTags(t,"EMPShare")}injectFramework(){if(!this.op.empRuntime||!this.op.empRuntime.frameworkLib)return;let{store:e,injectHtml:t}=this,{frameworkLib:s}=this.op.empRuntime;if(s){let o=g(s,e.mode);t.push({attributes:{src:o},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:t}=this;e.framework=Object.hasOwn(e,"framework")?e.framework:"react",e.runtimeGlobal=e.runtimeGlobal||b,e.frameworkGlobal=e.frameworkGlobal||(e.shareLib?"window":""),e.injectGlobalValToHtml!==!1&&t.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${e.frameworkGlobal}',runtimeLib:'${e.runtimeGlobal}',framework:'${e.framework}'}`})}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:t}=this,{empRuntime:s}=this.op,{framework:o,shareLib:n,runtimeGlobal:r,frameworkGlobal:a}=s,h={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},p={};for(let[l,u]of Object.entries(h))p[l]=`${r}.${u}`;if(o==="react"&&!n&&a){let l={react:"React","react-dom":"ReactDOM"};for(let[u,E]of Object.entries(l))p[u]=`${a}.${E}`}n&&t.map(l=>{l.type==="js"&&l.module&&l.global&&(p[l.module]=`${a}.${l.global}`)}),s.setExternals&&s.setExternals(p),e.chain.merge({externals:p})}setRuntimeLib(){if(!this.op.empRuntime)return;let{runtimeLib:e,shareLib:t}=this.op.empRuntime,{store:s,injectHtml:o}=this,{empRuntime:n}=this.op;e?e==="useFrameworkLib"&&!t||o.push({tagName:"script",pos:"head",attributes:{src:e}}):s.chain.plugin("plugin-emp-share-framework").use(m,[n])}setMF(){let e=this.op,{store:t}=this;if(e.name){let s=t.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},e);t.chain.plugin("plugin-emp-share").use(R.ModuleFederationPlugin,[s])}}setShareLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{externalsLib:t,injectHtml:s}=this;if(e&&typeof e=="object"){for(let[o,n]of Object.entries(e)){let r={};if(r.module=o,typeof n=="string"){let a=n.match(j)||[];a.length>0?(r.global=a[1],r.entry=a[2],r.type="js",t.push(r),r={}):(r.global="",r.entry=n,r.type="js",t.push(r),r={})}else Array.isArray(n)?n.map(a=>{if(!a)return;if(a.split("?")[0].endsWith(".css"))r.entry=a,r.type="css";else{let p=a.match(j)||[];p.length>0?(r.global=p[1],r.entry=p[2],r.type="js"):(r.global="",r.entry=a,r.type="js")}t.push(r),r={}}):typeof n=="object"&&n.entry&&(r.entry=n.entry,r.global=n.global,r.type=n.type,t.push(r),r={})}t.map(o=>{o.type==="js"?s.push({attributes:{src:o.entry},tagName:"script"}):o.type==="css"&&s.push({attributes:{href:o.entry,rel:"stylesheet"},tagName:"link"})})}}};var d=(i={})=>({name:"@empjs/share",async rsConfig(e){new c(i,e).setup()}}),G=d;0&&(module.exports={pluginRspackEmpShare});
1
+ "use strict";var f=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var w=(r,e)=>{for(var t in e)f(r,t,{get:e[t],enumerable:!0})},P=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of k(e))!x.call(r,s)&&s!==t&&f(r,s,{get:()=>e[s],enumerable:!(o=S(e,s))||o.enumerable});return r};var M=r=>P(f({},"__esModule",{value:!0}),r);var H={};w(H,{default:()=>G,pluginRspackEmpShare:()=>d});module.exports=M(H);var R=require("@module-federation/enhanced/rspack");var b="EMP_SHARE_RUNTIME";var y=r=>`data:text/javascript,${r}`;var L=r=>{let e=[`import '${r}'`].join(`
2
+ `);return y(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:t}=e,{runtimeLib:o}=this.options;if(!o){let s=L("@empjs/share/library");new t.EntryPlugin(e.context,s,{name:void 0}).apply(e)}}};function g(r,e){return typeof r=="string"?`${r}/runtime${e==="development"?".development":""}.umd.js`:typeof r=="object"?e==="development"?r.dev:r.prod:""}var j=/^([0-9a-zA-Z_\s]+)@(.*)/,c=class{op;store;injectHtml=[];externalsLib=[];constructor(e,t){this.op=e||{},this.store=t}setup(){this.setMF(),this.injectGlobalVal(),this.injectFramework(),this.setShareLib(),this.setRuntimeLib(),this.injectToHtml(),this.setExternal()}injectToHtml(){let{store:e,injectHtml:t}=this;t.length>0&&e.injectTags(t,"EMPShare")}injectFramework(){if(!this.op.empRuntime||!this.op.empRuntime.frameworkLib)return;let{store:e,injectHtml:t}=this,{frameworkLib:o}=this.op.empRuntime;if(o){let s=g(o,e.mode);t.push({attributes:{src:s},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:t}=this;e.framework=Object.hasOwn(e,"framework")?e.framework:"react",e.runtimeGlobal=e.runtimeGlobal||b,e.frameworkGlobal=e.frameworkGlobal||(e.shareLib?"window":""),e.injectGlobalValToHtml!==!1&&t.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${e.frameworkGlobal}',runtimeLib:'${e.runtimeGlobal}',framework:'${e.framework}'}`})}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:t}=this,{empRuntime:o}=this.op,{framework:s,shareLib:n,runtimeGlobal:i,frameworkGlobal:a}=o,h={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},p={};for(let[m,u]of Object.entries(h))p[m]=`${i}.${u}`;if(s==="react"&&!n&&a){let m={react:"React","react-dom":"ReactDOM"};for(let[u,E]of Object.entries(m))p[u]=`${a}.${E}`}n&&t.map(m=>{m.type==="js"&&m.module&&m.global&&(p[m.module]=`${a}.${m.global}`)}),o.setExternals&&o.setExternals(p),e.chain.merge({externals:p})}setRuntimeLib(){if(!this.op.empRuntime)return;let{runtimeLib:e,shareLib:t}=this.op.empRuntime,{store:o,injectHtml:s}=this,{empRuntime:n}=this.op;e?e==="useFrameworkLib"&&!t||s.push({tagName:"script",pos:"head",attributes:{src:e}}):o.chain.plugin("plugin-emp-share-framework").use(l,[n])}setMF(){let e=this.op,{store:t}=this;if(e.name){let o=t.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},e);o.empRuntime&&delete o.empRuntime,t.chain.plugin("plugin-emp-share").use(R.ModuleFederationPlugin,[o])}}setShareLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{externalsLib:t,injectHtml:o}=this;if(e&&typeof e=="object"){for(let[s,n]of Object.entries(e)){let i={};if(i.module=s,typeof n=="string"){let a=n.match(j)||[];a.length>0?(i.global=a[1],i.entry=a[2],i.type="js",t.push(i),i={}):(i.global="",i.entry=n,i.type="js",t.push(i),i={})}else Array.isArray(n)?n.map(a=>{if(!a)return;if(a.split("?")[0].endsWith(".css"))i.entry=a,i.type="css";else{let p=a.match(j)||[];p.length>0?(i.global=p[1],i.entry=p[2],i.type="js"):(i.global="",i.entry=a,i.type="js")}t.push(i),i={}}):typeof n=="object"&&n.entry&&(i.entry=n.entry,i.global=n.global,i.type=n.type,t.push(i),i={})}t.map(s=>{s.type==="js"?o.push({attributes:{src:s.entry},tagName:"script"}):s.type==="css"&&o.push({attributes:{href:s.entry,rel:"stylesheet"},tagName:"link"})})}}};var d=(r={})=>({name:"@empjs/share",async rsConfig(e){new c(r,e).setup()}}),G=d;0&&(module.exports={pluginRspackEmpShare});
3
3
  //# sourceMappingURL=rspack.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugins/rspack/index.ts","../src/plugins/rspack/share.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 {EmpShare} from './share'\nimport type {EMPPluginShareType} from './types'\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n const empShare = new EmpShare(o, store)\n empShare.setup()\n },\n }\n}\nexport default 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, ExternalsItemType, ModuleFederationPluginOptions} from './types'\nimport {getRuntimeLib} from './utils'\nconst exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\nexport class EmpShare {\n private op: EMPPluginShareType\n private store: GlobalStore\n /**\n * 注入资源\n */\n private injectHtml: any[] = []\n /**\n * 兼容 shareLib\n */\n private externalsLib: ExternalsItemType[] = []\n constructor(op: EMPPluginShareType, store: GlobalStore) {\n this.op = op || {}\n this.store = store\n }\n setup() {\n this.setMF() // 设置 MF 配置\n this.injectGlobalVal() // 插入全局变量 方便emp外的项目调用\n this.injectFramework() // 插入ui框架库\n this.setShareLib() //兼容 emp Sharelib的共享模型设置\n this.setRuntimeLib() // 设置 MF SDK\n this.injectToHtml() //触发插入动作\n this.setExternal() // 设置 external 降低包体\n }\n private injectToHtml() {\n const {store, injectHtml} = this\n if (injectHtml.length > 0) {\n store.injectTags(injectHtml, 'EMPShare')\n }\n }\n private injectFramework() {\n if (!this.op.empRuntime || !this.op.empRuntime.frameworkLib) return\n const {store, injectHtml} = this\n const {frameworkLib} = this.op.empRuntime\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n })\n }\n }\n private injectGlobalVal() {\n if (!this.op.empRuntime) return\n const {empRuntime} = this.op\n const {injectHtml} = this\n empRuntime.framework = Object.hasOwn(empRuntime, 'framework') ? empRuntime.framework : 'react'\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || (empRuntime.shareLib ? 'window' : '')\n\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${empRuntime.frameworkGlobal}',runtimeLib:'${empRuntime.runtimeGlobal}',framework:'${empRuntime.framework}'}`,\n })\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {framework, shareLib, runtimeGlobal, frameworkGlobal} = empRuntime\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' && !shareLib && 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 (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${frameworkGlobal}.${v.global}`\n }\n })\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n private setRuntimeLib() {\n if (!this.op.empRuntime) return\n\n const {runtimeLib, shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions>(\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 }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\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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AAc,MAAQC,EAAG,CAAC,EAC1BD,EAAc,KAAO,OAErBA,EAAc,OAAS,GACvBA,EAAc,MAAQE,EACtBF,EAAc,KAAO,KAEzB,CACAf,EAAa,KAAKe,CAAa,EAC/BA,EAAgB,CAAC,CACnB,CAAC,EACQ,OAAOL,GAAM,UAAYA,EAAE,QACpCK,EAAc,MAAQL,EAAE,MACxBK,EAAc,OAASL,EAAE,OACzBK,EAAc,KAAOL,EAAE,KACvBV,EAAa,KAAKe,CAAa,EAC/BA,EAAgB,CAAC,EAErB,CAEAf,EAAa,IAAIU,GAAK,CAChBA,EAAE,OAAS,KACbhB,EAAW,KAAK,CACd,WAAY,CACV,IAAKgB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBhB,EAAW,KAAK,CACd,WAAY,CACV,KAAMgB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EDpNO,IAAMQ,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAChB,IAAIC,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ","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","exp","EmpShare","op","store","injectHtml","frameworkLib","url","getRuntimeLib","empRuntime","shareGlobalName","externalsLib","framework","shareLib","runtimeGlobal","frameworkGlobal","externalRuntime","externals","key","value","externalReact","v","runtimeLib","EmpShareRemoteLibPlugin","o","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default"]}
1
+ {"version":3,"sources":["../src/plugins/rspack/index.ts","../src/plugins/rspack/share.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 {EmpShare} from './share'\nimport type {EMPPluginShareType} from './types'\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n const empShare = new EmpShare(o, store)\n empShare.setup()\n },\n }\n}\nexport default 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, ExternalsItemType, ModuleFederationPluginOptions} from './types'\nimport {getRuntimeLib} from './utils'\nconst exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\nexport class EmpShare {\n private op: EMPPluginShareType\n private store: GlobalStore\n /**\n * 注入资源\n */\n private injectHtml: any[] = []\n /**\n * 兼容 shareLib\n */\n private externalsLib: ExternalsItemType[] = []\n constructor(op: EMPPluginShareType, store: GlobalStore) {\n this.op = op || {}\n this.store = store\n }\n setup() {\n this.setMF() // 设置 MF 配置\n this.injectGlobalVal() // 插入全局变量 方便emp外的项目调用\n this.injectFramework() // 插入ui框架库\n this.setShareLib() //兼容 emp Sharelib的共享模型设置\n this.setRuntimeLib() // 设置 MF SDK\n this.injectToHtml() //触发插入动作\n this.setExternal() // 设置 external 降低包体\n }\n private injectToHtml() {\n const {store, injectHtml} = this\n if (injectHtml.length > 0) {\n store.injectTags(injectHtml, 'EMPShare')\n }\n }\n private injectFramework() {\n if (!this.op.empRuntime || !this.op.empRuntime.frameworkLib) return\n const {store, injectHtml} = this\n const {frameworkLib} = this.op.empRuntime\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n })\n }\n }\n private injectGlobalVal() {\n if (!this.op.empRuntime) return\n const {empRuntime} = this.op\n const {injectHtml} = this\n empRuntime.framework = Object.hasOwn(empRuntime, 'framework') ? empRuntime.framework : 'react'\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || (empRuntime.shareLib ? 'window' : '')\n\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${empRuntime.frameworkGlobal}',runtimeLib:'${empRuntime.runtimeGlobal}',framework:'${empRuntime.framework}'}`,\n })\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {framework, shareLib, runtimeGlobal, frameworkGlobal} = empRuntime\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' && !shareLib && 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 (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${frameworkGlobal}.${v.global}`\n }\n })\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n private setRuntimeLib() {\n if (!this.op.empRuntime) return\n\n const {runtimeLib, shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions & {empRuntime: any}>(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n if (op.empRuntime) {\n delete op.empRuntime\n }\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\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,oBCAx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,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EDtNO,IAAMQ,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAChB,IAAIC,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ","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","exp","EmpShare","op","store","injectHtml","frameworkLib","url","getRuntimeLib","empRuntime","shareGlobalName","externalsLib","framework","shareLib","runtimeGlobal","frameworkGlobal","externalRuntime","externals","key","value","externalReact","v","runtimeLib","EmpShareRemoteLibPlugin","o","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default"]}
package/dist/rspack.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import{ModuleFederationPlugin as d}from"@module-federation/enhanced/rspack";var h="EMP_SHARE_RUNTIME";var b=n=>`data:text/javascript,${n}`;var R=n=>{let e=[`import '${n}'`].join(`
2
- `);return b(e)},m=class{options;constructor(e){this.options=e}apply(e){let{webpack:r}=e,{runtimeLib:i}=this.options;if(!i){let s=R("@empjs/share/library");new r.EntryPlugin(e.context,s,{name:void 0}).apply(e)}}};function y(n,e){return typeof n=="string"?`${n}/runtime${e==="development"?".development":""}.umd.js`:typeof n=="object"?e==="development"?n.dev:n.prod:""}var g=/^([0-9a-zA-Z_\s]+)@(.*)/,c=class{op;store;injectHtml=[];externalsLib=[];constructor(e,r){this.op=e||{},this.store=r}setup(){this.setMF(),this.injectGlobalVal(),this.injectFramework(),this.setShareLib(),this.setRuntimeLib(),this.injectToHtml(),this.setExternal()}injectToHtml(){let{store:e,injectHtml:r}=this;r.length>0&&e.injectTags(r,"EMPShare")}injectFramework(){if(!this.op.empRuntime||!this.op.empRuntime.frameworkLib)return;let{store:e,injectHtml:r}=this,{frameworkLib:i}=this.op.empRuntime;if(i){let s=y(i,e.mode);r.push({attributes:{src:s},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:r}=this;e.framework=Object.hasOwn(e,"framework")?e.framework:"react",e.runtimeGlobal=e.runtimeGlobal||h,e.frameworkGlobal=e.frameworkGlobal||(e.shareLib?"window":""),e.injectGlobalValToHtml!==!1&&r.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${e.frameworkGlobal}',runtimeLib:'${e.runtimeGlobal}',framework:'${e.framework}'}`})}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:r}=this,{empRuntime:i}=this.op,{framework:s,shareLib:o,runtimeGlobal:t,frameworkGlobal:a}=i,f={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},p={};for(let[l,u]of Object.entries(f))p[l]=`${t}.${u}`;if(s==="react"&&!o&&a){let l={react:"React","react-dom":"ReactDOM"};for(let[u,j]of Object.entries(l))p[u]=`${a}.${j}`}o&&r.map(l=>{l.type==="js"&&l.module&&l.global&&(p[l.module]=`${a}.${l.global}`)}),i.setExternals&&i.setExternals(p),e.chain.merge({externals:p})}setRuntimeLib(){if(!this.op.empRuntime)return;let{runtimeLib:e,shareLib:r}=this.op.empRuntime,{store:i,injectHtml:s}=this,{empRuntime:o}=this.op;e?e==="useFrameworkLib"&&!r||s.push({tagName:"script",pos:"head",attributes:{src:e}}):i.chain.plugin("plugin-emp-share-framework").use(m,[o])}setMF(){let e=this.op,{store:r}=this;if(e.name){let i=r.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},e);r.chain.plugin("plugin-emp-share").use(d,[i])}}setShareLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{externalsLib:r,injectHtml:i}=this;if(e&&typeof e=="object"){for(let[s,o]of Object.entries(e)){let t={};if(t.module=s,typeof o=="string"){let a=o.match(g)||[];a.length>0?(t.global=a[1],t.entry=a[2],t.type="js",r.push(t),t={}):(t.global="",t.entry=o,t.type="js",r.push(t),t={})}else Array.isArray(o)?o.map(a=>{if(!a)return;if(a.split("?")[0].endsWith(".css"))t.entry=a,t.type="css";else{let p=a.match(g)||[];p.length>0?(t.global=p[1],t.entry=p[2],t.type="js"):(t.global="",t.entry=a,t.type="js")}r.push(t),t={}}):typeof o=="object"&&o.entry&&(t.entry=o.entry,t.global=o.global,t.type=o.type,r.push(t),t={})}r.map(s=>{s.type==="js"?i.push({attributes:{src:s.entry},tagName:"script"}):s.type==="css"&&i.push({attributes:{href:s.entry,rel:"stylesheet"},tagName:"link"})})}}};var E=(n={})=>({name:"@empjs/share",async rsConfig(e){new c(n,e).setup()}}),$=E;export{$ as default,E as pluginRspackEmpShare};
2
+ `);return b(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:i}=e,{runtimeLib:r}=this.options;if(!r){let s=R("@empjs/share/library");new i.EntryPlugin(e.context,s,{name:void 0}).apply(e)}}};function y(n,e){return typeof n=="string"?`${n}/runtime${e==="development"?".development":""}.umd.js`:typeof n=="object"?e==="development"?n.dev:n.prod:""}var g=/^([0-9a-zA-Z_\s]+)@(.*)/,c=class{op;store;injectHtml=[];externalsLib=[];constructor(e,i){this.op=e||{},this.store=i}setup(){this.setMF(),this.injectGlobalVal(),this.injectFramework(),this.setShareLib(),this.setRuntimeLib(),this.injectToHtml(),this.setExternal()}injectToHtml(){let{store:e,injectHtml:i}=this;i.length>0&&e.injectTags(i,"EMPShare")}injectFramework(){if(!this.op.empRuntime||!this.op.empRuntime.frameworkLib)return;let{store:e,injectHtml:i}=this,{frameworkLib:r}=this.op.empRuntime;if(r){let s=y(r,e.mode);i.push({attributes:{src:s},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:i}=this;e.framework=Object.hasOwn(e,"framework")?e.framework:"react",e.runtimeGlobal=e.runtimeGlobal||h,e.frameworkGlobal=e.frameworkGlobal||(e.shareLib?"window":""),e.injectGlobalValToHtml!==!1&&i.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${e.frameworkGlobal}',runtimeLib:'${e.runtimeGlobal}',framework:'${e.framework}'}`})}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:i}=this,{empRuntime:r}=this.op,{framework:s,shareLib:o,runtimeGlobal:t,frameworkGlobal:a}=r,f={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},p={};for(let[m,u]of Object.entries(f))p[m]=`${t}.${u}`;if(s==="react"&&!o&&a){let m={react:"React","react-dom":"ReactDOM"};for(let[u,j]of Object.entries(m))p[u]=`${a}.${j}`}o&&i.map(m=>{m.type==="js"&&m.module&&m.global&&(p[m.module]=`${a}.${m.global}`)}),r.setExternals&&r.setExternals(p),e.chain.merge({externals:p})}setRuntimeLib(){if(!this.op.empRuntime)return;let{runtimeLib:e,shareLib:i}=this.op.empRuntime,{store:r,injectHtml:s}=this,{empRuntime:o}=this.op;e?e==="useFrameworkLib"&&!i||s.push({tagName:"script",pos:"head",attributes:{src:e}}):r.chain.plugin("plugin-emp-share-framework").use(l,[o])}setMF(){let e=this.op,{store:i}=this;if(e.name){let r=i.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},e);r.empRuntime&&delete r.empRuntime,i.chain.plugin("plugin-emp-share").use(d,[r])}}setShareLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{externalsLib:i,injectHtml:r}=this;if(e&&typeof e=="object"){for(let[s,o]of Object.entries(e)){let t={};if(t.module=s,typeof o=="string"){let a=o.match(g)||[];a.length>0?(t.global=a[1],t.entry=a[2],t.type="js",i.push(t),t={}):(t.global="",t.entry=o,t.type="js",i.push(t),t={})}else Array.isArray(o)?o.map(a=>{if(!a)return;if(a.split("?")[0].endsWith(".css"))t.entry=a,t.type="css";else{let p=a.match(g)||[];p.length>0?(t.global=p[1],t.entry=p[2],t.type="js"):(t.global="",t.entry=a,t.type="js")}i.push(t),t={}}):typeof o=="object"&&o.entry&&(t.entry=o.entry,t.global=o.global,t.type=o.type,i.push(t),t={})}i.map(s=>{s.type==="js"?r.push({attributes:{src:s.entry},tagName:"script"}):s.type==="css"&&r.push({attributes:{href:s.entry,rel:"stylesheet"},tagName:"link"})})}}};var E=(n={})=>({name:"@empjs/share",async rsConfig(e){new c(n,e).setup()}}),$=E;export{$ as default,E as pluginRspackEmpShare};
3
3
  //# sourceMappingURL=rspack.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugins/rspack/share.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts","../src/plugins/rspack/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, ExternalsItemType, ModuleFederationPluginOptions} from './types'\nimport {getRuntimeLib} from './utils'\nconst exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\nexport class EmpShare {\n private op: EMPPluginShareType\n private store: GlobalStore\n /**\n * 注入资源\n */\n private injectHtml: any[] = []\n /**\n * 兼容 shareLib\n */\n private externalsLib: ExternalsItemType[] = []\n constructor(op: EMPPluginShareType, store: GlobalStore) {\n this.op = op || {}\n this.store = store\n }\n setup() {\n this.setMF() // 设置 MF 配置\n this.injectGlobalVal() // 插入全局变量 方便emp外的项目调用\n this.injectFramework() // 插入ui框架库\n this.setShareLib() //兼容 emp Sharelib的共享模型设置\n this.setRuntimeLib() // 设置 MF SDK\n this.injectToHtml() //触发插入动作\n this.setExternal() // 设置 external 降低包体\n }\n private injectToHtml() {\n const {store, injectHtml} = this\n if (injectHtml.length > 0) {\n store.injectTags(injectHtml, 'EMPShare')\n }\n }\n private injectFramework() {\n if (!this.op.empRuntime || !this.op.empRuntime.frameworkLib) return\n const {store, injectHtml} = this\n const {frameworkLib} = this.op.empRuntime\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n })\n }\n }\n private injectGlobalVal() {\n if (!this.op.empRuntime) return\n const {empRuntime} = this.op\n const {injectHtml} = this\n empRuntime.framework = Object.hasOwn(empRuntime, 'framework') ? empRuntime.framework : 'react'\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || (empRuntime.shareLib ? 'window' : '')\n\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${empRuntime.frameworkGlobal}',runtimeLib:'${empRuntime.runtimeGlobal}',framework:'${empRuntime.framework}'}`,\n })\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {framework, shareLib, runtimeGlobal, frameworkGlobal} = empRuntime\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' && !shareLib && 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 (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${frameworkGlobal}.${v.global}`\n }\n })\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n private setRuntimeLib() {\n if (!this.op.empRuntime) return\n\n const {runtimeLib, shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions>(\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 }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\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","import type {GlobalStore} from '@empjs/cli'\nimport {EmpShare} from './share'\nimport type {EMPPluginShareType} from './types'\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n const empShare = new EmpShare(o, store)\n empShare.setup()\n },\n }\n}\nexport default 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,CJFA,IAAME,EAAM,0BACCC,EAAN,KAAe,CACZ,GACA,MAIA,WAAoB,CAAC,EAIrB,aAAoC,CAAC,EAC7C,YAAYC,EAAwBC,EAAoB,CACtD,KAAK,GAAKD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,EAC/BA,EAAgB,CAAC,CACnB,CAAC,EACQ,OAAON,GAAM,UAAYA,EAAE,QACpCM,EAAc,MAAQN,EAAE,MACxBM,EAAc,OAASN,EAAE,OACzBM,EAAc,KAAON,EAAE,KACvBV,EAAa,KAAKgB,CAAa,EAC/BA,EAAgB,CAAC,EAErB,CAEAhB,EAAa,IAAIU,GAAK,CAChBA,EAAE,OAAS,KACbhB,EAAW,KAAK,CACd,WAAY,CACV,IAAKgB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBhB,EAAW,KAAK,CACd,WAAY,CACV,KAAMgB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EKpNO,IAAMS,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAChB,IAAIC,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ","names":["ModuleFederationPlugin","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","exp","EmpShare","op","store","injectHtml","frameworkLib","url","getRuntimeLib","empRuntime","shareGlobalName","externalsLib","framework","shareLib","runtimeGlobal","frameworkGlobal","externalRuntime","externals","key","value","externalReact","v","runtimeLib","EmpShareRemoteLibPlugin","o","ModuleFederationPlugin","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default"]}
1
+ {"version":3,"sources":["../src/plugins/rspack/share.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts","../src/plugins/rspack/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, ExternalsItemType, ModuleFederationPluginOptions} from './types'\nimport {getRuntimeLib} from './utils'\nconst exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\nexport class EmpShare {\n private op: EMPPluginShareType\n private store: GlobalStore\n /**\n * 注入资源\n */\n private injectHtml: any[] = []\n /**\n * 兼容 shareLib\n */\n private externalsLib: ExternalsItemType[] = []\n constructor(op: EMPPluginShareType, store: GlobalStore) {\n this.op = op || {}\n this.store = store\n }\n setup() {\n this.setMF() // 设置 MF 配置\n this.injectGlobalVal() // 插入全局变量 方便emp外的项目调用\n this.injectFramework() // 插入ui框架库\n this.setShareLib() //兼容 emp Sharelib的共享模型设置\n this.setRuntimeLib() // 设置 MF SDK\n this.injectToHtml() //触发插入动作\n this.setExternal() // 设置 external 降低包体\n }\n private injectToHtml() {\n const {store, injectHtml} = this\n if (injectHtml.length > 0) {\n store.injectTags(injectHtml, 'EMPShare')\n }\n }\n private injectFramework() {\n if (!this.op.empRuntime || !this.op.empRuntime.frameworkLib) return\n const {store, injectHtml} = this\n const {frameworkLib} = this.op.empRuntime\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n })\n }\n }\n private injectGlobalVal() {\n if (!this.op.empRuntime) return\n const {empRuntime} = this.op\n const {injectHtml} = this\n empRuntime.framework = Object.hasOwn(empRuntime, 'framework') ? empRuntime.framework : 'react'\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || (empRuntime.shareLib ? 'window' : '')\n\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${empRuntime.frameworkGlobal}',runtimeLib:'${empRuntime.runtimeGlobal}',framework:'${empRuntime.framework}'}`,\n })\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {framework, shareLib, runtimeGlobal, frameworkGlobal} = empRuntime\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' && !shareLib && 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 (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${frameworkGlobal}.${v.global}`\n }\n })\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n private setRuntimeLib() {\n if (!this.op.empRuntime) return\n\n const {runtimeLib, shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions & {empRuntime: any}>(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n if (op.empRuntime) {\n delete op.empRuntime\n }\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\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","import type {GlobalStore} from '@empjs/cli'\nimport {EmpShare} from './share'\nimport type {EMPPluginShareType} from './types'\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n const empShare = new EmpShare(o, store)\n empShare.setup()\n },\n }\n}\nexport default 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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":["ModuleFederationPlugin","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","exp","EmpShare","op","store","injectHtml","frameworkLib","url","getRuntimeLib","empRuntime","shareGlobalName","externalsLib","framework","shareLib","runtimeGlobal","frameworkGlobal","externalRuntime","externals","key","value","externalReact","v","runtimeLib","EmpShareRemoteLibPlugin","o","ModuleFederationPlugin","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default"]}
package/dist/runtime.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var r=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var R=(t,i)=>{for(var e in i)r(t,e,{get:i[e],enumerable:!0})},T=(t,i,e,o)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of y(i))!h.call(t,n)&&n!==e&&r(t,n,{get:()=>i[n],enumerable:!(o=b(i,n))||o.enumerable});return t};var d=t=>T(r({},"__esModule",{value:!0}),t);var M={};R(M,{EMPRuntime:()=>s,default:()=>f});module.exports=d(M);function l(t,...i){for(let e of i)for(let o in e){let n=e[o],p=t[o];if(Object(n)==n&&Object(p)===p){t[o]=l(p,n);continue}t[o]=e[o]}return t}var a="EMP_SHARE_RUNTIME";var u=window[a]||{},c=window,{EMPShareGlobalVal:m}=c||{};m&&m.runtimeLib&&(u=c[m.runtimeLib]);var s=class{libs=u;initOptions;options={showLog:!1};shareGlobalName=a;constructor(i){i&&this.setup(i)}setup(i){if(i&&(typeof i=="string"&&(i=window[i]),this.libs=i),!this.libs.MFRuntime||!this.libs.MFSDK)throw new Error("MFRuntime and MFSDK Required!")}init(i={}){let e={name:"empRuntimeProject",remotes:[]};e=l(e,i),this.libs.MFRuntime.init(e)}load(...i){return this.libs.MFRuntime.loadRemote(...i)}register=this.libs?.MFRuntime.registerRemotes;preload=this.libs?.MFRuntime.preloadRemote;loadShare=this.libs?.MFRuntime.loadShare},f=new s;0&&(module.exports={EMPRuntime});
1
+ "use strict";var r=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var R=(t,i)=>{for(var e in i)r(t,e,{get:i[e],enumerable:!0})},T=(t,i,e,n)=>{if(i&&typeof i=="object"||typeof i=="function")for(let s of h(i))!y.call(t,s)&&s!==e&&r(t,s,{get:()=>i[s],enumerable:!(n=b(i,s))||n.enumerable});return t};var f=t=>T(r({},"__esModule",{value:!0}),t);var M={};R(M,{EMPRuntime:()=>o,default:()=>d});module.exports=f(M);function a(t,...i){for(let e of i)for(let n in e){let s=e[n],p=t[n];if(Object(s)==s&&Object(p)===p){t[n]=a(p,s);continue}t[n]=e[n]}return t}var l="EMP_SHARE_RUNTIME";var u=window[l]||{},c=window,{EMPShareGlobalVal:m}=c||{};m&&m.runtimeLib&&(u=c[m.runtimeLib]);var o=class{libs=u;initOptions;options={showLog:!1};shareGlobalName=l;isInit=!1;constructor(i){i&&this.setup(i)}setup(i){if(i&&(typeof i=="string"&&(i=window[i]),this.libs=i),!this.libs.MFRuntime||!this.libs.MFSDK)throw new Error("MFRuntime and MFSDK Required!")}init(i={}){if(this.isInit)return;let e={name:"empRuntimeProject",remotes:[]};e=a(e,i),this.libs.MFRuntime.init(e),this.isInit=!0}load(...i){return this.libs.MFRuntime.loadRemote(...i)}register=this.libs?.MFRuntime.registerRemotes;preload=this.libs?.MFRuntime.preloadRemote;loadShare=this.libs?.MFRuntime.loadShare},d=new o;0&&(module.exports={EMPRuntime});
2
2
  //# sourceMappingURL=runtime.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/runtime/index.ts","../src/helper/index.ts","../src/helper/config.ts"],"sourcesContent":["import {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport type {EMPShareRuntimeType, EmpRuntimeOptions, InitOptionsType, LoadRemoteType} from 'src/types'\ntype EmpInitOptionsType = Partial<InitOptionsType>\nlet globalLib = window[shareGlobalName] || {}\n// 根据 injectGlobalValToHtml 提前把库赋值到 EMPRuntime\nconst win: any = window\nconst {EMPShareGlobalVal} = win || {}\nif (EMPShareGlobalVal && EMPShareGlobalVal.runtimeLib) {\n globalLib = win[EMPShareGlobalVal.runtimeLib]\n}\n\nexport class EMPRuntime {\n public libs: EMPShareRuntimeType = globalLib\n public initOptions!: InitOptionsType\n public options: EmpRuntimeOptions = {\n showLog: false,\n }\n public shareGlobalName = shareGlobalName\n // private isInit = false\n constructor(op?: EMPShareRuntimeType) {\n if (op) this.setup(op)\n }\n /**\n * 实例化 adapter libs\n */\n public setup(o?: EMPShareRuntimeType | string) {\n if (o) {\n if (typeof o === 'string') o = window[o]\n this.libs = o as any\n }\n if (!this.libs.MFRuntime || !this.libs.MFSDK) {\n throw new Error('MFRuntime and MFSDK Required!')\n }\n }\n public init(options: EmpInitOptionsType = {}) {\n // if (this.isInit) return\n let op: InitOptionsType = {\n name: 'empRuntimeProject',\n remotes: [],\n // plugins: [catchErrorNextPlugin(this.options.showLog)],\n }\n op = deepAssign<InitOptionsType>(op, options)\n this.libs.MFRuntime.init(op)\n // this.isInit = true\n }\n public load<T = any>(...args: LoadRemoteType) {\n return this.libs.MFRuntime.loadRemote<T>(...args) as Promise<T>\n }\n public register = this.libs?.MFRuntime.registerRemotes\n public preload = this.libs?.MFRuntime.preloadRemote\n public loadShare = this.libs?.MFRuntime.loadShare\n}\n//\nexport default new EMPRuntime()\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p)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GA,CAAI,CAClD,CACO,SAAW,KAAK,MAAM,UAAU,gBAChC,QAAU,KAAK,MAAM,UAAU,cAC/B,UAAY,KAAK,MAAM,UAAU,SAC1C,EAEOC,EAAQ,IAAIN","names":["runtime_exports","__export","EMPRuntime","runtime_default","__toCommonJS","deepAssign","target","sources","source","k","vs","vt","shareGlobalName","globalLib","shareGlobalName","win","EMPShareGlobalVal","EMPRuntime","op","o","options","deepAssign","args","runtime_default"]}
1
+ {"version":3,"sources":["../src/runtime/index.ts","../src/helper/index.ts","../src/helper/config.ts"],"sourcesContent":["import {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport type {EMPShareRuntimeType, EmpRuntimeOptions, InitOptionsType, LoadRemoteType} from 'src/types'\ntype EmpInitOptionsType = Partial<InitOptionsType>\nlet globalLib = window[shareGlobalName] || {}\n// 根据 injectGlobalValToHtml 提前把库赋值到 EMPRuntime\nconst win: any = window\nconst {EMPShareGlobalVal} = win || {}\nif (EMPShareGlobalVal && EMPShareGlobalVal.runtimeLib) {\n globalLib = win[EMPShareGlobalVal.runtimeLib]\n}\n\nexport class EMPRuntime {\n public libs: EMPShareRuntimeType = globalLib\n public initOptions!: InitOptionsType\n public options: EmpRuntimeOptions = {\n showLog: false,\n }\n public shareGlobalName = shareGlobalName\n private isInit = false\n constructor(op?: EMPShareRuntimeType) {\n if (op) this.setup(op)\n }\n /**\n * 实例化 adapter libs\n */\n public setup(o?: EMPShareRuntimeType | string) {\n if (o) {\n if (typeof o === 'string') o = window[o]\n this.libs = o as any\n }\n if (!this.libs.MFRuntime || !this.libs.MFSDK) {\n throw new Error('MFRuntime and MFSDK Required!')\n }\n }\n public init(options: EmpInitOptionsType = {}) {\n if (this.isInit) return\n let op: InitOptionsType = {\n name: 'empRuntimeProject',\n remotes: [],\n // plugins: [catchErrorNextPlugin(this.options.showLog)],\n }\n op = deepAssign<InitOptionsType>(op, options)\n this.libs.MFRuntime.init(op)\n this.isInit = true\n }\n public load<T = any>(...args: LoadRemoteType) {\n return this.libs.MFRuntime.loadRemote<T>(...args) as Promise<T>\n }\n public register = this.libs?.MFRuntime.registerRemotes\n public preload = this.libs?.MFRuntime.preloadRemote\n public loadShare = this.libs?.MFRuntime.loadShare\n}\n//\nexport default new EMPRuntime()\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GCEO,SAASK,EAAcC,KAAgBC,EAAiB,CAC7D,QAAWC,KAAUD,EACnB,QAAWE,KAAKD,EAAQ,CACtB,IAAME,EAAKF,EAAOC,CAAC,EACjBE,EAAKL,EAAOG,CAAC,EACf,GAAI,OAAOC,CAAE,GAAKA,GAAM,OAAOC,CAAE,IAAMA,EAAI,CACzCL,EAAOG,CAAC,EAAIJ,EAAWM,EAAID,CAAE,EAC7B,QACF,CACAJ,EAAOG,CAAC,EAAID,EAAOC,CAAC,CACtB,CAEF,OAAOH,CACT,CCfO,IAAMM,EAAkB,oBFI/B,IAAIC,EAAY,OAAOC,CAAe,GAAK,CAAC,EAEtCC,EAAW,OACX,CAAC,kBAAAC,CAAiB,EAAID,GAAO,CAAC,EAChCC,GAAqBA,EAAkB,aACzCH,EAAYE,EAAIC,EAAkB,UAAU,GAGvC,IAAMC,EAAN,KAAiB,CACf,KAA4BJ,EAC5B,YACA,QAA6B,CAClC,QAAS,EACX,EACO,gBAAkBC,EACjB,OAAS,GACjB,YAAYI,EAA0B,CAChCA,GAAI,KAAK,MAAMA,CAAE,CACvB,CAIO,MAAMC,EAAkC,CAK7C,GAJIA,IACE,OAAOA,GAAM,WAAUA,EAAI,OAAOA,CAAC,GACvC,KAAK,KAAOA,GAEV,CAAC,KAAK,KAAK,WAAa,CAAC,KAAK,KAAK,MACrC,MAAM,IAAI,MAAM,+BAA+B,CAEnD,CACO,KAAKC,EAA8B,CAAC,EAAG,CAC5C,GAAI,KAAK,OAAQ,OACjB,IAAIF,EAAsB,CACxB,KAAM,oBACN,QAAS,CAAC,CAEZ,EACAA,EAAKG,EAA4BH,EAAIE,CAAO,EAC5C,KAAK,KAAK,UAAU,KAAKF,CAAE,EAC3B,KAAK,OAAS,EAChB,CACO,QAAiBI,EAAsB,CAC5C,OAAO,KAAK,KAAK,UAAU,WAAc,GAAGA,CAAI,CAClD,CACO,SAAW,KAAK,MAAM,UAAU,gBAChC,QAAU,KAAK,MAAM,UAAU,cAC/B,UAAY,KAAK,MAAM,UAAU,SAC1C,EAEOC,EAAQ,IAAIN","names":["runtime_exports","__export","EMPRuntime","runtime_default","__toCommonJS","deepAssign","target","sources","source","k","vs","vt","shareGlobalName","globalLib","shareGlobalName","win","EMPShareGlobalVal","EMPRuntime","op","o","options","deepAssign","args","runtime_default"]}
@@ -8,6 +8,7 @@ declare class EMPRuntime {
8
8
  initOptions: InitOptionsType;
9
9
  options: EmpRuntimeOptions;
10
10
  shareGlobalName: string;
11
+ private isInit;
11
12
  constructor(op?: EMPShareRuntimeType);
12
13
  /**
13
14
  * 实例化 adapter libs
package/dist/runtime.d.ts CHANGED
@@ -8,6 +8,7 @@ declare class EMPRuntime {
8
8
  initOptions: InitOptionsType;
9
9
  options: EmpRuntimeOptions;
10
10
  shareGlobalName: string;
11
+ private isInit;
11
12
  constructor(op?: EMPShareRuntimeType);
12
13
  /**
13
14
  * 实例化 adapter libs
package/dist/runtime.js CHANGED
@@ -1,2 +1,2 @@
1
- function p(e,...i){for(let t of i)for(let n in t){let o=t[n],s=e[n];if(Object(o)==o&&Object(s)===s){e[n]=p(s,o);continue}e[n]=t[n]}return e}var r="EMP_SHARE_RUNTIME";var m=window[r]||{},u=window,{EMPShareGlobalVal:l}=u||{};l&&l.runtimeLib&&(m=u[l.runtimeLib]);var a=class{libs=m;initOptions;options={showLog:!1};shareGlobalName=r;constructor(i){i&&this.setup(i)}setup(i){if(i&&(typeof i=="string"&&(i=window[i]),this.libs=i),!this.libs.MFRuntime||!this.libs.MFSDK)throw new Error("MFRuntime and MFSDK Required!")}init(i={}){let t={name:"empRuntimeProject",remotes:[]};t=p(t,i),this.libs.MFRuntime.init(t)}load(...i){return this.libs.MFRuntime.loadRemote(...i)}register=this.libs?.MFRuntime.registerRemotes;preload=this.libs?.MFRuntime.preloadRemote;loadShare=this.libs?.MFRuntime.loadShare},R=new a;export{a as EMPRuntime,R as default};
1
+ function p(e,...i){for(let t of i)for(let s in t){let n=t[s],o=e[s];if(Object(n)==n&&Object(o)===o){e[s]=p(o,n);continue}e[s]=t[s]}return e}var r="EMP_SHARE_RUNTIME";var m=window[r]||{},u=window,{EMPShareGlobalVal:a}=u||{};a&&a.runtimeLib&&(m=u[a.runtimeLib]);var l=class{libs=m;initOptions;options={showLog:!1};shareGlobalName=r;isInit=!1;constructor(i){i&&this.setup(i)}setup(i){if(i&&(typeof i=="string"&&(i=window[i]),this.libs=i),!this.libs.MFRuntime||!this.libs.MFSDK)throw new Error("MFRuntime and MFSDK Required!")}init(i={}){if(this.isInit)return;let t={name:"empRuntimeProject",remotes:[]};t=p(t,i),this.libs.MFRuntime.init(t),this.isInit=!0}load(...i){return this.libs.MFRuntime.loadRemote(...i)}register=this.libs?.MFRuntime.registerRemotes;preload=this.libs?.MFRuntime.preloadRemote;loadShare=this.libs?.MFRuntime.loadShare},R=new l;export{l as EMPRuntime,R as default};
2
2
  //# sourceMappingURL=runtime.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/helper/index.ts","../src/helper/config.ts","../src/runtime/index.ts"],"sourcesContent":["export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","import {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport type {EMPShareRuntimeType, EmpRuntimeOptions, InitOptionsType, LoadRemoteType} from 'src/types'\ntype EmpInitOptionsType = Partial<InitOptionsType>\nlet globalLib = window[shareGlobalName] || {}\n// 根据 injectGlobalValToHtml 提前把库赋值到 EMPRuntime\nconst win: any = window\nconst {EMPShareGlobalVal} = win || {}\nif (EMPShareGlobalVal && EMPShareGlobalVal.runtimeLib) {\n globalLib = win[EMPShareGlobalVal.runtimeLib]\n}\n\nexport class EMPRuntime {\n public libs: EMPShareRuntimeType = globalLib\n public initOptions!: InitOptionsType\n public options: EmpRuntimeOptions = {\n showLog: false,\n }\n public shareGlobalName = shareGlobalName\n // private isInit = false\n constructor(op?: EMPShareRuntimeType) {\n if (op) this.setup(op)\n }\n /**\n * 实例化 adapter libs\n */\n public setup(o?: EMPShareRuntimeType | string) {\n if (o) {\n if (typeof o === 'string') o = window[o]\n this.libs = o as any\n }\n if (!this.libs.MFRuntime || !this.libs.MFSDK) {\n throw new Error('MFRuntime and MFSDK Required!')\n }\n }\n public init(options: EmpInitOptionsType = {}) {\n // if (this.isInit) return\n let op: InitOptionsType = {\n name: 'empRuntimeProject',\n remotes: [],\n // plugins: [catchErrorNextPlugin(this.options.showLog)],\n }\n op = deepAssign<InitOptionsType>(op, options)\n this.libs.MFRuntime.init(op)\n // this.isInit = true\n }\n public load<T = any>(...args: LoadRemoteType) {\n return this.libs.MFRuntime.loadRemote<T>(...args) as Promise<T>\n }\n public register = this.libs?.MFRuntime.registerRemotes\n public preload = this.libs?.MFRuntime.preloadRemote\n public loadShare = this.libs?.MFRuntime.loadShare\n}\n//\nexport default new EMPRuntime()\n"],"mappings":"AAEO,SAASA,EAAcC,KAAgBC,EAAiB,CAC7D,QAAWC,KAAUD,EACnB,QAAWE,KAAKD,EAAQ,CACtB,IAAME,EAAKF,EAAOC,CAAC,EACjBE,EAAKL,EAAOG,CAAC,EACf,GAAI,OAAOC,CAAE,GAAKA,GAAM,OAAOC,CAAE,IAAMA,EAAI,CACzCL,EAAOG,CAAC,EAAIJ,EAAWM,EAAID,CAAE,EAC7B,QACF,CACAJ,EAAOG,CAAC,EAAID,EAAOC,CAAC,CACtB,CAEF,OAAOH,CACT,CCfO,IAAMM,EAAkB,oBCI/B,IAAIC,EAAY,OAAOC,CAAe,GAAK,CAAC,EAEtCC,EAAW,OACX,CAAC,kBAAAC,CAAiB,EAAID,GAAO,CAAC,EAChCC,GAAqBA,EAAkB,aACzCH,EAAYE,EAAIC,EAAkB,UAAU,GAGvC,IAAMC,EAAN,KAAiB,CACf,KAA4BJ,EAC5B,YACA,QAA6B,CAClC,QAAS,EACX,EACO,gBAAkBC,EAEzB,YAAYI,EAA0B,CAChCA,GAAI,KAAK,MAAMA,CAAE,CACvB,CAIO,MAAMC,EAAkC,CAK7C,GAJIA,IACE,OAAOA,GAAM,WAAUA,EAAI,OAAOA,CAAC,GACvC,KAAK,KAAOA,GAEV,CAAC,KAAK,KAAK,WAAa,CAAC,KAAK,KAAK,MACrC,MAAM,IAAI,MAAM,+BAA+B,CAEnD,CACO,KAAKC,EAA8B,CAAC,EAAG,CAE5C,IAAIF,EAAsB,CACxB,KAAM,oBACN,QAAS,CAAC,CAEZ,EACAA,EAAKG,EAA4BH,EAAIE,CAAO,EAC5C,KAAK,KAAK,UAAU,KAAKF,CAAE,CAE7B,CACO,QAAiBI,EAAsB,CAC5C,OAAO,KAAK,KAAK,UAAU,WAAc,GAAGA,CAAI,CAClD,CACO,SAAW,KAAK,MAAM,UAAU,gBAChC,QAAU,KAAK,MAAM,UAAU,cAC/B,UAAY,KAAK,MAAM,UAAU,SAC1C,EAEOC,EAAQ,IAAIN","names":["deepAssign","target","sources","source","k","vs","vt","shareGlobalName","globalLib","shareGlobalName","win","EMPShareGlobalVal","EMPRuntime","op","o","options","deepAssign","args","runtime_default"]}
1
+ {"version":3,"sources":["../src/helper/index.ts","../src/helper/config.ts","../src/runtime/index.ts"],"sourcesContent":["export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","import {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport type {EMPShareRuntimeType, EmpRuntimeOptions, InitOptionsType, LoadRemoteType} from 'src/types'\ntype EmpInitOptionsType = Partial<InitOptionsType>\nlet globalLib = window[shareGlobalName] || {}\n// 根据 injectGlobalValToHtml 提前把库赋值到 EMPRuntime\nconst win: any = window\nconst {EMPShareGlobalVal} = win || {}\nif (EMPShareGlobalVal && EMPShareGlobalVal.runtimeLib) {\n globalLib = win[EMPShareGlobalVal.runtimeLib]\n}\n\nexport class EMPRuntime {\n public libs: EMPShareRuntimeType = globalLib\n public initOptions!: InitOptionsType\n public options: EmpRuntimeOptions = {\n showLog: false,\n }\n public shareGlobalName = shareGlobalName\n private isInit = false\n constructor(op?: EMPShareRuntimeType) {\n if (op) this.setup(op)\n }\n /**\n * 实例化 adapter libs\n */\n public setup(o?: EMPShareRuntimeType | string) {\n if (o) {\n if (typeof o === 'string') o = window[o]\n this.libs = o as any\n }\n if (!this.libs.MFRuntime || !this.libs.MFSDK) {\n throw new Error('MFRuntime and MFSDK Required!')\n }\n }\n public init(options: EmpInitOptionsType = {}) {\n if (this.isInit) return\n let op: InitOptionsType = {\n name: 'empRuntimeProject',\n remotes: [],\n // plugins: [catchErrorNextPlugin(this.options.showLog)],\n }\n op = deepAssign<InitOptionsType>(op, options)\n this.libs.MFRuntime.init(op)\n this.isInit = true\n }\n public load<T = any>(...args: LoadRemoteType) {\n return this.libs.MFRuntime.loadRemote<T>(...args) as Promise<T>\n }\n public register = this.libs?.MFRuntime.registerRemotes\n public preload = this.libs?.MFRuntime.preloadRemote\n public loadShare = this.libs?.MFRuntime.loadShare\n}\n//\nexport default new EMPRuntime()\n"],"mappings":"AAEO,SAASA,EAAcC,KAAgBC,EAAiB,CAC7D,QAAWC,KAAUD,EACnB,QAAWE,KAAKD,EAAQ,CACtB,IAAME,EAAKF,EAAOC,CAAC,EACjBE,EAAKL,EAAOG,CAAC,EACf,GAAI,OAAOC,CAAE,GAAKA,GAAM,OAAOC,CAAE,IAAMA,EAAI,CACzCL,EAAOG,CAAC,EAAIJ,EAAWM,EAAID,CAAE,EAC7B,QACF,CACAJ,EAAOG,CAAC,EAAID,EAAOC,CAAC,CACtB,CAEF,OAAOH,CACT,CCfO,IAAMM,EAAkB,oBCI/B,IAAIC,EAAY,OAAOC,CAAe,GAAK,CAAC,EAEtCC,EAAW,OACX,CAAC,kBAAAC,CAAiB,EAAID,GAAO,CAAC,EAChCC,GAAqBA,EAAkB,aACzCH,EAAYE,EAAIC,EAAkB,UAAU,GAGvC,IAAMC,EAAN,KAAiB,CACf,KAA4BJ,EAC5B,YACA,QAA6B,CAClC,QAAS,EACX,EACO,gBAAkBC,EACjB,OAAS,GACjB,YAAYI,EAA0B,CAChCA,GAAI,KAAK,MAAMA,CAAE,CACvB,CAIO,MAAMC,EAAkC,CAK7C,GAJIA,IACE,OAAOA,GAAM,WAAUA,EAAI,OAAOA,CAAC,GACvC,KAAK,KAAOA,GAEV,CAAC,KAAK,KAAK,WAAa,CAAC,KAAK,KAAK,MACrC,MAAM,IAAI,MAAM,+BAA+B,CAEnD,CACO,KAAKC,EAA8B,CAAC,EAAG,CAC5C,GAAI,KAAK,OAAQ,OACjB,IAAIF,EAAsB,CACxB,KAAM,oBACN,QAAS,CAAC,CAEZ,EACAA,EAAKG,EAA4BH,EAAIE,CAAO,EAC5C,KAAK,KAAK,UAAU,KAAKF,CAAE,EAC3B,KAAK,OAAS,EAChB,CACO,QAAiBI,EAAsB,CAC5C,OAAO,KAAK,KAAK,UAAU,WAAc,GAAGA,CAAI,CAClD,CACO,SAAW,KAAK,MAAM,UAAU,gBAChC,QAAU,KAAK,MAAM,UAAU,cAC/B,UAAY,KAAK,MAAM,UAAU,SAC1C,EAEOC,EAAQ,IAAIN","names":["deepAssign","target","sources","source","k","vs","vt","shareGlobalName","globalLib","shareGlobalName","win","EMPShareGlobalVal","EMPRuntime","op","o","options","deepAssign","args","runtime_default"]}
package/output/full.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import * as MFRuntime from '@module-federation/enhanced/runtime';
2
- import MFRuntime__default from '@module-federation/enhanced/runtime';
3
- export { MFRuntime };
4
1
  import MFSDK__default from '@module-federation/sdk';
5
2
  import * as MFSDK from '@module-federation/sdk';
6
3
  export { MFSDK };
4
+ import * as MFRuntime from '@module-federation/enhanced/runtime';
5
+ import MFRuntime__default from '@module-federation/enhanced/runtime';
6
+ import * as moduleFederationRuntime from '@empjs/module-federation-runtime';
7
+ export { moduleFederationRuntime as MFRuntime };
7
8
 
8
9
  type EMPShareRuntimeType = {
9
10
  MFRuntime: Required<typeof MFRuntime__default>;
@@ -37,6 +38,7 @@ declare class EMPRuntime {
37
38
  initOptions: InitOptionsType;
38
39
  options: EmpRuntimeOptions;
39
40
  shareGlobalName: string;
41
+ private isInit;
40
42
  constructor(op?: EMPShareRuntimeType);
41
43
  /**
42
44
  * 实例化 adapter libs