@empjs/share 3.1.10 → 3.1.13

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 x=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var P=(i,e)=>{for(var t in e)f(i,t,{get:e[t],enumerable:!0})},M=(i,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of x(e))!k.call(i,o)&&o!==t&&f(i,o,{get:()=>e[o],enumerable:!(s=S(e,o))||s.enumerable});return i};var w=i=>M(f({},"__esModule",{value:!0}),i);var T={};P(T,{default:()=>H,pluginRspackEmpShare:()=>h});module.exports=w(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=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,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});
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 = 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'\n//\n\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 // if (o.name) {\n // const op: any = store.deepAssign(\n // {\n // filename: 'emp.js',\n // manifest: false,\n // dts: false,\n // dev: {\n // disableDynamicRemoteTypeHints: true,\n // },\n // },\n // o,\n // )\n // delete op.empRuntime\n // store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n // }\n // const {empRuntime} = o\n // if (empRuntime) {\n // const injectHtml: any[] = []\n // const framework = empRuntime.framework || 'react'\n // const {frameworkLib, runtimeLib, shareLib} = empRuntime\n // /**\n // * shareLib 兼容\n // */\n // const externalsLib: ExternalsItemType[] = []\n // //\n // let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n // let frameworkGlobal = empRuntime.frameworkGlobal || ''\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:'${frameworkGlobal}',runtimeLib:'${runtimeGlobal}',framework:'${framework}'}`,\n // })\n // }\n // /**\n // * frameworkLib & runtimeLib 的全局引用\n // */\n // if (frameworkLib) {\n // const url = getRuntimeLib(frameworkLib, store.mode)\n // injectHtml.push({\n // attributes: {\n // src: url,\n // },\n // tagName: 'script',\n // // type: 'js',\n // // src: url,\n // })\n // } else if (shareLib && typeof shareLib === 'object') {\n // frameworkGlobal = !frameworkGlobal ? 'window' : frameworkGlobal\n // const exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\n\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 // if (!runtimeLib) {\n // // 内置 runtimeLib\n // store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n // //\n\n // // store.chain.optimization.merge({\n // // splitChunks: {\n // // cacheGroups: {\n // // moduleFederation: {\n // // name: 'mfRuntime',\n // // test: /[\\\\/]node_modules[\\\\/](@module-federation)[\\\\/]/,\n // // priority: 0,\n // // chunks: 'all',\n // // },\n // // },\n // // },\n // // })\n // }\n // // 统一封装到 frameworkLib\n // else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n // runtimeGlobal = frameworkGlobal\n // } else {\n // // 插入 runtime\n // injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n // }\n // if (injectHtml.length > 0) {\n // store.injectTags(injectHtml, 'EMPShare')\n // }\n // /********************************************************************\n // * 设置 externals\n // ********************************************************************\n // */\n // const externalRuntime = {\n // '@module-federation/runtime': `MFRuntime`,\n // '@module-federation/sdk': `MFSDK`,\n // }\n // const externals = {}\n // for (const [key, value] of Object.entries(externalRuntime)) {\n // externals[key] = `${runtimeGlobal}.${value}`\n // }\n // if (framework === 'react' && !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 },\n }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Y,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,EKlNO,IAAMQ,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAChB,IAAIC,EAASF,EAAGC,CAAK,EAC7B,MAAM,CAyLjB,CACF,GAGKE,EAAQJ,ENtMf,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>(\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,EA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Ac,KAAO,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"]}
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=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)},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};
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 = 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'\n//\n\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 // if (o.name) {\n // const op: any = store.deepAssign(\n // {\n // filename: 'emp.js',\n // manifest: false,\n // dts: false,\n // dev: {\n // disableDynamicRemoteTypeHints: true,\n // },\n // },\n // o,\n // )\n // delete op.empRuntime\n // store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n // }\n // const {empRuntime} = o\n // if (empRuntime) {\n // const injectHtml: any[] = []\n // const framework = empRuntime.framework || 'react'\n // const {frameworkLib, runtimeLib, shareLib} = empRuntime\n // /**\n // * shareLib 兼容\n // */\n // const externalsLib: ExternalsItemType[] = []\n // //\n // let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n // let frameworkGlobal = empRuntime.frameworkGlobal || ''\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:'${frameworkGlobal}',runtimeLib:'${runtimeGlobal}',framework:'${framework}'}`,\n // })\n // }\n // /**\n // * frameworkLib & runtimeLib 的全局引用\n // */\n // if (frameworkLib) {\n // const url = getRuntimeLib(frameworkLib, store.mode)\n // injectHtml.push({\n // attributes: {\n // src: url,\n // },\n // tagName: 'script',\n // // type: 'js',\n // // src: url,\n // })\n // } else if (shareLib && typeof shareLib === 'object') {\n // frameworkGlobal = !frameworkGlobal ? 'window' : frameworkGlobal\n // const exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\n\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 // if (!runtimeLib) {\n // // 内置 runtimeLib\n // store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n // //\n\n // // store.chain.optimization.merge({\n // // splitChunks: {\n // // cacheGroups: {\n // // moduleFederation: {\n // // name: 'mfRuntime',\n // // test: /[\\\\/]node_modules[\\\\/](@module-federation)[\\\\/]/,\n // // priority: 0,\n // // chunks: 'all',\n // // },\n // // },\n // // },\n // // })\n // }\n // // 统一封装到 frameworkLib\n // else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n // runtimeGlobal = frameworkGlobal\n // } else {\n // // 插入 runtime\n // injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n // }\n // if (injectHtml.length > 0) {\n // store.injectTags(injectHtml, 'EMPShare')\n // }\n // /********************************************************************\n // * 设置 externals\n // ********************************************************************\n // */\n // const externalRuntime = {\n // '@module-federation/runtime': `MFRuntime`,\n // '@module-federation/sdk': `MFSDK`,\n // }\n // const externals = {}\n // for (const [key, value] of Object.entries(externalRuntime)) {\n // externals[key] = `${runtimeGlobal}.${value}`\n // }\n // if (framework === 'react' && !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 },\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,OA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,CACL,IAAMC,EAAUC,EAAG,MAAM5B,CAAG,GAAK,CAAC,EAC9B2B,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,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,EKlNO,IAAMS,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAChB,IAAIC,EAASF,EAAGC,CAAK,EAC7B,MAAM,CAyLjB,CACF,GAGKE,EAAQJ,ECtMf,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"]}
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/rsp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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,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 P=(i,e)=>{for(var t in e)f(i,t,{get:e[t],enumerable:!0})},M=(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 w=i=>M(f({},"__esModule",{value:!0}),i);var H={};P(H,{default:()=>G,pluginRspackEmpShare:()=>d});module.exports=w(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=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=(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});
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'\n//\n\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 // if (o.name) {\n // const op: any = store.deepAssign(\n // {\n // filename: 'emp.js',\n // manifest: false,\n // dts: false,\n // dev: {\n // disableDynamicRemoteTypeHints: true,\n // },\n // },\n // o,\n // )\n // delete op.empRuntime\n // store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n // }\n // const {empRuntime} = o\n // if (empRuntime) {\n // const injectHtml: any[] = []\n // const framework = empRuntime.framework || 'react'\n // const {frameworkLib, runtimeLib, shareLib} = empRuntime\n // /**\n // * shareLib 兼容\n // */\n // const externalsLib: ExternalsItemType[] = []\n // //\n // let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n // let frameworkGlobal = empRuntime.frameworkGlobal || ''\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:'${frameworkGlobal}',runtimeLib:'${runtimeGlobal}',framework:'${framework}'}`,\n // })\n // }\n // /**\n // * frameworkLib & runtimeLib 的全局引用\n // */\n // if (frameworkLib) {\n // const url = getRuntimeLib(frameworkLib, store.mode)\n // injectHtml.push({\n // attributes: {\n // src: url,\n // },\n // tagName: 'script',\n // // type: 'js',\n // // src: url,\n // })\n // } else if (shareLib && typeof shareLib === 'object') {\n // frameworkGlobal = !frameworkGlobal ? 'window' : frameworkGlobal\n // const exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\n\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 // if (!runtimeLib) {\n // // 内置 runtimeLib\n // store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n // //\n\n // // store.chain.optimization.merge({\n // // splitChunks: {\n // // cacheGroups: {\n // // moduleFederation: {\n // // name: 'mfRuntime',\n // // test: /[\\\\/]node_modules[\\\\/](@module-federation)[\\\\/]/,\n // // priority: 0,\n // // chunks: 'all',\n // // },\n // // },\n // // },\n // // })\n // }\n // // 统一封装到 frameworkLib\n // else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n // runtimeGlobal = frameworkGlobal\n // } else {\n // // 插入 runtime\n // injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n // }\n // if (injectHtml.length > 0) {\n // store.injectTags(injectHtml, 'EMPShare')\n // }\n // /********************************************************************\n // * 设置 externals\n // ********************************************************************\n // */\n // const externalRuntime = {\n // '@module-federation/runtime': `MFRuntime`,\n // '@module-federation/sdk': `MFSDK`,\n // }\n // const externals = {}\n // for (const [key, value] of Object.entries(externalRuntime)) {\n // externals[key] = `${runtimeGlobal}.${value}`\n // }\n // if (framework === 'react' && !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 },\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 = 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,GA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B,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,EDlNO,IAAMQ,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAChB,IAAIC,EAASF,EAAGC,CAAK,EAC7B,MAAM,CAyLjB,CACF,GAGKE,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>(\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,EAA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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"]}
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=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)},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};
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 = 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'\n//\n\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 // if (o.name) {\n // const op: any = store.deepAssign(\n // {\n // filename: 'emp.js',\n // manifest: false,\n // dts: false,\n // dev: {\n // disableDynamicRemoteTypeHints: true,\n // },\n // },\n // o,\n // )\n // delete op.empRuntime\n // store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n // }\n // const {empRuntime} = o\n // if (empRuntime) {\n // const injectHtml: any[] = []\n // const framework = empRuntime.framework || 'react'\n // const {frameworkLib, runtimeLib, shareLib} = empRuntime\n // /**\n // * shareLib 兼容\n // */\n // const externalsLib: ExternalsItemType[] = []\n // //\n // let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n // let frameworkGlobal = empRuntime.frameworkGlobal || ''\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:'${frameworkGlobal}',runtimeLib:'${runtimeGlobal}',framework:'${framework}'}`,\n // })\n // }\n // /**\n // * frameworkLib & runtimeLib 的全局引用\n // */\n // if (frameworkLib) {\n // const url = getRuntimeLib(frameworkLib, store.mode)\n // injectHtml.push({\n // attributes: {\n // src: url,\n // },\n // tagName: 'script',\n // // type: 'js',\n // // src: url,\n // })\n // } else if (shareLib && typeof shareLib === 'object') {\n // frameworkGlobal = !frameworkGlobal ? 'window' : frameworkGlobal\n // const exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\n\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 // if (!runtimeLib) {\n // // 内置 runtimeLib\n // store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n // //\n\n // // store.chain.optimization.merge({\n // // splitChunks: {\n // // cacheGroups: {\n // // moduleFederation: {\n // // name: 'mfRuntime',\n // // test: /[\\\\/]node_modules[\\\\/](@module-federation)[\\\\/]/,\n // // priority: 0,\n // // chunks: 'all',\n // // },\n // // },\n // // },\n // // })\n // }\n // // 统一封装到 frameworkLib\n // else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n // runtimeGlobal = frameworkGlobal\n // } else {\n // // 插入 runtime\n // injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n // }\n // if (injectHtml.length > 0) {\n // store.injectTags(injectHtml, 'EMPShare')\n // }\n // /********************************************************************\n // * 设置 externals\n // ********************************************************************\n // */\n // const externalRuntime = {\n // '@module-federation/runtime': `MFRuntime`,\n // '@module-federation/sdk': `MFSDK`,\n // }\n // const externals = {}\n // for (const [key, value] of Object.entries(externalRuntime)) {\n // externals[key] = `${runtimeGlobal}.${value}`\n // }\n // if (framework === 'react' && !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 },\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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AAc,KAAO,KACrBhB,EAAa,KAAKgB,CAAa,EAC/BA,EAAgB,CAAC,EAErB,MAAW,MAAM,QAAQN,CAAC,EACxBA,EAAE,IAAIQ,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,MAAM5B,CAAG,GAAK,CAAC,EAC9B2B,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,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,EKlNO,IAAMS,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAChB,IAAIC,EAASF,EAAGC,CAAK,EAC7B,MAAM,CAyLjB,CACF,GAGKE,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>(\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,GAAM,CAAC,EACjB,KAAK,MAAQC,CACf,CACA,OAAQ,CACN,KAAK,MAAM,EACX,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KA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a,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"]}