@empjs/share 3.4.6 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var c=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var S=(s,e)=>{for(var t in e)c(s,t,{get:e[t],enumerable:!0})},M=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of E(e))!x.call(s,n)&&n!==t&&c(s,n,{get:()=>e[n],enumerable:!(r=k(e,n))||r.enumerable});return s};var P=s=>M(c({},"__esModule",{value:!0}),s);var H={};S(H,{default:()=>w,pluginRspackEmpShare:()=>h});module.exports=P(H);var j=require("@module-federation/enhanced/rspack");var b=s=>`data:text/javascript,${s}`;function f(s,...e){for(let t of e)for(let r in t){let n=t[r],a=s[r];if(Object(n)==n&&Object(a)===a){s[r]=f(a,n);continue}s[r]=t[r]}return s}var L=!1,N=L?console.log.bind(console,"[EMP Share]"):()=>{};var y="EMP_SHARE_RUNTIME";var T=s=>{let e=[`import '${s}'`].join(`
2
- `);return b(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:t}=e,{runtimeLib:r,runtime:n}=this.options;if(!r&&!n?.lib){let a=T("@empjs/share/library");new t.EntryPlugin(e.context,a,{name:void 0}).apply(e)}}};function g(s,e,t="runtime"){return typeof s=="string"?t==="runtime"?`${s}/runtime${e==="development"?".development":""}.umd.js`:`${s}/${t}.${e}.umd.js`:typeof s=="object"?e==="development"?s.dev:s.prod:""}var R=/^([0-9a-zA-Z_\s]+)@(.*)/,u=class{op;store;injectHtml=[];externalsLib=[];constructor(e,t){this.op=e||{},this.store=t}setup(){this.resetRuntime(),this.resetFramework(),this.setMfName(),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.fk.lib)return;let{store:e,injectHtml:t}=this;if(this.fk.lib){let r=g(this.fk.lib,e.mode,this.fk.entry);t.push({attributes:{src:r},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:t}=this,r=this.fk.global||(e.shareLib?"window":"");e.injectGlobalValToHtml!==!1&&t.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${r}',runtimeLib:'${this.rt.global}',framework:'${this.fk.name}'}`})}fk;resetFramework(){if(!this.op.empRuntime)return;let{framework:e,frameworkGlobal:t,frameworkLib:r}=this.op.empRuntime;this.fk={name:"none",version:0,entry:"",global:t||"",lib:r||""},typeof e=="string"?this.fk.name=e:typeof e=="object"&&Object.keys(e).length>0&&(e.entry=e.entry?e.entry:e.name,this.fk=f(this.fk,e))}rt;resetRuntime(){let{empRuntime:e}=this.op;e&&(e.runtimeGlobal=e.runtimeGlobal||y,this.rt={lib:e.runtimeLib||"",global:e.runtimeGlobal})}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:t}=this,{empRuntime:r}=this.op,{shareLib:n}=r,a={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},i={};for(let[o,p]of Object.entries(a))i[o]=`${this.rt.global}.${p}`;if(this.fk.name==="react"&&!n&&this.fk.global){let o=this.fk.version,p={react:"React","react-dom":"ReactDOM"};this.fk.entry==="reactRouter"&&(p["react-router-dom"]="ReactRouterDOM");for(let[m,d]of Object.entries(p))i[m]=`${this.fk.global}.${d}`;[17,18,19].includes(o)&&(i["react-dom/client"]=this.fk.global,i["react/jsx-runtime"]=this.fk.global,i["react/jsx-dev-runtime"]=this.fk.global)}n&&t.map(o=>{o.type==="js"&&o.module&&o.global&&(i[o.module]=`${this.fk.global}.${o.global}`)}),r.setExternals&&r.setExternals(i),e.chain.merge({externals:i})}setRuntimeLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{store:t,injectHtml:r}=this,{empRuntime:n}=this.op;this.rt.lib?this.rt.lib==="useFrameworkLib"&&!e||r.push({tagName:"script",pos:"head",attributes:{src:this.rt.lib}}):t.chain.plugin("plugin-emp-share-framework").use(l,[n])}setMfName(){this.op.name?(this.op.name=this.store.encodeVarName(this.op.name),this.op.name!==this.store.empConfig.output.uniqueName&&this.store.chain.output.set("uniqueName",this.op.name)):this.op.name=this.store.empConfig.output.uniqueName}setMF(){let e=this.op,{store:t}=this;if(e.name){let r=t.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},e);r.empRuntime&&delete r.empRuntime,t.chain.plugin("plugin-emp-share").use(j.ModuleFederationPlugin,[r])}}setShareLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{externalsLib:t,injectHtml:r}=this;if(e&&typeof e=="object"){for(let[n,a]of Object.entries(e)){let i={};if(i.module=n,typeof a=="string"){let o=a.match(R)||[];o.length>0?(i.global=o[1],i.entry=o[2],i.type="js",t.push(i),i={}):(i.global="",i.entry=a,i.type="js",t.push(i),i={})}else Array.isArray(a)?a.map(o=>{if(!o)return;if(o.split("?")[0].endsWith(".css"))i.entry=o,i.type="css";else{let m=o.match(R)||[];m.length>0?(i.global=m[1],i.entry=m[2],i.type="js"):(i.global="",i.entry=o,i.type="js")}t.push(i),i={}}):typeof a=="object"&&a.entry&&(i.entry=a.entry,i.global=a.global,i.type=a.type,t.push(i),i={})}t.map(n=>{n.type==="js"?r.push({attributes:{src:n.entry},tagName:"script"}):n.type==="css"&&r.push({attributes:{href:n.entry,rel:"stylesheet"},tagName:"link"})})}}};var v=(s={})=>({name:"@empjs/share",async rsConfig(e){s.manifest===!0?s.manifest={fileName:"emp.json"}:typeof s.manifest=="object"&&(s.manifest=e.deepAssign({fileName:"emp.json"},s.manifest)),new u(s,e).setup()}}),h=v;var w=h;0&&(module.exports={pluginRspackEmpShare});
1
+ "use strict";var c=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var S=(s,e)=>{for(var t in e)c(s,t,{get:e[t],enumerable:!0})},M=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of E(e))!x.call(s,n)&&n!==t&&c(s,n,{get:()=>e[n],enumerable:!(r=k(e,n))||r.enumerable});return s};var P=s=>M(c({},"__esModule",{value:!0}),s);var H={};S(H,{default:()=>w,pluginRspackEmpShare:()=>h});module.exports=P(H);var j=require("@module-federation/enhanced/rspack");var b=s=>`data:text/javascript,${s}`;function f(s,...e){for(let t of e)for(let r in t){let n=t[r],a=s[r];if(Object(n)==n&&Object(a)===a){s[r]=f(a,n);continue}s[r]=t[r]}return s}var L=!1,O=L?console.log.bind(console,"[EMP Share]"):()=>{};var y="EMP_SHARE_RUNTIME";var T=s=>{let e=[`import '${s}'`].join(`
2
+ `);return b(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:t}=e,r=T("@empjs/share/library");new t.EntryPlugin(e.context,r,{name:void 0}).apply(e)}};function g(s,e,t="runtime"){return typeof s=="string"?t==="runtime"?`${s}/runtime${e==="development"?".development":""}.umd.js`:`${s}/${t}.${e}.umd.js`:typeof s=="object"?e==="development"?s.dev:s.prod:""}var R=/^([0-9a-zA-Z_\s]+)@(.*)/,u=class{op;store;injectHtml=[];externalsLib=[];constructor(e,t){this.op=e||{},this.store=t}setup(){this.resetRuntime(),this.resetFramework(),this.setMfName(),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.fk.lib)return;let{store:e,injectHtml:t}=this;if(this.fk.lib){let r=g(this.fk.lib,e.mode,this.fk.entry);t.push({attributes:{src:r},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:t}=this,r=this.fk.global||(e.shareLib?"window":"");e.injectGlobalValToHtml!==!1&&t.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${r}',runtimeLib:'${this.rt.global}',framework:'${this.fk.name}'}`})}fk;resetFramework(){if(!this.op.empRuntime)return;let{framework:e,frameworkGlobal:t,frameworkLib:r}=this.op.empRuntime;this.fk={name:"none",version:0,entry:"",global:t||"",lib:r||""},typeof e=="string"?this.fk.name=e:typeof e=="object"&&Object.keys(e).length>0&&(e.entry=e.entry?e.entry:e.name,this.fk=f(this.fk,e))}rt;resetRuntime(){let{empRuntime:e}=this.op;if(!e)return;let t=e.runtimeGlobal||y,r=e.runtimeLib?e.runtimeLib:e.runtime?.lib?e.runtime.lib:"";this.rt={lib:r,global:t}}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:t}=this,{empRuntime:r}=this.op,{shareLib:n}=r,a={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},i={};for(let[o,p]of Object.entries(a))i[o]=`${this.rt.global}.${p}`;if(this.fk.name==="react"&&!n&&this.fk.global){let o=this.fk.version,p={react:"React","react-dom":"ReactDOM"};this.fk.entry==="reactRouter"&&(p["react-router-dom"]="ReactRouterDOM");for(let[m,d]of Object.entries(p))i[m]=`${this.fk.global}.${d}`;[17,18,19].includes(o)&&(i["react-dom/client"]=this.fk.global,i["react/jsx-runtime"]=this.fk.global,i["react/jsx-dev-runtime"]=this.fk.global)}n&&t.map(o=>{o.type==="js"&&o.module&&o.global&&(i[o.module]=`${this.fk.global}.${o.global}`)}),r.setExternals&&r.setExternals(i),e.chain.merge({externals:i})}setRuntimeLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{store:t,injectHtml:r}=this,{empRuntime:n}=this.op;this.rt.lib?this.rt.lib==="useFrameworkLib"&&!e||r.push({tagName:"script",pos:"head",attributes:{src:this.rt.lib}}):t.chain.plugin("plugin-emp-share-framework").use(l,[n])}setMfName(){this.op.name?(this.op.name=this.store.encodeVarName(this.op.name),this.op.name!==this.store.empConfig.output.uniqueName&&this.store.chain.output.set("uniqueName",this.op.name)):this.op.name=this.store.empConfig.output.uniqueName}setMF(){let e=this.op,{store:t}=this;if(e.name){let r=t.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},e);r.empRuntime&&delete r.empRuntime,t.chain.plugin("plugin-emp-share").use(j.ModuleFederationPlugin,[r])}}setShareLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{externalsLib:t,injectHtml:r}=this;if(e&&typeof e=="object"){for(let[n,a]of Object.entries(e)){let i={};if(i.module=n,typeof a=="string"){let o=a.match(R)||[];o.length>0?(i.global=o[1],i.entry=o[2],i.type="js",t.push(i),i={}):(i.global="",i.entry=a,i.type="js",t.push(i),i={})}else Array.isArray(a)?a.map(o=>{if(!o)return;if(o.split("?")[0].endsWith(".css"))i.entry=o,i.type="css";else{let m=o.match(R)||[];m.length>0?(i.global=m[1],i.entry=m[2],i.type="js"):(i.global="",i.entry=o,i.type="js")}t.push(i),i={}}):typeof a=="object"&&a.entry&&(i.entry=a.entry,i.global=a.global,i.type=a.type,t.push(i),i={})}t.map(n=>{n.type==="js"?r.push({attributes:{src:n.entry},tagName:"script"}):n.type==="css"&&r.push({attributes:{href:n.entry,rel:"stylesheet"},tagName:"link"})})}}};var v=(s={})=>({name:"@empjs/share",async rsConfig(e){s.manifest===!0?s.manifest={fileName:"emp.json"}:typeof s.manifest=="object"&&(s.manifest=e.deepAssign({fileName:"emp.json"},s.manifest)),new u(s,e).setup()}}),h=v;var w=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/index.ts","../src/helper/config.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 {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {\n EMPPluginShareType,\n ExternalsItemType,\n ModuleFederationPluginOptions,\n frameworkOptions,\n runtimeLibType,\n} 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.resetRuntime()\n this.resetFramework()\n this.setMfName() //设置 mfName 默认为 uniqueName\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.fk.lib) return\n const {store, injectHtml} = this\n if (this.fk.lib) {\n const url = getRuntimeLib(this.fk.lib, store.mode, this.fk.entry)\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 const frameworkGlobal = this.fk.global || (empRuntime.shareLib ? 'window' : '')\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:'${this.rt.global}',framework:'${this.fk.name}'}`,\n })\n }\n }\n public fk!: Required<frameworkOptions>\n private resetFramework() {\n if (!this.op.empRuntime) return\n const {framework, frameworkGlobal, frameworkLib} = this.op.empRuntime\n //\n this.fk = {\n name: 'none',\n version: 0,\n entry: '',\n global: frameworkGlobal || '',\n lib: frameworkLib || '',\n }\n //\n if (typeof framework === 'string') {\n this.fk.name = framework as any\n } else if (typeof framework === 'object' && Object.keys(framework).length > 0) {\n // 默认 框架名 为入口\n framework.entry = framework.entry ? framework.entry : framework.name\n this.fk = deepAssign(this.fk, framework)\n }\n }\n public rt!: Required<runtimeLibType>\n private resetRuntime() {\n const {empRuntime} = this.op\n if (!empRuntime) return\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n this.rt = {\n lib: empRuntime.runtimeLib || '',\n global: empRuntime.runtimeGlobal,\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {shareLib} = empRuntime\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] = `${this.rt.global}.${value}`\n }\n if (this.fk.name === 'react' && !shareLib && this.fk.global) {\n const version = this.fk.version\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n if (this.fk.entry === 'reactRouter') {\n externalReact['react-router-dom'] = 'ReactRouterDOM'\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${this.fk.global}.${value}`\n }\n if ([17, 18, 19].includes(version)) {\n externals['react-dom/client'] = this.fk.global\n externals['react/jsx-runtime'] = this.fk.global\n externals['react/jsx-dev-runtime'] = this.fk.global\n }\n }\n if (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${this.fk.global}.${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 {shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!this.rt.lib) {\n // 内置 this.rt.lib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (this.rt.lib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: this.rt.lib}})\n }\n }\n private setMfName() {\n if (this.op.name) {\n this.op.name = this.store.encodeVarName(this.op.name)\n if (this.op.name !== this.store.empConfig.output.uniqueName) {\n this.store.chain.output.set('uniqueName', this.op.name)\n }\n } else {\n this.op.name = this.store.empConfig.output.uniqueName\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions & {empRuntime: any}>(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n if (op.empRuntime) {\n delete op.empRuntime\n }\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\n })\n }\n }\n}\n","export const 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\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\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, runtime} = this.options\n // 当没有设置 runtimeLib 时候需要内置\n if (!runtimeLib && !runtime?.lib) {\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, entry = 'runtime') {\n if (typeof host === 'string') {\n if (entry === 'runtime') {\n return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n } else {\n return `${host}/${entry}.${mode}.umd.js`\n }\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 //\n if (o.manifest === true) {\n o.manifest = {\n fileName: 'emp.json',\n }\n } else if (typeof o.manifest === 'object') {\n o.manifest = store.deepAssign({fileName: 'emp.json'}, o.manifest)\n }\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,EAAcC,GAAoB,wBAAwBA,CAAO,GAEvE,SAASC,EAAcC,KAAgBC,EA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AAOJ,GAAM,UAAYA,EAAE,QACpCI,EAAc,MAAQJ,EAAE,MACxBI,EAAc,OAASJ,EAAE,OACzBI,EAAc,KAAOJ,EAAE,KACvBR,EAAa,KAAKY,CAAa,EAC/BA,EAAgB,CAAC,EAErB,CAEAZ,EAAa,IAAIQ,GAAK,CAChBA,EAAE,OAAS,KACbjB,EAAW,KAAK,CACd,WAAY,CACV,IAAKiB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBjB,EAAW,KAAK,CACd,WAAY,CACV,KAAMiB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EK/QO,IAAMO,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAE7BD,EAAE,WAAa,GACjBA,EAAE,SAAW,CACX,SAAU,UACZ,EACS,OAAOA,EAAE,UAAa,WAC/BA,EAAE,SAAWC,EAAM,WAAW,CAAC,SAAU,UAAU,EAAGD,EAAE,QAAQ,GAEjD,IAAIE,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ,ENnBf,IAAOK,EAAQC","names":["src_exports","__export","src_default","rspack_default","__toCommonJS","import_rspack","importJsVm","content","deepAssign","target","sources","source","k","vs","vt","isDev","log","shareGlobalName","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","runtime","entry","getRuntimeLib","host","mode","entry","exp","EmpShare","op","store","injectHtml","url","getRuntimeLib","empRuntime","frameworkGlobal","framework","frameworkLib","deepAssign","shareGlobalName","externalsLib","shareLib","externalRuntime","externals","key","value","version","externalReact","v","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/index.ts","../src/helper/config.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 {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {\n EMPPluginShareType,\n ExternalsItemType,\n ModuleFederationPluginOptions,\n frameworkOptions,\n runtimeLibType,\n} 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.resetRuntime()\n this.resetFramework()\n this.setMfName() //设置 mfName 默认为 uniqueName\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.fk.lib) return\n const {store, injectHtml} = this\n if (this.fk.lib) {\n const url = getRuntimeLib(this.fk.lib, store.mode, this.fk.entry)\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 const frameworkGlobal = this.fk.global || (empRuntime.shareLib ? 'window' : '')\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:'${this.rt.global}',framework:'${this.fk.name}'}`,\n })\n }\n }\n public fk!: Required<frameworkOptions>\n private resetFramework() {\n if (!this.op.empRuntime) return\n const {framework, frameworkGlobal, frameworkLib} = this.op.empRuntime\n //\n this.fk = {\n name: 'none',\n version: 0,\n entry: '',\n global: frameworkGlobal || '',\n lib: frameworkLib || '',\n }\n //\n if (typeof framework === 'string') {\n this.fk.name = framework as any\n } else if (typeof framework === 'object' && Object.keys(framework).length > 0) {\n // 默认 框架名 为入口\n framework.entry = framework.entry ? framework.entry : framework.name\n this.fk = deepAssign(this.fk, framework)\n }\n }\n public rt!: Required<runtimeLibType>\n private resetRuntime() {\n const {empRuntime} = this.op\n if (!empRuntime) return\n const global = empRuntime.runtimeGlobal || shareGlobalName\n const lib = empRuntime.runtimeLib ? empRuntime.runtimeLib : empRuntime.runtime?.lib ? empRuntime.runtime.lib : ''\n this.rt = {\n lib,\n global,\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {shareLib} = empRuntime\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] = `${this.rt.global}.${value}`\n }\n if (this.fk.name === 'react' && !shareLib && this.fk.global) {\n const version = this.fk.version\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n if (this.fk.entry === 'reactRouter') {\n externalReact['react-router-dom'] = 'ReactRouterDOM'\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${this.fk.global}.${value}`\n }\n if ([17, 18, 19].includes(version)) {\n externals['react-dom/client'] = this.fk.global\n externals['react/jsx-runtime'] = this.fk.global\n externals['react/jsx-dev-runtime'] = this.fk.global\n }\n }\n if (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${this.fk.global}.${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 {shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!this.rt.lib) {\n // 内置 this.rt.lib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (this.rt.lib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: this.rt.lib}})\n }\n }\n private setMfName() {\n if (this.op.name) {\n this.op.name = this.store.encodeVarName(this.op.name)\n if (this.op.name !== this.store.empConfig.output.uniqueName) {\n this.store.chain.output.set('uniqueName', this.op.name)\n }\n } else {\n this.op.name = this.store.empConfig.output.uniqueName\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions & {empRuntime: any}>(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n if (op.empRuntime) {\n delete op.empRuntime\n }\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\n })\n }\n }\n}\n","export const 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\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\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}\n// 当没有设置 runtimeLib 时候需要内置\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 entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string, entry = 'runtime') {\n if (typeof host === 'string') {\n if (entry === 'runtime') {\n return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n } else {\n return `${host}/${entry}.${mode}.umd.js`\n }\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 //\n if (o.manifest === true) {\n o.manifest = {\n fileName: 'emp.json',\n }\n } else if (typeof o.manifest === 'object') {\n o.manifest = store.deepAssign({fileName: 'emp.json'}, o.manifest)\n }\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,EAAcC,GAAoB,wBAAwBA,CAAO,GAEvE,SAASC,EAAcC,KAAgBC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AE,QACpCI,EAAc,MAAQJ,EAAE,MACxBI,EAAc,OAASJ,EAAE,OACzBI,EAAc,KAAOJ,EAAE,KACvBR,EAAa,KAAKY,CAAa,EAC/BA,EAAgB,CAAC,EAErB,CAEAZ,EAAa,IAAIQ,GAAK,CAChBA,EAAE,OAAS,KACbnB,EAAW,KAAK,CACd,WAAY,CACV,IAAKmB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBnB,EAAW,KAAK,CACd,WAAY,CACV,KAAMmB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EKhRO,IAAMO,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAE7BD,EAAE,WAAa,GACjBA,EAAE,SAAW,CACX,SAAU,UACZ,EACS,OAAOA,EAAE,UAAa,WAC/BA,EAAE,SAAWC,EAAM,WAAW,CAAC,SAAU,UAAU,EAAGD,EAAE,QAAQ,GAEjD,IAAIE,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ,ENnBf,IAAOK,EAAQC","names":["src_exports","__export","src_default","rspack_default","__toCommonJS","import_rspack","importJsVm","content","deepAssign","target","sources","source","k","vs","vt","isDev","log","shareGlobalName","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","entry","getRuntimeLib","host","mode","entry","exp","EmpShare","op","store","injectHtml","url","getRuntimeLib","empRuntime","frameworkGlobal","framework","frameworkLib","deepAssign","global","shareGlobalName","lib","externalsLib","shareLib","externalRuntime","externals","key","value","version","externalReact","v","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
- import{ModuleFederationPlugin as k}from"@module-federation/enhanced/rspack";var f=r=>`data:text/javascript,${r}`;function c(r,...e){for(let i of e)for(let s in i){let o=i[s],a=r[s];if(Object(o)==o&&Object(a)===a){r[s]=c(a,o);continue}r[s]=i[s]}return r}var j=!1,x=j?console.log.bind(console,"[EMP Share]"):()=>{};var h="EMP_SHARE_RUNTIME";var d=r=>{let e=[`import '${r}'`].join(`
2
- `);return f(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:i}=e,{runtimeLib:s,runtime:o}=this.options;if(!s&&!o?.lib){let a=d("@empjs/share/library");new i.EntryPlugin(e.context,a,{name:void 0}).apply(e)}}};function b(r,e,i="runtime"){return typeof r=="string"?i==="runtime"?`${r}/runtime${e==="development"?".development":""}.umd.js`:`${r}/${i}.${e}.umd.js`:typeof r=="object"?e==="development"?r.dev:r.prod:""}var y=/^([0-9a-zA-Z_\s]+)@(.*)/,u=class{op;store;injectHtml=[];externalsLib=[];constructor(e,i){this.op=e||{},this.store=i}setup(){this.resetRuntime(),this.resetFramework(),this.setMfName(),this.setMF(),this.injectGlobalVal(),this.injectFramework(),this.setShareLib(),this.setRuntimeLib(),this.injectToHtml(),this.setExternal()}injectToHtml(){let{store:e,injectHtml:i}=this;i.length>0&&e.injectTags(i,"EMPShare")}injectFramework(){if(!this.op.empRuntime||!this.fk.lib)return;let{store:e,injectHtml:i}=this;if(this.fk.lib){let s=b(this.fk.lib,e.mode,this.fk.entry);i.push({attributes:{src:s},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:i}=this,s=this.fk.global||(e.shareLib?"window":"");e.injectGlobalValToHtml!==!1&&i.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${s}',runtimeLib:'${this.rt.global}',framework:'${this.fk.name}'}`})}fk;resetFramework(){if(!this.op.empRuntime)return;let{framework:e,frameworkGlobal:i,frameworkLib:s}=this.op.empRuntime;this.fk={name:"none",version:0,entry:"",global:i||"",lib:s||""},typeof e=="string"?this.fk.name=e:typeof e=="object"&&Object.keys(e).length>0&&(e.entry=e.entry?e.entry:e.name,this.fk=c(this.fk,e))}rt;resetRuntime(){let{empRuntime:e}=this.op;e&&(e.runtimeGlobal=e.runtimeGlobal||h,this.rt={lib:e.runtimeLib||"",global:e.runtimeGlobal})}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:i}=this,{empRuntime:s}=this.op,{shareLib:o}=s,a={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},t={};for(let[n,p]of Object.entries(a))t[n]=`${this.rt.global}.${p}`;if(this.fk.name==="react"&&!o&&this.fk.global){let n=this.fk.version,p={react:"React","react-dom":"ReactDOM"};this.fk.entry==="reactRouter"&&(p["react-router-dom"]="ReactRouterDOM");for(let[m,R]of Object.entries(p))t[m]=`${this.fk.global}.${R}`;[17,18,19].includes(n)&&(t["react-dom/client"]=this.fk.global,t["react/jsx-runtime"]=this.fk.global,t["react/jsx-dev-runtime"]=this.fk.global)}o&&i.map(n=>{n.type==="js"&&n.module&&n.global&&(t[n.module]=`${this.fk.global}.${n.global}`)}),s.setExternals&&s.setExternals(t),e.chain.merge({externals:t})}setRuntimeLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{store:i,injectHtml:s}=this,{empRuntime:o}=this.op;this.rt.lib?this.rt.lib==="useFrameworkLib"&&!e||s.push({tagName:"script",pos:"head",attributes:{src:this.rt.lib}}):i.chain.plugin("plugin-emp-share-framework").use(l,[o])}setMfName(){this.op.name?(this.op.name=this.store.encodeVarName(this.op.name),this.op.name!==this.store.empConfig.output.uniqueName&&this.store.chain.output.set("uniqueName",this.op.name)):this.op.name=this.store.empConfig.output.uniqueName}setMF(){let e=this.op,{store:i}=this;if(e.name){let s=i.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},e);s.empRuntime&&delete s.empRuntime,i.chain.plugin("plugin-emp-share").use(k,[s])}}setShareLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{externalsLib:i,injectHtml:s}=this;if(e&&typeof e=="object"){for(let[o,a]of Object.entries(e)){let t={};if(t.module=o,typeof a=="string"){let n=a.match(y)||[];n.length>0?(t.global=n[1],t.entry=n[2],t.type="js",i.push(t),t={}):(t.global="",t.entry=a,t.type="js",i.push(t),t={})}else Array.isArray(a)?a.map(n=>{if(!n)return;if(n.split("?")[0].endsWith(".css"))t.entry=n,t.type="css";else{let m=n.match(y)||[];m.length>0?(t.global=m[1],t.entry=m[2],t.type="js"):(t.global="",t.entry=n,t.type="js")}i.push(t),t={}}):typeof a=="object"&&a.entry&&(t.entry=a.entry,t.global=a.global,t.type=a.type,i.push(t),t={})}i.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 E=(r={})=>({name:"@empjs/share",async rsConfig(e){r.manifest===!0?r.manifest={fileName:"emp.json"}:typeof r.manifest=="object"&&(r.manifest=e.deepAssign({fileName:"emp.json"},r.manifest)),new u(r,e).setup()}}),g=E;var V=g;export{V as default,g as pluginRspackEmpShare};
1
+ import{ModuleFederationPlugin as k}from"@module-federation/enhanced/rspack";var f=r=>`data:text/javascript,${r}`;function c(r,...e){for(let t of e)for(let s in t){let o=t[s],a=r[s];if(Object(o)==o&&Object(a)===a){r[s]=c(a,o);continue}r[s]=t[s]}return r}var j=!1,x=j?console.log.bind(console,"[EMP Share]"):()=>{};var h="EMP_SHARE_RUNTIME";var d=r=>{let e=[`import '${r}'`].join(`
2
+ `);return f(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:t}=e,s=d("@empjs/share/library");new t.EntryPlugin(e.context,s,{name:void 0}).apply(e)}};function b(r,e,t="runtime"){return typeof r=="string"?t==="runtime"?`${r}/runtime${e==="development"?".development":""}.umd.js`:`${r}/${t}.${e}.umd.js`:typeof r=="object"?e==="development"?r.dev:r.prod:""}var y=/^([0-9a-zA-Z_\s]+)@(.*)/,u=class{op;store;injectHtml=[];externalsLib=[];constructor(e,t){this.op=e||{},this.store=t}setup(){this.resetRuntime(),this.resetFramework(),this.setMfName(),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.fk.lib)return;let{store:e,injectHtml:t}=this;if(this.fk.lib){let s=b(this.fk.lib,e.mode,this.fk.entry);t.push({attributes:{src:s},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:t}=this,s=this.fk.global||(e.shareLib?"window":"");e.injectGlobalValToHtml!==!1&&t.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${s}',runtimeLib:'${this.rt.global}',framework:'${this.fk.name}'}`})}fk;resetFramework(){if(!this.op.empRuntime)return;let{framework:e,frameworkGlobal:t,frameworkLib:s}=this.op.empRuntime;this.fk={name:"none",version:0,entry:"",global:t||"",lib:s||""},typeof e=="string"?this.fk.name=e:typeof e=="object"&&Object.keys(e).length>0&&(e.entry=e.entry?e.entry:e.name,this.fk=c(this.fk,e))}rt;resetRuntime(){let{empRuntime:e}=this.op;if(!e)return;let t=e.runtimeGlobal||h,s=e.runtimeLib?e.runtimeLib:e.runtime?.lib?e.runtime.lib:"";this.rt={lib:s,global:t}}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:t}=this,{empRuntime:s}=this.op,{shareLib:o}=s,a={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},i={};for(let[n,p]of Object.entries(a))i[n]=`${this.rt.global}.${p}`;if(this.fk.name==="react"&&!o&&this.fk.global){let n=this.fk.version,p={react:"React","react-dom":"ReactDOM"};this.fk.entry==="reactRouter"&&(p["react-router-dom"]="ReactRouterDOM");for(let[m,R]of Object.entries(p))i[m]=`${this.fk.global}.${R}`;[17,18,19].includes(n)&&(i["react-dom/client"]=this.fk.global,i["react/jsx-runtime"]=this.fk.global,i["react/jsx-dev-runtime"]=this.fk.global)}o&&t.map(n=>{n.type==="js"&&n.module&&n.global&&(i[n.module]=`${this.fk.global}.${n.global}`)}),s.setExternals&&s.setExternals(i),e.chain.merge({externals:i})}setRuntimeLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{store:t,injectHtml:s}=this,{empRuntime:o}=this.op;this.rt.lib?this.rt.lib==="useFrameworkLib"&&!e||s.push({tagName:"script",pos:"head",attributes:{src:this.rt.lib}}):t.chain.plugin("plugin-emp-share-framework").use(l,[o])}setMfName(){this.op.name?(this.op.name=this.store.encodeVarName(this.op.name),this.op.name!==this.store.empConfig.output.uniqueName&&this.store.chain.output.set("uniqueName",this.op.name)):this.op.name=this.store.empConfig.output.uniqueName}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);s.empRuntime&&delete s.empRuntime,t.chain.plugin("plugin-emp-share").use(k,[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,a]of Object.entries(e)){let i={};if(i.module=o,typeof a=="string"){let n=a.match(y)||[];n.length>0?(i.global=n[1],i.entry=n[2],i.type="js",t.push(i),i={}):(i.global="",i.entry=a,i.type="js",t.push(i),i={})}else Array.isArray(a)?a.map(n=>{if(!n)return;if(n.split("?")[0].endsWith(".css"))i.entry=n,i.type="css";else{let m=n.match(y)||[];m.length>0?(i.global=m[1],i.entry=m[2],i.type="js"):(i.global="",i.entry=n,i.type="js")}t.push(i),i={}}):typeof a=="object"&&a.entry&&(i.entry=a.entry,i.global=a.global,i.type=a.type,t.push(i),i={})}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 E=(r={})=>({name:"@empjs/share",async rsConfig(e){r.manifest===!0?r.manifest={fileName:"emp.json"}:typeof r.manifest=="object"&&(r.manifest=e.deepAssign({fileName:"emp.json"},r.manifest)),new u(r,e).setup()}}),g=E;var V=g;export{V as default,g 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/index.ts","../src/helper/config.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 {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {\n EMPPluginShareType,\n ExternalsItemType,\n ModuleFederationPluginOptions,\n frameworkOptions,\n runtimeLibType,\n} 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.resetRuntime()\n this.resetFramework()\n this.setMfName() //设置 mfName 默认为 uniqueName\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.fk.lib) return\n const {store, injectHtml} = this\n if (this.fk.lib) {\n const url = getRuntimeLib(this.fk.lib, store.mode, this.fk.entry)\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 const frameworkGlobal = this.fk.global || (empRuntime.shareLib ? 'window' : '')\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:'${this.rt.global}',framework:'${this.fk.name}'}`,\n })\n }\n }\n public fk!: Required<frameworkOptions>\n private resetFramework() {\n if (!this.op.empRuntime) return\n const {framework, frameworkGlobal, frameworkLib} = this.op.empRuntime\n //\n this.fk = {\n name: 'none',\n version: 0,\n entry: '',\n global: frameworkGlobal || '',\n lib: frameworkLib || '',\n }\n //\n if (typeof framework === 'string') {\n this.fk.name = framework as any\n } else if (typeof framework === 'object' && Object.keys(framework).length > 0) {\n // 默认 框架名 为入口\n framework.entry = framework.entry ? framework.entry : framework.name\n this.fk = deepAssign(this.fk, framework)\n }\n }\n public rt!: Required<runtimeLibType>\n private resetRuntime() {\n const {empRuntime} = this.op\n if (!empRuntime) return\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n this.rt = {\n lib: empRuntime.runtimeLib || '',\n global: empRuntime.runtimeGlobal,\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {shareLib} = empRuntime\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] = `${this.rt.global}.${value}`\n }\n if (this.fk.name === 'react' && !shareLib && this.fk.global) {\n const version = this.fk.version\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n if (this.fk.entry === 'reactRouter') {\n externalReact['react-router-dom'] = 'ReactRouterDOM'\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${this.fk.global}.${value}`\n }\n if ([17, 18, 19].includes(version)) {\n externals['react-dom/client'] = this.fk.global\n externals['react/jsx-runtime'] = this.fk.global\n externals['react/jsx-dev-runtime'] = this.fk.global\n }\n }\n if (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${this.fk.global}.${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 {shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!this.rt.lib) {\n // 内置 this.rt.lib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (this.rt.lib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: this.rt.lib}})\n }\n }\n private setMfName() {\n if (this.op.name) {\n this.op.name = this.store.encodeVarName(this.op.name)\n if (this.op.name !== this.store.empConfig.output.uniqueName) {\n this.store.chain.output.set('uniqueName', this.op.name)\n }\n } else {\n this.op.name = this.store.empConfig.output.uniqueName\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions & {empRuntime: any}>(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n if (op.empRuntime) {\n delete op.empRuntime\n }\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\n })\n }\n }\n}\n","export const 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\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\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, runtime} = this.options\n // 当没有设置 runtimeLib 时候需要内置\n if (!runtimeLib && !runtime?.lib) {\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, entry = 'runtime') {\n if (typeof host === 'string') {\n if (entry === 'runtime') {\n return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n } else {\n return `${host}/${entry}.${mode}.umd.js`\n }\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 //\n if (o.manifest === true) {\n o.manifest = {\n fileName: 'emp.json',\n }\n } else if (typeof o.manifest === 'object') {\n o.manifest = store.deepAssign({fileName: 'emp.json'}, o.manifest)\n }\n const empShare = new EmpShare(o, store)\n empShare.setup()\n },\n }\n}\nexport default pluginRspackEmpShare\n","import {default as pluginRspackEmpShare} from 'src/plugins/rspack'\nexport default pluginRspackEmpShare\nexport {pluginRspackEmpShare}\n"],"mappings":"AACA,OAAQ,0BAAAA,MAA6B,qCCD9B,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GAEvE,SAASC,EAAcC,KAAgBC,EAAiB,CAC7D,QAAWC,KAAUD,EACnB,QAAWE,KAAKD,EAAQ,CACtB,IAAME,EAAKF,EAAOC,CAAC,EACjBE,EAAKL,EAAOG,CAAC,EACf,GAAI,OAAOC,CAAE,GAAKA,GAAM,OAAOC,CAAE,IAAMA,EAAI,CACzCL,EAAOG,CAAC,EAAIJ,EAAWM,EAAID,CAAE,EAC7B,QACF,CACAJ,EAAOG,CAAC,EAAID,EAAOC,CAAC,CACtB,CAEF,OAAOH,CACT,CAMO,IAAMM,EAAQ,GACRC,EAAMD,EAAQ,QAAQ,IAAI,KAAK,QAAS,aAAa,EAAI,IAAM,CAAC,ECtBtE,IAAME,EAAkB,oBCG/B,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,EAAY,QAAAC,CAAO,EAAI,KAAK,QAEnC,GAAI,CAACD,GAAc,CAACC,GAAS,IAAK,CAChC,IAAMC,EAAQV,EAAqB,sBAAsB,EACzD,IAAIO,EAAQ,YAAYD,EAAS,QAASI,EAAO,CAC/C,KAAM,MACR,CAAC,EAAE,MAAMJ,CAAQ,CACnB,CACF,CACF,ECtBO,SAASK,EAAcC,EAA8CC,EAAcC,EAAQ,UAAW,CAC3G,OA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M5B,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,CACAb,EAAa,KAAKa,CAAa,EAC/BA,EAAgB,CAAC,CACnB,CAAC,EACQ,OAAOL,GAAM,UAAYA,EAAE,QACpCK,EAAc,MAAQL,EAAE,MACxBK,EAAc,OAASL,EAAE,OACzBK,EAAc,KAAOL,EAAE,KACvBR,EAAa,KAAKa,CAAa,EAC/BA,EAAgB,CAAC,EAErB,CAEAb,EAAa,IAAIQ,GAAK,CAChBA,EAAE,OAAS,KACbjB,EAAW,KAAK,CACd,WAAY,CACV,IAAKiB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBjB,EAAW,KAAK,CACd,WAAY,CACV,KAAMiB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EK/QO,IAAMQ,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAE7BD,EAAE,WAAa,GACjBA,EAAE,SAAW,CACX,SAAU,UACZ,EACS,OAAOA,EAAE,UAAa,WAC/BA,EAAE,SAAWC,EAAM,WAAW,CAAC,SAAU,UAAU,EAAGD,EAAE,QAAQ,GAEjD,IAAIE,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ,ECnBf,IAAOK,EAAQC","names":["ModuleFederationPlugin","importJsVm","content","deepAssign","target","sources","source","k","vs","vt","isDev","log","shareGlobalName","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","runtime","entry","getRuntimeLib","host","mode","entry","exp","EmpShare","op","store","injectHtml","url","getRuntimeLib","empRuntime","frameworkGlobal","framework","frameworkLib","deepAssign","shareGlobalName","externalsLib","shareLib","externalRuntime","externals","key","value","version","externalReact","v","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/index.ts","../src/helper/config.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 {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {\n EMPPluginShareType,\n ExternalsItemType,\n ModuleFederationPluginOptions,\n frameworkOptions,\n runtimeLibType,\n} 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.resetRuntime()\n this.resetFramework()\n this.setMfName() //设置 mfName 默认为 uniqueName\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.fk.lib) return\n const {store, injectHtml} = this\n if (this.fk.lib) {\n const url = getRuntimeLib(this.fk.lib, store.mode, this.fk.entry)\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 const frameworkGlobal = this.fk.global || (empRuntime.shareLib ? 'window' : '')\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:'${this.rt.global}',framework:'${this.fk.name}'}`,\n })\n }\n }\n public fk!: Required<frameworkOptions>\n private resetFramework() {\n if (!this.op.empRuntime) return\n const {framework, frameworkGlobal, frameworkLib} = this.op.empRuntime\n //\n this.fk = {\n name: 'none',\n version: 0,\n entry: '',\n global: frameworkGlobal || '',\n lib: frameworkLib || '',\n }\n //\n if (typeof framework === 'string') {\n this.fk.name = framework as any\n } else if (typeof framework === 'object' && Object.keys(framework).length > 0) {\n // 默认 框架名 为入口\n framework.entry = framework.entry ? framework.entry : framework.name\n this.fk = deepAssign(this.fk, framework)\n }\n }\n public rt!: Required<runtimeLibType>\n private resetRuntime() {\n const {empRuntime} = this.op\n if (!empRuntime) return\n const global = empRuntime.runtimeGlobal || shareGlobalName\n const lib = empRuntime.runtimeLib ? empRuntime.runtimeLib : empRuntime.runtime?.lib ? empRuntime.runtime.lib : ''\n this.rt = {\n lib,\n global,\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {shareLib} = empRuntime\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] = `${this.rt.global}.${value}`\n }\n if (this.fk.name === 'react' && !shareLib && this.fk.global) {\n const version = this.fk.version\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n if (this.fk.entry === 'reactRouter') {\n externalReact['react-router-dom'] = 'ReactRouterDOM'\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${this.fk.global}.${value}`\n }\n if ([17, 18, 19].includes(version)) {\n externals['react-dom/client'] = this.fk.global\n externals['react/jsx-runtime'] = this.fk.global\n externals['react/jsx-dev-runtime'] = this.fk.global\n }\n }\n if (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${this.fk.global}.${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 {shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!this.rt.lib) {\n // 内置 this.rt.lib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (this.rt.lib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: this.rt.lib}})\n }\n }\n private setMfName() {\n if (this.op.name) {\n this.op.name = this.store.encodeVarName(this.op.name)\n if (this.op.name !== this.store.empConfig.output.uniqueName) {\n this.store.chain.output.set('uniqueName', this.op.name)\n }\n } else {\n this.op.name = this.store.empConfig.output.uniqueName\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions & {empRuntime: any}>(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n if (op.empRuntime) {\n delete op.empRuntime\n }\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\n })\n }\n }\n}\n","export const 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\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\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}\n// 当没有设置 runtimeLib 时候需要内置\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 entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string, entry = 'runtime') {\n if (typeof host === 'string') {\n if (entry === 'runtime') {\n return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n } else {\n return `${host}/${entry}.${mode}.umd.js`\n }\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 //\n if (o.manifest === true) {\n o.manifest = {\n fileName: 'emp.json',\n }\n } else if (typeof o.manifest === 'object') {\n o.manifest = store.deepAssign({fileName: 'emp.json'}, o.manifest)\n }\n const empShare = new EmpShare(o, store)\n empShare.setup()\n },\n }\n}\nexport default pluginRspackEmpShare\n","import {default as pluginRspackEmpShare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,EAAc,KAAO,OAErBA,EAAc,OAAS,GACvBA,EAAc,MAAQE,EACtBF,EAAc,KAAO,KAEzB,CACAb,EAAa,KAAKa,CAAa,EAC/BA,EAAgB,CAAC,CACnB,CAAC,EACQ,OAAOL,GAAM,UAAYA,EAAE,QACpCK,EAAc,MAAQL,EAAE,MACxBK,EAAc,OAASL,EAAE,OACzBK,EAAc,KAAOL,EAAE,KACvBR,EAAa,KAAKa,CAAa,EAC/BA,EAAgB,CAAC,EAErB,CAEAb,EAAa,IAAIQ,GAAK,CAChBA,EAAE,OAAS,KACbnB,EAAW,KAAK,CACd,WAAY,CACV,IAAKmB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBnB,EAAW,KAAK,CACd,WAAY,CACV,KAAMmB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EKhRO,IAAMQ,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAE7BD,EAAE,WAAa,GACjBA,EAAE,SAAW,CACX,SAAU,UACZ,EACS,OAAOA,EAAE,UAAa,WAC/BA,EAAE,SAAWC,EAAM,WAAW,CAAC,SAAU,UAAU,EAAGD,EAAE,QAAQ,GAEjD,IAAIE,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ,ECnBf,IAAOK,EAAQC","names":["ModuleFederationPlugin","importJsVm","content","deepAssign","target","sources","source","k","vs","vt","isDev","log","shareGlobalName","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","entry","getRuntimeLib","host","mode","entry","exp","EmpShare","op","store","injectHtml","url","getRuntimeLib","empRuntime","frameworkGlobal","framework","frameworkLib","deepAssign","global","shareGlobalName","lib","externalsLib","shareLib","externalRuntime","externals","key","value","version","externalReact","v","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 c=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var x=(s,e)=>{for(var t in e)c(s,t,{get:e[t],enumerable:!0})},M=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of E(e))!S.call(s,n)&&n!==t&&c(s,n,{get:()=>e[n],enumerable:!(r=d(e,n))||r.enumerable});return s};var P=s=>M(c({},"__esModule",{value:!0}),s);var w={};x(w,{default:()=>v,pluginRspackEmpShare:()=>R});module.exports=P(w);var j=require("@module-federation/enhanced/rspack");var h=s=>`data:text/javascript,${s}`;function f(s,...e){for(let t of e)for(let r in t){let n=t[r],a=s[r];if(Object(n)==n&&Object(a)===a){s[r]=f(a,n);continue}s[r]=t[r]}return s}var L=!1,G=L?console.log.bind(console,"[EMP Share]"):()=>{};var b="EMP_SHARE_RUNTIME";var T=s=>{let e=[`import '${s}'`].join(`
2
- `);return h(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:t}=e,{runtimeLib:r,runtime:n}=this.options;if(!r&&!n?.lib){let a=T("@empjs/share/library");new t.EntryPlugin(e.context,a,{name:void 0}).apply(e)}}};function y(s,e,t="runtime"){return typeof s=="string"?t==="runtime"?`${s}/runtime${e==="development"?".development":""}.umd.js`:`${s}/${t}.${e}.umd.js`:typeof s=="object"?e==="development"?s.dev:s.prod:""}var g=/^([0-9a-zA-Z_\s]+)@(.*)/,u=class{op;store;injectHtml=[];externalsLib=[];constructor(e,t){this.op=e||{},this.store=t}setup(){this.resetRuntime(),this.resetFramework(),this.setMfName(),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.fk.lib)return;let{store:e,injectHtml:t}=this;if(this.fk.lib){let r=y(this.fk.lib,e.mode,this.fk.entry);t.push({attributes:{src:r},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:t}=this,r=this.fk.global||(e.shareLib?"window":"");e.injectGlobalValToHtml!==!1&&t.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${r}',runtimeLib:'${this.rt.global}',framework:'${this.fk.name}'}`})}fk;resetFramework(){if(!this.op.empRuntime)return;let{framework:e,frameworkGlobal:t,frameworkLib:r}=this.op.empRuntime;this.fk={name:"none",version:0,entry:"",global:t||"",lib:r||""},typeof e=="string"?this.fk.name=e:typeof e=="object"&&Object.keys(e).length>0&&(e.entry=e.entry?e.entry:e.name,this.fk=f(this.fk,e))}rt;resetRuntime(){let{empRuntime:e}=this.op;e&&(e.runtimeGlobal=e.runtimeGlobal||b,this.rt={lib:e.runtimeLib||"",global:e.runtimeGlobal})}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:t}=this,{empRuntime:r}=this.op,{shareLib:n}=r,a={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},i={};for(let[o,p]of Object.entries(a))i[o]=`${this.rt.global}.${p}`;if(this.fk.name==="react"&&!n&&this.fk.global){let o=this.fk.version,p={react:"React","react-dom":"ReactDOM"};this.fk.entry==="reactRouter"&&(p["react-router-dom"]="ReactRouterDOM");for(let[m,k]of Object.entries(p))i[m]=`${this.fk.global}.${k}`;[17,18,19].includes(o)&&(i["react-dom/client"]=this.fk.global,i["react/jsx-runtime"]=this.fk.global,i["react/jsx-dev-runtime"]=this.fk.global)}n&&t.map(o=>{o.type==="js"&&o.module&&o.global&&(i[o.module]=`${this.fk.global}.${o.global}`)}),r.setExternals&&r.setExternals(i),e.chain.merge({externals:i})}setRuntimeLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{store:t,injectHtml:r}=this,{empRuntime:n}=this.op;this.rt.lib?this.rt.lib==="useFrameworkLib"&&!e||r.push({tagName:"script",pos:"head",attributes:{src:this.rt.lib}}):t.chain.plugin("plugin-emp-share-framework").use(l,[n])}setMfName(){this.op.name?(this.op.name=this.store.encodeVarName(this.op.name),this.op.name!==this.store.empConfig.output.uniqueName&&this.store.chain.output.set("uniqueName",this.op.name)):this.op.name=this.store.empConfig.output.uniqueName}setMF(){let e=this.op,{store:t}=this;if(e.name){let r=t.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},e);r.empRuntime&&delete r.empRuntime,t.chain.plugin("plugin-emp-share").use(j.ModuleFederationPlugin,[r])}}setShareLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{externalsLib:t,injectHtml:r}=this;if(e&&typeof e=="object"){for(let[n,a]of Object.entries(e)){let i={};if(i.module=n,typeof a=="string"){let o=a.match(g)||[];o.length>0?(i.global=o[1],i.entry=o[2],i.type="js",t.push(i),i={}):(i.global="",i.entry=a,i.type="js",t.push(i),i={})}else Array.isArray(a)?a.map(o=>{if(!o)return;if(o.split("?")[0].endsWith(".css"))i.entry=o,i.type="css";else{let m=o.match(g)||[];m.length>0?(i.global=m[1],i.entry=m[2],i.type="js"):(i.global="",i.entry=o,i.type="js")}t.push(i),i={}}):typeof a=="object"&&a.entry&&(i.entry=a.entry,i.global=a.global,i.type=a.type,t.push(i),i={})}t.map(n=>{n.type==="js"?r.push({attributes:{src:n.entry},tagName:"script"}):n.type==="css"&&r.push({attributes:{href:n.entry,rel:"stylesheet"},tagName:"link"})})}}};var R=(s={})=>({name:"@empjs/share",async rsConfig(e){s.manifest===!0?s.manifest={fileName:"emp.json"}:typeof s.manifest=="object"&&(s.manifest=e.deepAssign({fileName:"emp.json"},s.manifest)),new u(s,e).setup()}}),v=R;0&&(module.exports={pluginRspackEmpShare});
1
+ "use strict";var u=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var x=(s,e)=>{for(var t in e)u(s,t,{get:e[t],enumerable:!0})},M=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of E(e))!S.call(s,n)&&n!==t&&u(s,n,{get:()=>e[n],enumerable:!(r=d(e,n))||r.enumerable});return s};var P=s=>M(u({},"__esModule",{value:!0}),s);var w={};x(w,{default:()=>v,pluginRspackEmpShare:()=>R});module.exports=P(w);var j=require("@module-federation/enhanced/rspack");var h=s=>`data:text/javascript,${s}`;function f(s,...e){for(let t of e)for(let r in t){let n=t[r],a=s[r];if(Object(n)==n&&Object(a)===a){s[r]=f(a,n);continue}s[r]=t[r]}return s}var L=!1,N=L?console.log.bind(console,"[EMP Share]"):()=>{};var b="EMP_SHARE_RUNTIME";var T=s=>{let e=[`import '${s}'`].join(`
2
+ `);return h(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:t}=e,r=T("@empjs/share/library");new t.EntryPlugin(e.context,r,{name:void 0}).apply(e)}};function y(s,e,t="runtime"){return typeof s=="string"?t==="runtime"?`${s}/runtime${e==="development"?".development":""}.umd.js`:`${s}/${t}.${e}.umd.js`:typeof s=="object"?e==="development"?s.dev:s.prod:""}var g=/^([0-9a-zA-Z_\s]+)@(.*)/,c=class{op;store;injectHtml=[];externalsLib=[];constructor(e,t){this.op=e||{},this.store=t}setup(){this.resetRuntime(),this.resetFramework(),this.setMfName(),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.fk.lib)return;let{store:e,injectHtml:t}=this;if(this.fk.lib){let r=y(this.fk.lib,e.mode,this.fk.entry);t.push({attributes:{src:r},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:t}=this,r=this.fk.global||(e.shareLib?"window":"");e.injectGlobalValToHtml!==!1&&t.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${r}',runtimeLib:'${this.rt.global}',framework:'${this.fk.name}'}`})}fk;resetFramework(){if(!this.op.empRuntime)return;let{framework:e,frameworkGlobal:t,frameworkLib:r}=this.op.empRuntime;this.fk={name:"none",version:0,entry:"",global:t||"",lib:r||""},typeof e=="string"?this.fk.name=e:typeof e=="object"&&Object.keys(e).length>0&&(e.entry=e.entry?e.entry:e.name,this.fk=f(this.fk,e))}rt;resetRuntime(){let{empRuntime:e}=this.op;if(!e)return;let t=e.runtimeGlobal||b,r=e.runtimeLib?e.runtimeLib:e.runtime?.lib?e.runtime.lib:"";this.rt={lib:r,global:t}}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:t}=this,{empRuntime:r}=this.op,{shareLib:n}=r,a={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},i={};for(let[o,p]of Object.entries(a))i[o]=`${this.rt.global}.${p}`;if(this.fk.name==="react"&&!n&&this.fk.global){let o=this.fk.version,p={react:"React","react-dom":"ReactDOM"};this.fk.entry==="reactRouter"&&(p["react-router-dom"]="ReactRouterDOM");for(let[m,k]of Object.entries(p))i[m]=`${this.fk.global}.${k}`;[17,18,19].includes(o)&&(i["react-dom/client"]=this.fk.global,i["react/jsx-runtime"]=this.fk.global,i["react/jsx-dev-runtime"]=this.fk.global)}n&&t.map(o=>{o.type==="js"&&o.module&&o.global&&(i[o.module]=`${this.fk.global}.${o.global}`)}),r.setExternals&&r.setExternals(i),e.chain.merge({externals:i})}setRuntimeLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{store:t,injectHtml:r}=this,{empRuntime:n}=this.op;this.rt.lib?this.rt.lib==="useFrameworkLib"&&!e||r.push({tagName:"script",pos:"head",attributes:{src:this.rt.lib}}):t.chain.plugin("plugin-emp-share-framework").use(l,[n])}setMfName(){this.op.name?(this.op.name=this.store.encodeVarName(this.op.name),this.op.name!==this.store.empConfig.output.uniqueName&&this.store.chain.output.set("uniqueName",this.op.name)):this.op.name=this.store.empConfig.output.uniqueName}setMF(){let e=this.op,{store:t}=this;if(e.name){let r=t.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},e);r.empRuntime&&delete r.empRuntime,t.chain.plugin("plugin-emp-share").use(j.ModuleFederationPlugin,[r])}}setShareLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{externalsLib:t,injectHtml:r}=this;if(e&&typeof e=="object"){for(let[n,a]of Object.entries(e)){let i={};if(i.module=n,typeof a=="string"){let o=a.match(g)||[];o.length>0?(i.global=o[1],i.entry=o[2],i.type="js",t.push(i),i={}):(i.global="",i.entry=a,i.type="js",t.push(i),i={})}else Array.isArray(a)?a.map(o=>{if(!o)return;if(o.split("?")[0].endsWith(".css"))i.entry=o,i.type="css";else{let m=o.match(g)||[];m.length>0?(i.global=m[1],i.entry=m[2],i.type="js"):(i.global="",i.entry=o,i.type="js")}t.push(i),i={}}):typeof a=="object"&&a.entry&&(i.entry=a.entry,i.global=a.global,i.type=a.type,t.push(i),i={})}t.map(n=>{n.type==="js"?r.push({attributes:{src:n.entry},tagName:"script"}):n.type==="css"&&r.push({attributes:{href:n.entry,rel:"stylesheet"},tagName:"link"})})}}};var R=(s={})=>({name:"@empjs/share",async rsConfig(e){s.manifest===!0?s.manifest={fileName:"emp.json"}:typeof s.manifest=="object"&&(s.manifest=e.deepAssign({fileName:"emp.json"},s.manifest)),new c(s,e).setup()}}),v=R;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/index.ts","../src/helper/config.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 //\n if (o.manifest === true) {\n o.manifest = {\n fileName: 'emp.json',\n }\n } else if (typeof o.manifest === 'object') {\n o.manifest = store.deepAssign({fileName: 'emp.json'}, o.manifest)\n }\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 {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {\n EMPPluginShareType,\n ExternalsItemType,\n ModuleFederationPluginOptions,\n frameworkOptions,\n runtimeLibType,\n} 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.resetRuntime()\n this.resetFramework()\n this.setMfName() //设置 mfName 默认为 uniqueName\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.fk.lib) return\n const {store, injectHtml} = this\n if (this.fk.lib) {\n const url = getRuntimeLib(this.fk.lib, store.mode, this.fk.entry)\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 const frameworkGlobal = this.fk.global || (empRuntime.shareLib ? 'window' : '')\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:'${this.rt.global}',framework:'${this.fk.name}'}`,\n })\n }\n }\n public fk!: Required<frameworkOptions>\n private resetFramework() {\n if (!this.op.empRuntime) return\n const {framework, frameworkGlobal, frameworkLib} = this.op.empRuntime\n //\n this.fk = {\n name: 'none',\n version: 0,\n entry: '',\n global: frameworkGlobal || '',\n lib: frameworkLib || '',\n }\n //\n if (typeof framework === 'string') {\n this.fk.name = framework as any\n } else if (typeof framework === 'object' && Object.keys(framework).length > 0) {\n // 默认 框架名 为入口\n framework.entry = framework.entry ? framework.entry : framework.name\n this.fk = deepAssign(this.fk, framework)\n }\n }\n public rt!: Required<runtimeLibType>\n private resetRuntime() {\n const {empRuntime} = this.op\n if (!empRuntime) return\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n this.rt = {\n lib: empRuntime.runtimeLib || '',\n global: empRuntime.runtimeGlobal,\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {shareLib} = empRuntime\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] = `${this.rt.global}.${value}`\n }\n if (this.fk.name === 'react' && !shareLib && this.fk.global) {\n const version = this.fk.version\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n if (this.fk.entry === 'reactRouter') {\n externalReact['react-router-dom'] = 'ReactRouterDOM'\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${this.fk.global}.${value}`\n }\n if ([17, 18, 19].includes(version)) {\n externals['react-dom/client'] = this.fk.global\n externals['react/jsx-runtime'] = this.fk.global\n externals['react/jsx-dev-runtime'] = this.fk.global\n }\n }\n if (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${this.fk.global}.${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 {shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!this.rt.lib) {\n // 内置 this.rt.lib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (this.rt.lib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: this.rt.lib}})\n }\n }\n private setMfName() {\n if (this.op.name) {\n this.op.name = this.store.encodeVarName(this.op.name)\n if (this.op.name !== this.store.empConfig.output.uniqueName) {\n this.store.chain.output.set('uniqueName', this.op.name)\n }\n } else {\n this.op.name = this.store.empConfig.output.uniqueName\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions & {empRuntime: any}>(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n if (op.empRuntime) {\n delete op.empRuntime\n }\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\n })\n }\n }\n}\n","export const 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\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\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, runtime} = this.options\n // 当没有设置 runtimeLib 时候需要内置\n if (!runtimeLib && !runtime?.lib) {\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, entry = 'runtime') {\n if (typeof host === 'string') {\n if (entry === 'runtime') {\n return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n } else {\n return `${host}/${entry}.${mode}.umd.js`\n }\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,EAAcC,GAAoB,wBAAwBA,CAAO,GAEvE,SAASC,EAAcC,KAAgBC,EAAiB,CAC7D,QAAWC,KAAUD,EACnB,QAAWE,KAAKD,EAAQ,CACtB,IAAME,EAAKF,EAAOC,CAAC,EACjBE,EAAKL,EAAOG,CAAC,EACf,GAAI,OAAOC,CAAE,GAAKA,GAAM,OAAOC,CAA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CAEAZ,EAAa,IAAIQ,GAAK,CAChBA,EAAE,OAAS,KACbjB,EAAW,KAAK,CACd,WAAY,CACV,IAAKiB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBjB,EAAW,KAAK,CACd,WAAY,CACV,KAAMiB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,ED/QO,IAAMO,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAE7BD,EAAE,WAAa,GACjBA,EAAE,SAAW,CACX,SAAU,UACZ,EACS,OAAOA,EAAE,UAAa,WAC/BA,EAAE,SAAWC,EAAM,WAAW,CAAC,SAAU,UAAU,EAAGD,EAAE,QAAQ,GAEjD,IAAIE,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ","names":["rspack_exports","__export","rspack_default","pluginRspackEmpShare","__toCommonJS","import_rspack","importJsVm","content","deepAssign","target","sources","source","k","vs","vt","isDev","log","shareGlobalName","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","runtime","entry","getRuntimeLib","host","mode","entry","exp","EmpShare","op","store","injectHtml","url","getRuntimeLib","empRuntime","frameworkGlobal","framework","frameworkLib","deepAssign","shareGlobalName","externalsLib","shareLib","externalRuntime","externals","key","value","version","externalReact","v","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/index.ts","../src/helper/config.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 //\n if (o.manifest === true) {\n o.manifest = {\n fileName: 'emp.json',\n }\n } else if (typeof o.manifest === 'object') {\n o.manifest = store.deepAssign({fileName: 'emp.json'}, o.manifest)\n }\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 {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {\n EMPPluginShareType,\n ExternalsItemType,\n ModuleFederationPluginOptions,\n frameworkOptions,\n runtimeLibType,\n} 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.resetRuntime()\n this.resetFramework()\n this.setMfName() //设置 mfName 默认为 uniqueName\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.fk.lib) return\n const {store, injectHtml} = this\n if (this.fk.lib) {\n const url = getRuntimeLib(this.fk.lib, store.mode, this.fk.entry)\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 const frameworkGlobal = this.fk.global || (empRuntime.shareLib ? 'window' : '')\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:'${this.rt.global}',framework:'${this.fk.name}'}`,\n })\n }\n }\n public fk!: Required<frameworkOptions>\n private resetFramework() {\n if (!this.op.empRuntime) return\n const {framework, frameworkGlobal, frameworkLib} = this.op.empRuntime\n //\n this.fk = {\n name: 'none',\n version: 0,\n entry: '',\n global: frameworkGlobal || '',\n lib: frameworkLib || '',\n }\n //\n if (typeof framework === 'string') {\n this.fk.name = framework as any\n } else if (typeof framework === 'object' && Object.keys(framework).length > 0) {\n // 默认 框架名 为入口\n framework.entry = framework.entry ? framework.entry : framework.name\n this.fk = deepAssign(this.fk, framework)\n }\n }\n public rt!: Required<runtimeLibType>\n private resetRuntime() {\n const {empRuntime} = this.op\n if (!empRuntime) return\n const global = empRuntime.runtimeGlobal || shareGlobalName\n const lib = empRuntime.runtimeLib ? empRuntime.runtimeLib : empRuntime.runtime?.lib ? empRuntime.runtime.lib : ''\n this.rt = {\n lib,\n global,\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {shareLib} = empRuntime\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] = `${this.rt.global}.${value}`\n }\n if (this.fk.name === 'react' && !shareLib && this.fk.global) {\n const version = this.fk.version\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n if (this.fk.entry === 'reactRouter') {\n externalReact['react-router-dom'] = 'ReactRouterDOM'\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${this.fk.global}.${value}`\n }\n if ([17, 18, 19].includes(version)) {\n externals['react-dom/client'] = this.fk.global\n externals['react/jsx-runtime'] = this.fk.global\n externals['react/jsx-dev-runtime'] = this.fk.global\n }\n }\n if (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${this.fk.global}.${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 {shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!this.rt.lib) {\n // 内置 this.rt.lib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (this.rt.lib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: this.rt.lib}})\n }\n }\n private setMfName() {\n if (this.op.name) {\n this.op.name = this.store.encodeVarName(this.op.name)\n if (this.op.name !== this.store.empConfig.output.uniqueName) {\n this.store.chain.output.set('uniqueName', this.op.name)\n }\n } else {\n this.op.name = this.store.empConfig.output.uniqueName\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions & {empRuntime: any}>(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n if (op.empRuntime) {\n delete op.empRuntime\n }\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\n })\n }\n }\n}\n","export const 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\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\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}\n// 当没有设置 runtimeLib 时候需要内置\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 entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string, entry = 'runtime') {\n if (typeof host === 'string') {\n if (entry === 'runtime') {\n return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n } else {\n return `${host}/${entry}.${mode}.umd.js`\n }\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,EAAcC,GAAoB,wBAAwBA,CAAO,GAEvE,SAASC,EAAcC,KAAgBC,EAAiB,CAC7D,QAAWC,KAAUD,EACnB,QAAWE,KAAKD,EAAQ,CACtB,IAAME,EAAKF,EAAOC,CAAC,EACjBE,EAAKL,EAAOG,CAAC,EACf,GAAI,OAAOC,CAAE,GAAKA,GAAM,OAAOC,CAAE,IAAMA,EAAI,CACzCL,EAAOG,CAAC,EAAIJ,EAAWM,EAAID,CAAE,EAC7B,QACF,CACAJ,EAAOG,CAAC,EAAID,EAA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AE,OAAS,OACpBnB,EAAW,KAAK,CACd,WAAY,CACV,KAAMmB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EDhRO,IAAMO,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAE7BD,EAAE,WAAa,GACjBA,EAAE,SAAW,CACX,SAAU,UACZ,EACS,OAAOA,EAAE,UAAa,WAC/BA,EAAE,SAAWC,EAAM,WAAW,CAAC,SAAU,UAAU,EAAGD,EAAE,QAAQ,GAEjD,IAAIE,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ","names":["rspack_exports","__export","rspack_default","pluginRspackEmpShare","__toCommonJS","import_rspack","importJsVm","content","deepAssign","target","sources","source","k","vs","vt","isDev","log","shareGlobalName","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","entry","getRuntimeLib","host","mode","entry","exp","EmpShare","op","store","injectHtml","url","getRuntimeLib","empRuntime","frameworkGlobal","framework","frameworkLib","deepAssign","global","shareGlobalName","lib","externalsLib","shareLib","externalRuntime","externals","key","value","version","externalReact","v","EmpShareRemoteLibPlugin","o","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default"]}
package/dist/rspack.js CHANGED
@@ -1,3 +1,3 @@
1
- import{ModuleFederationPlugin as k}from"@module-federation/enhanced/rspack";var f=r=>`data:text/javascript,${r}`;function c(r,...e){for(let i of e)for(let s in i){let o=i[s],a=r[s];if(Object(o)==o&&Object(a)===a){r[s]=c(a,o);continue}r[s]=i[s]}return r}var j=!1,E=j?console.log.bind(console,"[EMP Share]"):()=>{};var h="EMP_SHARE_RUNTIME";var R=r=>{let e=[`import '${r}'`].join(`
2
- `);return f(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:i}=e,{runtimeLib:s,runtime:o}=this.options;if(!s&&!o?.lib){let a=R("@empjs/share/library");new i.EntryPlugin(e.context,a,{name:void 0}).apply(e)}}};function b(r,e,i="runtime"){return typeof r=="string"?i==="runtime"?`${r}/runtime${e==="development"?".development":""}.umd.js`:`${r}/${i}.${e}.umd.js`:typeof r=="object"?e==="development"?r.dev:r.prod:""}var y=/^([0-9a-zA-Z_\s]+)@(.*)/,u=class{op;store;injectHtml=[];externalsLib=[];constructor(e,i){this.op=e||{},this.store=i}setup(){this.resetRuntime(),this.resetFramework(),this.setMfName(),this.setMF(),this.injectGlobalVal(),this.injectFramework(),this.setShareLib(),this.setRuntimeLib(),this.injectToHtml(),this.setExternal()}injectToHtml(){let{store:e,injectHtml:i}=this;i.length>0&&e.injectTags(i,"EMPShare")}injectFramework(){if(!this.op.empRuntime||!this.fk.lib)return;let{store:e,injectHtml:i}=this;if(this.fk.lib){let s=b(this.fk.lib,e.mode,this.fk.entry);i.push({attributes:{src:s},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:i}=this,s=this.fk.global||(e.shareLib?"window":"");e.injectGlobalValToHtml!==!1&&i.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${s}',runtimeLib:'${this.rt.global}',framework:'${this.fk.name}'}`})}fk;resetFramework(){if(!this.op.empRuntime)return;let{framework:e,frameworkGlobal:i,frameworkLib:s}=this.op.empRuntime;this.fk={name:"none",version:0,entry:"",global:i||"",lib:s||""},typeof e=="string"?this.fk.name=e:typeof e=="object"&&Object.keys(e).length>0&&(e.entry=e.entry?e.entry:e.name,this.fk=c(this.fk,e))}rt;resetRuntime(){let{empRuntime:e}=this.op;e&&(e.runtimeGlobal=e.runtimeGlobal||h,this.rt={lib:e.runtimeLib||"",global:e.runtimeGlobal})}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:i}=this,{empRuntime:s}=this.op,{shareLib:o}=s,a={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},t={};for(let[n,p]of Object.entries(a))t[n]=`${this.rt.global}.${p}`;if(this.fk.name==="react"&&!o&&this.fk.global){let n=this.fk.version,p={react:"React","react-dom":"ReactDOM"};this.fk.entry==="reactRouter"&&(p["react-router-dom"]="ReactRouterDOM");for(let[m,g]of Object.entries(p))t[m]=`${this.fk.global}.${g}`;[17,18,19].includes(n)&&(t["react-dom/client"]=this.fk.global,t["react/jsx-runtime"]=this.fk.global,t["react/jsx-dev-runtime"]=this.fk.global)}o&&i.map(n=>{n.type==="js"&&n.module&&n.global&&(t[n.module]=`${this.fk.global}.${n.global}`)}),s.setExternals&&s.setExternals(t),e.chain.merge({externals:t})}setRuntimeLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{store:i,injectHtml:s}=this,{empRuntime:o}=this.op;this.rt.lib?this.rt.lib==="useFrameworkLib"&&!e||s.push({tagName:"script",pos:"head",attributes:{src:this.rt.lib}}):i.chain.plugin("plugin-emp-share-framework").use(l,[o])}setMfName(){this.op.name?(this.op.name=this.store.encodeVarName(this.op.name),this.op.name!==this.store.empConfig.output.uniqueName&&this.store.chain.output.set("uniqueName",this.op.name)):this.op.name=this.store.empConfig.output.uniqueName}setMF(){let e=this.op,{store:i}=this;if(e.name){let s=i.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},e);s.empRuntime&&delete s.empRuntime,i.chain.plugin("plugin-emp-share").use(k,[s])}}setShareLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{externalsLib:i,injectHtml:s}=this;if(e&&typeof e=="object"){for(let[o,a]of Object.entries(e)){let t={};if(t.module=o,typeof a=="string"){let n=a.match(y)||[];n.length>0?(t.global=n[1],t.entry=n[2],t.type="js",i.push(t),t={}):(t.global="",t.entry=a,t.type="js",i.push(t),t={})}else Array.isArray(a)?a.map(n=>{if(!n)return;if(n.split("?")[0].endsWith(".css"))t.entry=n,t.type="css";else{let m=n.match(y)||[];m.length>0?(t.global=m[1],t.entry=m[2],t.type="js"):(t.global="",t.entry=n,t.type="js")}i.push(t),t={}}):typeof a=="object"&&a.entry&&(t.entry=a.entry,t.global=a.global,t.type=a.type,i.push(t),t={})}i.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=(r={})=>({name:"@empjs/share",async rsConfig(e){r.manifest===!0?r.manifest={fileName:"emp.json"}:typeof r.manifest=="object"&&(r.manifest=e.deepAssign({fileName:"emp.json"},r.manifest)),new u(r,e).setup()}}),$=d;export{$ as default,d as pluginRspackEmpShare};
1
+ import{ModuleFederationPlugin as k}from"@module-federation/enhanced/rspack";var f=r=>`data:text/javascript,${r}`;function u(r,...e){for(let t of e)for(let s in t){let o=t[s],a=r[s];if(Object(o)==o&&Object(a)===a){r[s]=u(a,o);continue}r[s]=t[s]}return r}var j=!1,E=j?console.log.bind(console,"[EMP Share]"):()=>{};var h="EMP_SHARE_RUNTIME";var R=r=>{let e=[`import '${r}'`].join(`
2
+ `);return f(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:t}=e,s=R("@empjs/share/library");new t.EntryPlugin(e.context,s,{name:void 0}).apply(e)}};function b(r,e,t="runtime"){return typeof r=="string"?t==="runtime"?`${r}/runtime${e==="development"?".development":""}.umd.js`:`${r}/${t}.${e}.umd.js`:typeof r=="object"?e==="development"?r.dev:r.prod:""}var y=/^([0-9a-zA-Z_\s]+)@(.*)/,c=class{op;store;injectHtml=[];externalsLib=[];constructor(e,t){this.op=e||{},this.store=t}setup(){this.resetRuntime(),this.resetFramework(),this.setMfName(),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.fk.lib)return;let{store:e,injectHtml:t}=this;if(this.fk.lib){let s=b(this.fk.lib,e.mode,this.fk.entry);t.push({attributes:{src:s},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:t}=this,s=this.fk.global||(e.shareLib?"window":"");e.injectGlobalValToHtml!==!1&&t.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${s}',runtimeLib:'${this.rt.global}',framework:'${this.fk.name}'}`})}fk;resetFramework(){if(!this.op.empRuntime)return;let{framework:e,frameworkGlobal:t,frameworkLib:s}=this.op.empRuntime;this.fk={name:"none",version:0,entry:"",global:t||"",lib:s||""},typeof e=="string"?this.fk.name=e:typeof e=="object"&&Object.keys(e).length>0&&(e.entry=e.entry?e.entry:e.name,this.fk=u(this.fk,e))}rt;resetRuntime(){let{empRuntime:e}=this.op;if(!e)return;let t=e.runtimeGlobal||h,s=e.runtimeLib?e.runtimeLib:e.runtime?.lib?e.runtime.lib:"";this.rt={lib:s,global:t}}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:t}=this,{empRuntime:s}=this.op,{shareLib:o}=s,a={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},i={};for(let[n,p]of Object.entries(a))i[n]=`${this.rt.global}.${p}`;if(this.fk.name==="react"&&!o&&this.fk.global){let n=this.fk.version,p={react:"React","react-dom":"ReactDOM"};this.fk.entry==="reactRouter"&&(p["react-router-dom"]="ReactRouterDOM");for(let[m,g]of Object.entries(p))i[m]=`${this.fk.global}.${g}`;[17,18,19].includes(n)&&(i["react-dom/client"]=this.fk.global,i["react/jsx-runtime"]=this.fk.global,i["react/jsx-dev-runtime"]=this.fk.global)}o&&t.map(n=>{n.type==="js"&&n.module&&n.global&&(i[n.module]=`${this.fk.global}.${n.global}`)}),s.setExternals&&s.setExternals(i),e.chain.merge({externals:i})}setRuntimeLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{store:t,injectHtml:s}=this,{empRuntime:o}=this.op;this.rt.lib?this.rt.lib==="useFrameworkLib"&&!e||s.push({tagName:"script",pos:"head",attributes:{src:this.rt.lib}}):t.chain.plugin("plugin-emp-share-framework").use(l,[o])}setMfName(){this.op.name?(this.op.name=this.store.encodeVarName(this.op.name),this.op.name!==this.store.empConfig.output.uniqueName&&this.store.chain.output.set("uniqueName",this.op.name)):this.op.name=this.store.empConfig.output.uniqueName}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);s.empRuntime&&delete s.empRuntime,t.chain.plugin("plugin-emp-share").use(k,[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,a]of Object.entries(e)){let i={};if(i.module=o,typeof a=="string"){let n=a.match(y)||[];n.length>0?(i.global=n[1],i.entry=n[2],i.type="js",t.push(i),i={}):(i.global="",i.entry=a,i.type="js",t.push(i),i={})}else Array.isArray(a)?a.map(n=>{if(!n)return;if(n.split("?")[0].endsWith(".css"))i.entry=n,i.type="css";else{let m=n.match(y)||[];m.length>0?(i.global=m[1],i.entry=m[2],i.type="js"):(i.global="",i.entry=n,i.type="js")}t.push(i),i={}}):typeof a=="object"&&a.entry&&(i.entry=a.entry,i.global=a.global,i.type=a.type,t.push(i),i={})}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=(r={})=>({name:"@empjs/share",async rsConfig(e){r.manifest===!0?r.manifest={fileName:"emp.json"}:typeof r.manifest=="object"&&(r.manifest=e.deepAssign({fileName:"emp.json"},r.manifest)),new c(r,e).setup()}}),$=d;export{$ as default,d as pluginRspackEmpShare};
3
3
  //# sourceMappingURL=rspack.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugins/rspack/share.ts","../src/helper/index.ts","../src/helper/config.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 {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {\n EMPPluginShareType,\n ExternalsItemType,\n ModuleFederationPluginOptions,\n frameworkOptions,\n runtimeLibType,\n} 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.resetRuntime()\n this.resetFramework()\n this.setMfName() //设置 mfName 默认为 uniqueName\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.fk.lib) return\n const {store, injectHtml} = this\n if (this.fk.lib) {\n const url = getRuntimeLib(this.fk.lib, store.mode, this.fk.entry)\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 const frameworkGlobal = this.fk.global || (empRuntime.shareLib ? 'window' : '')\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:'${this.rt.global}',framework:'${this.fk.name}'}`,\n })\n }\n }\n public fk!: Required<frameworkOptions>\n private resetFramework() {\n if (!this.op.empRuntime) return\n const {framework, frameworkGlobal, frameworkLib} = this.op.empRuntime\n //\n this.fk = {\n name: 'none',\n version: 0,\n entry: '',\n global: frameworkGlobal || '',\n lib: frameworkLib || '',\n }\n //\n if (typeof framework === 'string') {\n this.fk.name = framework as any\n } else if (typeof framework === 'object' && Object.keys(framework).length > 0) {\n // 默认 框架名 为入口\n framework.entry = framework.entry ? framework.entry : framework.name\n this.fk = deepAssign(this.fk, framework)\n }\n }\n public rt!: Required<runtimeLibType>\n private resetRuntime() {\n const {empRuntime} = this.op\n if (!empRuntime) return\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n this.rt = {\n lib: empRuntime.runtimeLib || '',\n global: empRuntime.runtimeGlobal,\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {shareLib} = empRuntime\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] = `${this.rt.global}.${value}`\n }\n if (this.fk.name === 'react' && !shareLib && this.fk.global) {\n const version = this.fk.version\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n if (this.fk.entry === 'reactRouter') {\n externalReact['react-router-dom'] = 'ReactRouterDOM'\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${this.fk.global}.${value}`\n }\n if ([17, 18, 19].includes(version)) {\n externals['react-dom/client'] = this.fk.global\n externals['react/jsx-runtime'] = this.fk.global\n externals['react/jsx-dev-runtime'] = this.fk.global\n }\n }\n if (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${this.fk.global}.${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 {shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!this.rt.lib) {\n // 内置 this.rt.lib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (this.rt.lib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: this.rt.lib}})\n }\n }\n private setMfName() {\n if (this.op.name) {\n this.op.name = this.store.encodeVarName(this.op.name)\n if (this.op.name !== this.store.empConfig.output.uniqueName) {\n this.store.chain.output.set('uniqueName', this.op.name)\n }\n } else {\n this.op.name = this.store.empConfig.output.uniqueName\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions & {empRuntime: any}>(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n if (op.empRuntime) {\n delete op.empRuntime\n }\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\n })\n }\n }\n}\n","export const 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\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\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, runtime} = this.options\n // 当没有设置 runtimeLib 时候需要内置\n if (!runtimeLib && !runtime?.lib) {\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, entry = 'runtime') {\n if (typeof host === 'string') {\n if (entry === 'runtime') {\n return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n } else {\n return `${host}/${entry}.${mode}.umd.js`\n }\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 //\n if (o.manifest === true) {\n o.manifest = {\n fileName: 'emp.json',\n }\n } else if (typeof o.manifest === 'object') {\n o.manifest = store.deepAssign({fileName: 'emp.json'}, o.manifest)\n }\n const empShare = new EmpShare(o, store)\n empShare.setup()\n },\n }\n}\nexport default pluginRspackEmpShare\n"],"mappings":"AACA,OAAQ,0BAAAA,MAA6B,qCCD9B,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GAEvE,SAASC,EAAcC,KAAgBC,EAAiB,CAC7D,QAAWC,KAAUD,EACnB,QAAWE,KAAKD,EAAQ,CACtB,IAAME,EAAKF,EAAOC,CAAC,EACjBE,EAAKL,EAAOG,CAAC,EACf,GAAI,OAAOC,CAAE,GAAK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,CAAC,EAErB,CAEAb,EAAa,IAAIQ,GAAK,CAChBA,EAAE,OAAS,KACbjB,EAAW,KAAK,CACd,WAAY,CACV,IAAKiB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBjB,EAAW,KAAK,CACd,WAAY,CACV,KAAMiB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EK/QO,IAAMQ,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAE7BD,EAAE,WAAa,GACjBA,EAAE,SAAW,CACX,SAAU,UACZ,EACS,OAAOA,EAAE,UAAa,WAC/BA,EAAE,SAAWC,EAAM,WAAW,CAAC,SAAU,UAAU,EAAGD,EAAE,QAAQ,GAEjD,IAAIE,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ","names":["ModuleFederationPlugin","importJsVm","content","deepAssign","target","sources","source","k","vs","vt","isDev","log","shareGlobalName","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","runtime","entry","getRuntimeLib","host","mode","entry","exp","EmpShare","op","store","injectHtml","url","getRuntimeLib","empRuntime","frameworkGlobal","framework","frameworkLib","deepAssign","shareGlobalName","externalsLib","shareLib","externalRuntime","externals","key","value","version","externalReact","v","EmpShareRemoteLibPlugin","o","ModuleFederationPlugin","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default"]}
1
+ {"version":3,"sources":["../src/plugins/rspack/share.ts","../src/helper/index.ts","../src/helper/config.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 {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {\n EMPPluginShareType,\n ExternalsItemType,\n ModuleFederationPluginOptions,\n frameworkOptions,\n runtimeLibType,\n} 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.resetRuntime()\n this.resetFramework()\n this.setMfName() //设置 mfName 默认为 uniqueName\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.fk.lib) return\n const {store, injectHtml} = this\n if (this.fk.lib) {\n const url = getRuntimeLib(this.fk.lib, store.mode, this.fk.entry)\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 const frameworkGlobal = this.fk.global || (empRuntime.shareLib ? 'window' : '')\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:'${this.rt.global}',framework:'${this.fk.name}'}`,\n })\n }\n }\n public fk!: Required<frameworkOptions>\n private resetFramework() {\n if (!this.op.empRuntime) return\n const {framework, frameworkGlobal, frameworkLib} = this.op.empRuntime\n //\n this.fk = {\n name: 'none',\n version: 0,\n entry: '',\n global: frameworkGlobal || '',\n lib: frameworkLib || '',\n }\n //\n if (typeof framework === 'string') {\n this.fk.name = framework as any\n } else if (typeof framework === 'object' && Object.keys(framework).length > 0) {\n // 默认 框架名 为入口\n framework.entry = framework.entry ? framework.entry : framework.name\n this.fk = deepAssign(this.fk, framework)\n }\n }\n public rt!: Required<runtimeLibType>\n private resetRuntime() {\n const {empRuntime} = this.op\n if (!empRuntime) return\n const global = empRuntime.runtimeGlobal || shareGlobalName\n const lib = empRuntime.runtimeLib ? empRuntime.runtimeLib : empRuntime.runtime?.lib ? empRuntime.runtime.lib : ''\n this.rt = {\n lib,\n global,\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {shareLib} = empRuntime\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] = `${this.rt.global}.${value}`\n }\n if (this.fk.name === 'react' && !shareLib && this.fk.global) {\n const version = this.fk.version\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n if (this.fk.entry === 'reactRouter') {\n externalReact['react-router-dom'] = 'ReactRouterDOM'\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${this.fk.global}.${value}`\n }\n if ([17, 18, 19].includes(version)) {\n externals['react-dom/client'] = this.fk.global\n externals['react/jsx-runtime'] = this.fk.global\n externals['react/jsx-dev-runtime'] = this.fk.global\n }\n }\n if (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${this.fk.global}.${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 {shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!this.rt.lib) {\n // 内置 this.rt.lib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (this.rt.lib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: this.rt.lib}})\n }\n }\n private setMfName() {\n if (this.op.name) {\n this.op.name = this.store.encodeVarName(this.op.name)\n if (this.op.name !== this.store.empConfig.output.uniqueName) {\n this.store.chain.output.set('uniqueName', this.op.name)\n }\n } else {\n this.op.name = this.store.empConfig.output.uniqueName\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions & {empRuntime: any}>(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n if (op.empRuntime) {\n delete op.empRuntime\n }\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\n })\n }\n }\n}\n","export const 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\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\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}\n// 当没有设置 runtimeLib 时候需要内置\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 entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string, entry = 'runtime') {\n if (typeof host === 'string') {\n if (entry === 'runtime') {\n return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n } else {\n return `${host}/${entry}.${mode}.umd.js`\n }\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 //\n if (o.manifest === true) {\n o.manifest = {\n fileName: 'emp.json',\n }\n } else if (typeof o.manifest === 'object') {\n o.manifest = store.deepAssign({fileName: 'emp.json'}, o.manifest)\n }\n const empShare = new EmpShare(o, store)\n empShare.setup()\n },\n }\n}\nexport default pluginRspackEmpShare\n"],"mappings":"AACA,OAAQ,0BAAAA,MAA6B,qCCD9B,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GAEvE,SAASC,EAAcC,KAAgBC,EAAiB,CAC7D,QAAWC,KAAUD,EACnB,QAAWE,KAAKD,EAAQ,CACtB,IAAME,EAAKF,EAAOC,CAAC,EACjBE,EAAKL,EAAOG,CAAC,EACf,GAAI,OAAOC,CAAE,GAAKA,GAAM,OAAOC,CAAE,IAAMA,EAAI,CACzCL,EAAOG,CAAC,EAAIJ,EAAWM,EAAID,CAAE,EAC7B,QACF,CACAJ,EAAOG,CAAC,EAAID,EAAOC,CAAC,CACtB,CAEF,OAAOH,CACT,CAMO,IAAMM,EAAQ,GACRC,EAAMD,EAAQ,QAAQ,IAA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AAC,CAEL,CAAC,CACH,CACF,CACF,EKhRO,IAAMQ,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,CAE7BD,EAAE,WAAa,GACjBA,EAAE,SAAW,CACX,SAAU,UACZ,EACS,OAAOA,EAAE,UAAa,WAC/BA,EAAE,SAAWC,EAAM,WAAW,CAAC,SAAU,UAAU,EAAGD,EAAE,QAAQ,GAEjD,IAAIE,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ","names":["ModuleFederationPlugin","importJsVm","content","deepAssign","target","sources","source","k","vs","vt","isDev","log","shareGlobalName","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","entry","getRuntimeLib","host","mode","entry","exp","EmpShare","op","store","injectHtml","url","getRuntimeLib","empRuntime","frameworkGlobal","framework","frameworkLib","deepAssign","global","shareGlobalName","lib","externalsLib","shareLib","externalRuntime","externals","key","value","version","externalReact","v","EmpShareRemoteLibPlugin","o","ModuleFederationPlugin","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empjs/share",
3
- "version": "3.4.6",
3
+ "version": "3.5.0",
4
4
  "description": "emp share and runtime",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -102,7 +102,7 @@
102
102
  "serve": "^14.2.1",
103
103
  "tsup": "^8.3.5",
104
104
  "typescript": "^5.5.4",
105
- "@empjs/cli": "3.4.6"
105
+ "@empjs/cli": "3.5.0"
106
106
  },
107
107
  "scripts": {
108
108
  "dev": "pnpm run /^dev:.*/",