@empjs/share 3.3.2 → 3.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/rspack.cjs +2 -2
- package/dist/rspack.cjs.map +1 -1
- package/dist/rspack.js +2 -2
- package/dist/rspack.js.map +1 -1
- package/output/full.js +1 -1
- package/output/full.js.map +1 -1
- package/output/sdk.js +1 -1
- package/output/sdk.js.map +1 -1
- package/output/sdkPolyfill.js +1 -1
- package/output/sdkPolyfill.js.map +1 -1
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var f=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var
|
|
2
|
-
`);return g(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:t}=e,{runtimeLib:
|
|
1
|
+
"use strict";var f=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var M=(s,e)=>{for(var t in e)f(s,t,{get:e[t],enumerable:!0})},P=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of x(e))!k.call(s,o)&&o!==t&&f(s,o,{get:()=>e[o],enumerable:!(r=S(e,o))||r.enumerable});return s};var w=s=>P(f({},"__esModule",{value:!0}),s);var N={};M(N,{default:()=>T,pluginRspackEmpShare:()=>h});module.exports=w(N);var d=require("@module-federation/enhanced/rspack");var y="EMP_SHARE_RUNTIME";var g=s=>`data:text/javascript,${s}`;var L=!1,A=L?console.log.bind(console,"[EMP Share]"):()=>{};var G=s=>{let e=[`import '${s}'`].join(`
|
|
2
|
+
`);return g(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:t}=e,{runtimeLib:r}=this.options;if(!r){let o=G("@empjs/share/library");new t.EntryPlugin(e.context,o,{name:void 0}).apply(e)}}};function j(s,e){return typeof s=="string"?`${s}/runtime${e==="development"?".development":""}.umd.js`:typeof s=="object"?e==="development"?s.dev:s.prod:""}var R=/^([0-9a-zA-Z_\s]+)@(.*)/,c=class{op;store;injectHtml=[];externalsLib=[];constructor(e,t){this.op=e||{},this.store=t}setup(){this.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.op.empRuntime.frameworkLib)return;let{store:e,injectHtml:t}=this,{frameworkLib:r}=this.op.empRuntime;if(r){let o=j(r,e.mode);t.push({attributes:{src:o},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:t}=this;e.framework=Object.hasOwn(e,"framework")?e.framework:"react",e.runtimeGlobal=e.runtimeGlobal||y,e.frameworkGlobal=e.frameworkGlobal||(e.shareLib?"window":""),e.injectGlobalValToHtml!==!1&&t.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${e.frameworkGlobal}',runtimeLib:'${e.runtimeGlobal}',framework:'${e.framework}'}`})}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:t}=this,{empRuntime:r}=this.op,{framework:o,shareLib:n,runtimeGlobal:i,frameworkGlobal:a}=r,b={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},p={};for(let[m,u]of Object.entries(b))p[m]=`${i}.${u}`;if(o==="react"&&!n&&a){let m={react:"React","react-dom":"ReactDOM"};for(let[u,E]of Object.entries(m))p[u]=`${a}.${E}`}n&&t.map(m=>{m.type==="js"&&m.module&&m.global&&(p[m.module]=`${a}.${m.global}`)}),r.setExternals&&r.setExternals(p),e.chain.merge({externals:p})}setRuntimeLib(){if(!this.op.empRuntime)return;let{runtimeLib:e,shareLib:t}=this.op.empRuntime,{store:r,injectHtml:o}=this,{empRuntime:n}=this.op;e?e==="useFrameworkLib"&&!t||o.push({tagName:"script",pos:"head",attributes:{src:e}}):r.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(d.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[o,n]of Object.entries(e)){let i={};if(i.module=o,typeof n=="string"){let a=n.match(R)||[];a.length>0?(i.global=a[1],i.entry=a[2],i.type="js",t.push(i),i={}):(i.global="",i.entry=n,i.type="js",t.push(i),i={})}else Array.isArray(n)?n.map(a=>{if(!a)return;if(a.split("?")[0].endsWith(".css"))i.entry=a,i.type="css";else{let p=a.match(R)||[];p.length>0?(i.global=p[1],i.entry=p[2],i.type="js"):(i.global="",i.entry=a,i.type="js")}t.push(i),i={}}):typeof n=="object"&&n.entry&&(i.entry=n.entry,i.global=n.global,i.type=n.type,t.push(i),i={})}t.map(o=>{o.type==="js"?r.push({attributes:{src:o.entry},tagName:"script"}):o.type==="css"&&r.push({attributes:{href:o.entry,rel:"stylesheet"},tagName:"link"})})}}};var H=(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()}}),h=H;var T=h;0&&(module.exports={pluginRspackEmpShare});
|
|
3
3
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/plugins/rspack/share.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts","../src/plugins/rspack/index.ts"],"sourcesContent":["import {default as pluginRspackEmpShare} from 'src/plugins/rspack'\nexport default pluginRspackEmpShare\nexport {pluginRspackEmpShare}\n","import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType, ExternalsItemType, ModuleFederationPluginOptions} from './types'\nimport {getRuntimeLib} from './utils'\nconst exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\nexport class EmpShare {\n private op: EMPPluginShareType\n private store: GlobalStore\n /**\n * 注入资源\n */\n private injectHtml: any[] = []\n /**\n * 兼容 shareLib\n */\n private externalsLib: ExternalsItemType[] = []\n constructor(op: EMPPluginShareType, store: GlobalStore) {\n this.op = op || {}\n this.store = store\n }\n setup() {\n this.setMF() // 设置 MF 配置\n this.injectGlobalVal() // 插入全局变量 方便emp外的项目调用\n this.injectFramework() // 插入ui框架库\n this.setShareLib() //兼容 emp Sharelib的共享模型设置\n this.setRuntimeLib() // 设置 MF SDK\n this.injectToHtml() //触发插入动作\n this.setExternal() // 设置 external 降低包体\n }\n private injectToHtml() {\n const {store, injectHtml} = this\n if (injectHtml.length > 0) {\n store.injectTags(injectHtml, 'EMPShare')\n }\n }\n private injectFramework() {\n if (!this.op.empRuntime || !this.op.empRuntime.frameworkLib) return\n const {store, injectHtml} = this\n const {frameworkLib} = this.op.empRuntime\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n })\n }\n }\n private injectGlobalVal() {\n if (!this.op.empRuntime) return\n const {empRuntime} = this.op\n const {injectHtml} = this\n empRuntime.framework = Object.hasOwn(empRuntime, 'framework') ? empRuntime.framework : 'react'\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || (empRuntime.shareLib ? 'window' : '')\n\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${empRuntime.frameworkGlobal}',runtimeLib:'${empRuntime.runtimeGlobal}',framework:'${empRuntime.framework}'}`,\n })\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {framework, shareLib, runtimeGlobal, frameworkGlobal} = empRuntime\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && !shareLib && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${frameworkGlobal}.${v.global}`\n }\n })\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n private setRuntimeLib() {\n if (!this.op.empRuntime) return\n\n const {runtimeLib, shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions & {empRuntime: any}>(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n if (op.empRuntime) {\n delete op.empRuntime\n }\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\n })\n }\n }\n}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n","import type {GlobalStore} from '@empjs/cli'\nimport {EmpShare} from './share'\nimport type {EMPPluginShareType} from './types'\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n //\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 //\n const empShare = new EmpShare(o, store)\n empShare.setup()\n },\n }\n}\nexport default pluginRspackEmpShare\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,yBAAAC,IAAA,eAAAC,EAAAJ,GCCA,IAAAK,EAAqC,8CCD9B,IAAMC,EAAkB,oBCAxB,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GAqBvE,IAAMC,EAAQ,GACRC,EAAMD,EAAQ,QAAQ,IAAI,KAAK,QAAS,aAAa,EAAI,IAAM,CAAC,ECnB7E,IAAME,EAAuBC,GAAO,CAClC,IAAMC,EAAU,CAAC,WAAWD,CAAG,GAAG,EAAE,KAAK;AAAA,CAAI,EAC7C,OAAOE,EAAWD,CAAO,CAC3B,EACaE,EAAN,KAA8B,CACnC,QACA,YAAYC,EAA4B,CACtC,KAAK,QAAUA,CACjB,CACA,MAAMC,EAAoB,CACxB,GAAM,CAAC,QAAAC,CAAO,EAAID,EACZ,CAAC,WAAAE,CAAU,EAAI,KAAK,QAC1B,GAAI,CAACA,EAAY,CACf,IAAMC,EAAQT,EAAqB,sBAAsB,EACzD,IAAIO,EAAQ,YAAYD,EAAS,QAASG,EAAO,CAC/C,KAAM,MACR,CAAC,EAAE,MAAMH,CAAQ,CACnB,CACF,CACF,ECrBO,SAASI,EAAcC,EAA8CC,EAAc,CACxF,OAAI,OAAOD,GAAS,SAAiB,GAAGA,CAAI,WAAWC,IAAS,cAAgB,eAAiB,EAAE,UAC1F,OAAOD,GAAS,SACnBC,IAAS,cAAsBD,EAAK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EAAG,OAAS,GACdD,EAAc,OAASC,EAAG,CAAC,EAC3BD,EAAc,MAAQC,EAAG,CAAC,EAC1BD,EAAc,KAAO,OAErBA,EAAc,OAAS,GACvBA,EAAc,MAAQE,EACtBF,EAAc,KAAO,KAEzB,CACAf,EAAa,KAAKe,CAAa,EAC/BA,EAAgB,CAAC,CACnB,CAAC,EACQ,OAAOL,GAAM,UAAYA,EAAE,QACpCK,EAAc,MAAQL,EAAE,MACxBK,EAAc,OAASL,EAAE,OACzBK,EAAc,KAAOL,EAAE,KACvBV,EAAa,KAAKe,CAAa,EAC/BA,EAAgB,CAAC,EAErB,CAEAf,EAAa,IAAIU,GAAK,CAChBA,EAAE,OAAS,KACbhB,EAAW,KAAK,CACd,WAAY,CACV,IAAKgB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBhB,EAAW,KAAK,CACd,WAAY,CACV,KAAMgB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EKtNO,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,GAGjD,IAAIE,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ,ENpBf,IAAOK,EAAQC","names":["src_exports","__export","src_default","rspack_default","__toCommonJS","import_rspack","shareGlobalName","importJsVm","content","isDev","log","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","exp","EmpShare","op","store","injectHtml","frameworkLib","url","getRuntimeLib","empRuntime","shareGlobalName","externalsLib","framework","shareLib","runtimeGlobal","frameworkGlobal","externalRuntime","externals","key","value","externalReact","v","runtimeLib","EmpShareRemoteLibPlugin","o","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default","src_default","rspack_default"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/plugins/rspack/share.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts","../src/plugins/rspack/index.ts"],"sourcesContent":["import {default as pluginRspackEmpShare} from 'src/plugins/rspack'\nexport default pluginRspackEmpShare\nexport {pluginRspackEmpShare}\n","import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType, ExternalsItemType, ModuleFederationPluginOptions} from './types'\nimport {getRuntimeLib} from './utils'\nconst exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\nexport class EmpShare {\n private op: EMPPluginShareType\n private store: GlobalStore\n /**\n * 注入资源\n */\n private injectHtml: any[] = []\n /**\n * 兼容 shareLib\n */\n private externalsLib: ExternalsItemType[] = []\n constructor(op: EMPPluginShareType, store: GlobalStore) {\n this.op = op || {}\n this.store = store\n }\n setup() {\n this.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.op.empRuntime.frameworkLib) return\n const {store, injectHtml} = this\n const {frameworkLib} = this.op.empRuntime\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n })\n }\n }\n private injectGlobalVal() {\n if (!this.op.empRuntime) return\n const {empRuntime} = this.op\n const {injectHtml} = this\n empRuntime.framework = Object.hasOwn(empRuntime, 'framework') ? empRuntime.framework : 'react'\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || (empRuntime.shareLib ? 'window' : '')\n\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${empRuntime.frameworkGlobal}',runtimeLib:'${empRuntime.runtimeGlobal}',framework:'${empRuntime.framework}'}`,\n })\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {framework, shareLib, runtimeGlobal, frameworkGlobal} = empRuntime\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && !shareLib && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${frameworkGlobal}.${v.global}`\n }\n })\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n private setRuntimeLib() {\n if (!this.op.empRuntime) return\n\n const {runtimeLib, shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n }\n private 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 shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n","import type {GlobalStore} from '@empjs/cli'\nimport {EmpShare} from './share'\nimport type {EMPPluginShareType} from './types'\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n //\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,EAAkB,oBCAxB,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GAqBvE,IAAMC,EAAQ,GACRC,EAAMD,EAAQ,QAAQ,IAAI,KAAK,QAAS,aAAa,EAAI,IAAM,CAAC,ECnB7E,IAAME,EAAuBC,GAAO,CAClC,IAAMC,EAAU,CAAC,WAAWD,CAAG,GAAG,EAAE,KAAK;AAAA,CAAI,EAC7C,OAAOE,EAAWD,CAAO,CAC3B,EACaE,EAAN,KAA8B,CACnC,QACA,YAAYC,EAA4B,CACtC,KAAK,QAAUA,CACjB,CACA,MAAMC,EAAoB,CACxB,GAAM,CAAC,QAAAC,CAAO,EAAID,EACZ,CAAC,WAAAE,CAAU,EAAI,KAAK,QAC1B,GAAI,CAACA,EAAY,CACf,IAAMC,EAAQT,EAAqB,sBAAsB,EACzD,IAAIO,E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,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","shareGlobalName","importJsVm","content","isDev","log","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","exp","EmpShare","op","store","injectHtml","frameworkLib","url","getRuntimeLib","empRuntime","shareGlobalName","externalsLib","framework","shareLib","runtimeGlobal","frameworkGlobal","externalRuntime","externals","key","value","externalReact","v","runtimeLib","EmpShareRemoteLibPlugin","o","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default","src_default","rspack_default"]}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{ModuleFederationPlugin as S}from"@module-federation/enhanced/rspack";var h="EMP_SHARE_RUNTIME";var b=
|
|
2
|
-
`);return b(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:i}=e,{runtimeLib:
|
|
1
|
+
import{ModuleFederationPlugin as S}from"@module-federation/enhanced/rspack";var h="EMP_SHARE_RUNTIME";var b=s=>`data:text/javascript,${s}`;var d=!1,M=d?console.log.bind(console,"[EMP Share]"):()=>{};var E=s=>{let e=[`import '${s}'`].join(`
|
|
2
|
+
`);return b(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:i}=e,{runtimeLib:r}=this.options;if(!r){let n=E("@empjs/share/library");new i.EntryPlugin(e.context,n,{name:void 0}).apply(e)}}};function y(s,e){return typeof s=="string"?`${s}/runtime${e==="development"?".development":""}.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,i){this.op=e||{},this.store=i}setup(){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.op.empRuntime.frameworkLib)return;let{store:e,injectHtml:i}=this,{frameworkLib:r}=this.op.empRuntime;if(r){let n=y(r,e.mode);i.push({attributes:{src:n},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:i}=this;e.framework=Object.hasOwn(e,"framework")?e.framework:"react",e.runtimeGlobal=e.runtimeGlobal||h,e.frameworkGlobal=e.frameworkGlobal||(e.shareLib?"window":""),e.injectGlobalValToHtml!==!1&&i.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${e.frameworkGlobal}',runtimeLib:'${e.runtimeGlobal}',framework:'${e.framework}'}`})}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:i}=this,{empRuntime:r}=this.op,{framework:n,shareLib:o,runtimeGlobal:t,frameworkGlobal:a}=r,f={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},p={};for(let[m,u]of Object.entries(f))p[m]=`${t}.${u}`;if(n==="react"&&!o&&a){let m={react:"React","react-dom":"ReactDOM"};for(let[u,R]of Object.entries(m))p[u]=`${a}.${R}`}o&&i.map(m=>{m.type==="js"&&m.module&&m.global&&(p[m.module]=`${a}.${m.global}`)}),r.setExternals&&r.setExternals(p),e.chain.merge({externals:p})}setRuntimeLib(){if(!this.op.empRuntime)return;let{runtimeLib:e,shareLib:i}=this.op.empRuntime,{store:r,injectHtml:n}=this,{empRuntime:o}=this.op;e?e==="useFrameworkLib"&&!i||n.push({tagName:"script",pos:"head",attributes:{src:e}}):r.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 r=i.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},e);r.empRuntime&&delete r.empRuntime,i.chain.plugin("plugin-emp-share").use(S,[r])}}setShareLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{externalsLib:i,injectHtml:r}=this;if(e&&typeof e=="object"){for(let[n,o]of Object.entries(e)){let t={};if(t.module=n,typeof o=="string"){let a=o.match(g)||[];a.length>0?(t.global=a[1],t.entry=a[2],t.type="js",i.push(t),t={}):(t.global="",t.entry=o,t.type="js",i.push(t),t={})}else Array.isArray(o)?o.map(a=>{if(!a)return;if(a.split("?")[0].endsWith(".css"))t.entry=a,t.type="css";else{let p=a.match(g)||[];p.length>0?(t.global=p[1],t.entry=p[2],t.type="js"):(t.global="",t.entry=a,t.type="js")}i.push(t),t={}}):typeof o=="object"&&o.entry&&(t.entry=o.entry,t.global=o.global,t.type=o.type,i.push(t),t={})}i.map(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 x=(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()}}),j=x;var F=j;export{F as default,j as pluginRspackEmpShare};
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugins/rspack/share.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts","../src/plugins/rspack/index.ts","../src/index.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType, ExternalsItemType, ModuleFederationPluginOptions} from './types'\nimport {getRuntimeLib} from './utils'\nconst exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\nexport class EmpShare {\n private op: EMPPluginShareType\n private store: GlobalStore\n /**\n * 注入资源\n */\n private injectHtml: any[] = []\n /**\n * 兼容 shareLib\n */\n private externalsLib: ExternalsItemType[] = []\n constructor(op: EMPPluginShareType, store: GlobalStore) {\n this.op = op || {}\n this.store = store\n }\n setup() {\n this.setMF() // 设置 MF 配置\n this.injectGlobalVal() // 插入全局变量 方便emp外的项目调用\n this.injectFramework() // 插入ui框架库\n this.setShareLib() //兼容 emp Sharelib的共享模型设置\n this.setRuntimeLib() // 设置 MF SDK\n this.injectToHtml() //触发插入动作\n this.setExternal() // 设置 external 降低包体\n }\n private injectToHtml() {\n const {store, injectHtml} = this\n if (injectHtml.length > 0) {\n store.injectTags(injectHtml, 'EMPShare')\n }\n }\n private injectFramework() {\n if (!this.op.empRuntime || !this.op.empRuntime.frameworkLib) return\n const {store, injectHtml} = this\n const {frameworkLib} = this.op.empRuntime\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n })\n }\n }\n private injectGlobalVal() {\n if (!this.op.empRuntime) return\n const {empRuntime} = this.op\n const {injectHtml} = this\n empRuntime.framework = Object.hasOwn(empRuntime, 'framework') ? empRuntime.framework : 'react'\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || (empRuntime.shareLib ? 'window' : '')\n\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${empRuntime.frameworkGlobal}',runtimeLib:'${empRuntime.runtimeGlobal}',framework:'${empRuntime.framework}'}`,\n })\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {framework, shareLib, runtimeGlobal, frameworkGlobal} = empRuntime\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && !shareLib && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${frameworkGlobal}.${v.global}`\n }\n })\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n private setRuntimeLib() {\n if (!this.op.empRuntime) return\n\n const {runtimeLib, shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions & {empRuntime: any}>(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n if (op.empRuntime) {\n delete op.empRuntime\n }\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\n })\n }\n }\n}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n","import type {GlobalStore} from '@empjs/cli'\nimport {EmpShare} from './share'\nimport type {EMPPluginShareType} from './types'\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n //\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 //\n const empShare = new EmpShare(o, store)\n empShare.setup()\n },\n }\n}\nexport default pluginRspackEmpShare\n","import {default as pluginRspackEmpShare} from 'src/plugins/rspack'\nexport default pluginRspackEmpShare\nexport {pluginRspackEmpShare}\n"],"mappings":"AACA,OAAQ,0BAAAA,MAA6B,qCCD9B,IAAMC,EAAkB,oBCAxB,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GAqBvE,IAAMC,EAAQ,GACRC,EAAMD,EAAQ,QAAQ,IAAI,KAAK,QAAS,aAAa,EAAI,IAAM,CAAC,ECnB7E,IAAME,EAAuBC,GAAO,CAClC,IAAMC,EAAU,CAAC,WAAWD,CAAG,GAAG,EAAE,KAAK;AAAA,CAAI,EAC7C,OAAOE,EAAWD,CAAO,CAC3B,EACaE,EAAN,KAA8B,CACnC,QACA,YAAYC,EAA4B,CACtC,KAAK,QAAUA,CACjB,CACA,MAAMC,EAAoB,CACxB,GAAM,CAAC,QAAAC,CAAO,EAAID,EACZ,CAAC,WAAAE,CAAU,EAAI,KAAK,QAC1B,GAAI,CAACA,EAAY,CACf,IAAMC,EAAQT,EAAqB,sBAAsB,EACzD,IAAIO,EAAQ,YAAYD,EAAS,QAASG,EAAO,CAC/C,KAAM,MACR,CAAC,EAAE,MAAMH,CAAQ,CACnB,CACF,CACF,ECrBO,SAASI,EAAcC,EAA8CC,EAAc,CACxF,OAAI,OAAOD,GAAS,SAAiB,GAAGA,CAAI,WAAWC,IAAS,cAAgB,eAAiB,EAAE,UAC1F,OAAOD,GAAS,SACnBC,IAAS,cAAsBD,EAAK,IAC5BA,EAAK,KAEZ,EACT,CJFA,IAAME,EAAM,0BACCC,EAAN,KAAe,CACZ,GACA,MAIA,WAAoB,CAAC,EAIrB,aAAoC,CAAC,EAC7C,YAAYC,EAAwBC,EAAoB,CACtD,KAAK,GAAKD,GAAM,CAAC,EACjB,KAAK,MAAQC,CACf,CACA,OAAQ,CACN,KAAK,MAAM,EACX,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,OAAON,GAAM,UAAYA,EAAE,QACpCM,EAAc,MAAQN,EAAE,MACxBM,EAAc,OAASN,EAAE,OACzBM,EAAc,KAAON,EAAE,KACvBV,EAAa,KAAKgB,CAAa,EAC/BA,EAAgB,CAAC,EAErB,CAEAhB,EAAa,IAAIU,GAAK,CAChBA,EAAE,OAAS,KACbhB,EAAW,KAAK,CACd,WAAY,CACV,IAAKgB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBhB,EAAW,KAAK,CACd,WAAY,CACV,KAAMgB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EKtNO,IAAMS,EAAuB,CAACC,EAAwB,CAAC,KACrD,CACL,KAAM,eACN,MAAM,SAASC,EAAoB,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,GAGjD,IAAIE,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ,ECpBf,IAAOK,EAAQC","names":["ModuleFederationPlugin","shareGlobalName","importJsVm","content","isDev","log","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","exp","EmpShare","op","store","injectHtml","frameworkLib","url","getRuntimeLib","empRuntime","shareGlobalName","externalsLib","framework","shareLib","runtimeGlobal","frameworkGlobal","externalRuntime","externals","key","value","externalReact","v","runtimeLib","EmpShareRemoteLibPlugin","o","ModuleFederationPlugin","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default","src_default","rspack_default"]}
|
|
1
|
+
{"version":3,"sources":["../src/plugins/rspack/share.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts","../src/plugins/rspack/index.ts","../src/index.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType, ExternalsItemType, ModuleFederationPluginOptions} from './types'\nimport {getRuntimeLib} from './utils'\nconst exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\nexport class EmpShare {\n private op: EMPPluginShareType\n private store: GlobalStore\n /**\n * 注入资源\n */\n private injectHtml: any[] = []\n /**\n * 兼容 shareLib\n */\n private externalsLib: ExternalsItemType[] = []\n constructor(op: EMPPluginShareType, store: GlobalStore) {\n this.op = op || {}\n this.store = store\n }\n setup() {\n this.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.op.empRuntime.frameworkLib) return\n const {store, injectHtml} = this\n const {frameworkLib} = this.op.empRuntime\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n })\n }\n }\n private injectGlobalVal() {\n if (!this.op.empRuntime) return\n const {empRuntime} = this.op\n const {injectHtml} = this\n empRuntime.framework = Object.hasOwn(empRuntime, 'framework') ? empRuntime.framework : 'react'\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || (empRuntime.shareLib ? 'window' : '')\n\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${empRuntime.frameworkGlobal}',runtimeLib:'${empRuntime.runtimeGlobal}',framework:'${empRuntime.framework}'}`,\n })\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {framework, shareLib, runtimeGlobal, frameworkGlobal} = empRuntime\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && !shareLib && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${frameworkGlobal}.${v.global}`\n }\n })\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n private setRuntimeLib() {\n if (!this.op.empRuntime) return\n\n const {runtimeLib, shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n }\n private 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 shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n","import type {GlobalStore} from '@empjs/cli'\nimport {EmpShare} from './share'\nimport type {EMPPluginShareType} from './types'\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n //\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,EAAkB,oBCAxB,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GAqBvE,IAAMC,EAAQ,GACRC,EAAMD,EAAQ,QAAQ,IAAI,KAAK,QAAS,aAAa,EAAI,IAAM,CAAC,ECnB7E,IAAME,EAAuBC,GAAO,CAClC,IAAMC,EAAU,CAAC,WAAWD,CAAG,GAAG,EAAE,KAAK;AAAA,CAAI,EAC7C,OAAOE,EAAWD,CAAO,CAC3B,EACaE,EAAN,KAA8B,CACnC,QACA,YAAYC,EAA4B,CACtC,KAAK,QAAUA,CACjB,CACA,MAAMC,EAAoB,CACxB,GAAM,CAAC,QAAAC,CAAO,EAAID,EACZ,CAAC,WAAAE,CAAU,EAAI,KAAK,QAC1B,GAAI,CAACA,EAAY,CACf,IAAMC,EAAQT,EAAqB,sBAAsB,EACzD,IAAIO,EAAQ,YAAYD,EAAS,QAASG,EAAO,CAC/C,KAAM,MACR,CAAC,EAAE,MAAMH,CAAQ,CACnB,CACF,CACF,ECrBO,SAASI,EAAcC,EAA8CC,EAAc,CACxF,OAAI,OAAOD,GAAS,SAAiB,GAAGA,CAAI,WAAWC,IAAS,cAAgB,eAAiB,EAAE,UAC1F,OAAOD,GAAS,SACnBC,IAAS,cAAsBD,EAAK,IAC5BA,EAAK,KAEZ,EACT,CJFA,IAAME,EAAM,0BACCC,EAAN,KA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getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","exp","EmpShare","op","store","injectHtml","frameworkLib","url","getRuntimeLib","empRuntime","shareGlobalName","externalsLib","framework","shareLib","runtimeGlobal","frameworkGlobal","externalRuntime","externals","key","value","externalReact","v","runtimeLib","EmpShareRemoteLibPlugin","o","ModuleFederationPlugin","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default","src_default","rspack_default"]}
|
package/dist/rspack.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var f=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var
|
|
2
|
-
`);return y(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:t}=e,{runtimeLib:
|
|
1
|
+
"use strict";var f=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var M=(s,e)=>{for(var t in e)f(s,t,{get:e[t],enumerable:!0})},P=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of x(e))!k.call(s,n)&&n!==t&&f(s,n,{get:()=>e[n],enumerable:!(r=S(e,n))||r.enumerable});return s};var w=s=>P(f({},"__esModule",{value:!0}),s);var T={};M(T,{default:()=>H,pluginRspackEmpShare:()=>d});module.exports=w(T);var R=require("@module-federation/enhanced/rspack");var b="EMP_SHARE_RUNTIME";var y=s=>`data:text/javascript,${s}`;var L=!1,v=L?console.log.bind(console,"[EMP Share]"):()=>{};var G=s=>{let e=[`import '${s}'`].join(`
|
|
2
|
+
`);return y(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:t}=e,{runtimeLib:r}=this.options;if(!r){let n=G("@empjs/share/library");new t.EntryPlugin(e.context,n,{name:void 0}).apply(e)}}};function g(s,e){return typeof s=="string"?`${s}/runtime${e==="development"?".development":""}.umd.js`:typeof s=="object"?e==="development"?s.dev:s.prod:""}var j=/^([0-9a-zA-Z_\s]+)@(.*)/,c=class{op;store;injectHtml=[];externalsLib=[];constructor(e,t){this.op=e||{},this.store=t}setup(){this.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.op.empRuntime.frameworkLib)return;let{store:e,injectHtml:t}=this,{frameworkLib:r}=this.op.empRuntime;if(r){let n=g(r,e.mode);t.push({attributes:{src:n},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:t}=this;e.framework=Object.hasOwn(e,"framework")?e.framework:"react",e.runtimeGlobal=e.runtimeGlobal||b,e.frameworkGlobal=e.frameworkGlobal||(e.shareLib?"window":""),e.injectGlobalValToHtml!==!1&&t.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${e.frameworkGlobal}',runtimeLib:'${e.runtimeGlobal}',framework:'${e.framework}'}`})}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:t}=this,{empRuntime:r}=this.op,{framework:n,shareLib:o,runtimeGlobal:i,frameworkGlobal:a}=r,h={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},p={};for(let[m,u]of Object.entries(h))p[m]=`${i}.${u}`;if(n==="react"&&!o&&a){let m={react:"React","react-dom":"ReactDOM"};for(let[u,E]of Object.entries(m))p[u]=`${a}.${E}`}o&&t.map(m=>{m.type==="js"&&m.module&&m.global&&(p[m.module]=`${a}.${m.global}`)}),r.setExternals&&r.setExternals(p),e.chain.merge({externals:p})}setRuntimeLib(){if(!this.op.empRuntime)return;let{runtimeLib:e,shareLib:t}=this.op.empRuntime,{store:r,injectHtml:n}=this,{empRuntime:o}=this.op;e?e==="useFrameworkLib"&&!t||n.push({tagName:"script",pos:"head",attributes:{src:e}}):r.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 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(R.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,o]of Object.entries(e)){let i={};if(i.module=n,typeof o=="string"){let a=o.match(j)||[];a.length>0?(i.global=a[1],i.entry=a[2],i.type="js",t.push(i),i={}):(i.global="",i.entry=o,i.type="js",t.push(i),i={})}else Array.isArray(o)?o.map(a=>{if(!a)return;if(a.split("?")[0].endsWith(".css"))i.entry=a,i.type="css";else{let p=a.match(j)||[];p.length>0?(i.global=p[1],i.entry=p[2],i.type="js"):(i.global="",i.entry=a,i.type="js")}t.push(i),i={}}):typeof o=="object"&&o.entry&&(i.entry=o.entry,i.global=o.global,i.type=o.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 d=(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()}}),H=d;0&&(module.exports={pluginRspackEmpShare});
|
|
3
3
|
//# sourceMappingURL=rspack.cjs.map
|
package/dist/rspack.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugins/rspack/index.ts","../src/plugins/rspack/share.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {EmpShare} from './share'\nimport type {EMPPluginShareType} from './types'\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n //\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 //\n const empShare = new EmpShare(o, store)\n empShare.setup()\n },\n }\n}\nexport default pluginRspackEmpShare\n","import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType, ExternalsItemType, ModuleFederationPluginOptions} from './types'\nimport {getRuntimeLib} from './utils'\nconst exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\nexport class EmpShare {\n private op: EMPPluginShareType\n private store: GlobalStore\n /**\n * 注入资源\n */\n private injectHtml: any[] = []\n /**\n * 兼容 shareLib\n */\n private externalsLib: ExternalsItemType[] = []\n constructor(op: EMPPluginShareType, store: GlobalStore) {\n this.op = op || {}\n this.store = store\n }\n setup() {\n this.setMF() // 设置 MF 配置\n this.injectGlobalVal() // 插入全局变量 方便emp外的项目调用\n this.injectFramework() // 插入ui框架库\n this.setShareLib() //兼容 emp Sharelib的共享模型设置\n this.setRuntimeLib() // 设置 MF SDK\n this.injectToHtml() //触发插入动作\n this.setExternal() // 设置 external 降低包体\n }\n private injectToHtml() {\n const {store, injectHtml} = this\n if (injectHtml.length > 0) {\n store.injectTags(injectHtml, 'EMPShare')\n }\n }\n private injectFramework() {\n if (!this.op.empRuntime || !this.op.empRuntime.frameworkLib) return\n const {store, injectHtml} = this\n const {frameworkLib} = this.op.empRuntime\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n })\n }\n }\n private injectGlobalVal() {\n if (!this.op.empRuntime) return\n const {empRuntime} = this.op\n const {injectHtml} = this\n empRuntime.framework = Object.hasOwn(empRuntime, 'framework') ? empRuntime.framework : 'react'\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || (empRuntime.shareLib ? 'window' : '')\n\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${empRuntime.frameworkGlobal}',runtimeLib:'${empRuntime.runtimeGlobal}',framework:'${empRuntime.framework}'}`,\n })\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {framework, shareLib, runtimeGlobal, frameworkGlobal} = empRuntime\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && !shareLib && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${frameworkGlobal}.${v.global}`\n }\n })\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n private setRuntimeLib() {\n if (!this.op.empRuntime) return\n\n const {runtimeLib, shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions & {empRuntime: any}>(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n if (op.empRuntime) {\n delete op.empRuntime\n }\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\n })\n }\n }\n}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,yBAAAC,IAAA,eAAAC,EAAAJ,GCCA,IAAAK,EAAqC,8CCD9B,IAAMC,EAAkB,oBCAxB,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GAqBvE,IAAMC,EAAQ,GACRC,EAAMD,EAAQ,QAAQ,IAAI,KAAK,QAAS,aAAa,EAAI,IAAM,CAAC,ECnB7E,IAAME,EAAuBC,GAAO,CAClC,IAAMC,EAAU,CAAC,WAAWD,CAAG,GAAG,EAAE,KAAK;AAAA,CAAI,EAC7C,OAAOE,EAAWD,CAAO,CAC3B,EACaE,EAAN,KAA8B,CACnC,QACA,YAAYC,EAA4B,CACtC,KAAK,QAAUA,CACjB,CACA,MAAMC,EAAoB,CACxB,GAAM,CAAC,QAAAC,CAAO,EAAID,EACZ,CAAC,WAAAE,CAAU,EAAI,KAAK,QAC1B,GAAI,CAACA,EAAY,CACf,IAAMC,EAAQT,EAAqB,sBAAsB,EACzD,IAAIO,EAAQ,YAAYD,EAAS,QAASG,EAAO,CAC/C,KAAM,MACR,CAAC,EAAE,MAAMH,CAAQ,CACnB,CACF,CACF,ECrBO,SAASI,EAAcC,EAA8CC,EAAc,CACxF,OAAI,OAAOD,GAAS,SAAiB,GAAGA,CAAI,WAAWC,IAAS,cAAgB,eAAiB,EAAE,UAC1F,OAAOD,GAAS,SACnBC,IAAS,cAAsBD,EAAK,IAC5BA,EAAK,KAEZ,EACT,CJFA,IAAME,EAAM,0BACCC,EAAN,KAAe,CACZ,GACA,MAIA,WAAoB,CAAC,EAIrB,aAAoC,CAAC,EAC7C,YAAYC,EAAwBC,EAAoB,CACtD,KAAK,GAAKD,GAAM,CAAC,EACjB,KAAK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EAC/BA,EAAgB,CAAC,CACnB,CAAC,EACQ,OAAOL,GAAM,UAAYA,EAAE,QACpCK,EAAc,MAAQL,EAAE,MACxBK,EAAc,OAASL,EAAE,OACzBK,EAAc,KAAOL,EAAE,KACvBV,EAAa,KAAKe,CAAa,EAC/BA,EAAgB,CAAC,EAErB,CAEAf,EAAa,IAAIU,GAAK,CAChBA,EAAE,OAAS,KACbhB,EAAW,KAAK,CACd,WAAY,CACV,IAAKgB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBhB,EAAW,KAAK,CACd,WAAY,CACV,KAAMgB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EDtNO,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,GAGjD,IAAIE,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ","names":["rspack_exports","__export","rspack_default","pluginRspackEmpShare","__toCommonJS","import_rspack","shareGlobalName","importJsVm","content","isDev","log","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","exp","EmpShare","op","store","injectHtml","frameworkLib","url","getRuntimeLib","empRuntime","shareGlobalName","externalsLib","framework","shareLib","runtimeGlobal","frameworkGlobal","externalRuntime","externals","key","value","externalReact","v","runtimeLib","EmpShareRemoteLibPlugin","o","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default"]}
|
|
1
|
+
{"version":3,"sources":["../src/plugins/rspack/index.ts","../src/plugins/rspack/share.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {EmpShare} from './share'\nimport type {EMPPluginShareType} from './types'\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n //\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 {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType, ExternalsItemType, ModuleFederationPluginOptions} from './types'\nimport {getRuntimeLib} from './utils'\nconst exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\nexport class EmpShare {\n private op: EMPPluginShareType\n private store: GlobalStore\n /**\n * 注入资源\n */\n private injectHtml: any[] = []\n /**\n * 兼容 shareLib\n */\n private externalsLib: ExternalsItemType[] = []\n constructor(op: EMPPluginShareType, store: GlobalStore) {\n this.op = op || {}\n this.store = store\n }\n setup() {\n this.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.op.empRuntime.frameworkLib) return\n const {store, injectHtml} = this\n const {frameworkLib} = this.op.empRuntime\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n })\n }\n }\n private injectGlobalVal() {\n if (!this.op.empRuntime) return\n const {empRuntime} = this.op\n const {injectHtml} = this\n empRuntime.framework = Object.hasOwn(empRuntime, 'framework') ? empRuntime.framework : 'react'\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || (empRuntime.shareLib ? 'window' : '')\n\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${empRuntime.frameworkGlobal}',runtimeLib:'${empRuntime.runtimeGlobal}',framework:'${empRuntime.framework}'}`,\n })\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {framework, shareLib, runtimeGlobal, frameworkGlobal} = empRuntime\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && !shareLib && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${frameworkGlobal}.${v.global}`\n }\n })\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n private setRuntimeLib() {\n if (!this.op.empRuntime) return\n\n const {runtimeLib, shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n }\n private 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 shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,yBAAAC,IAAA,eAAAC,EAAAJ,GCCA,IAAAK,EAAqC,8CCD9B,IAAMC,EAAkB,oBCAxB,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GAqBvE,IAAMC,EAAQ,GACRC,EAAMD,EAAQ,QAAQ,IAAI,KAAK,QAAS,aAAa,EAAI,IAAM,CAAC,ECnB7E,IAAME,EAAuBC,GAAO,CAClC,IAAMC,EAAU,CAAC,WAAWD,CAAG,GAAG,EAAE,KAAK;AAAA,CAAI,EAC7C,OAAOE,EAAWD,CAAO,CAC3B,EACaE,EAAN,KAA8B,CACnC,QACA,YAAYC,EAA4B,CACtC,KAAK,QAAUA,CACjB,CACA,MAAMC,EAAoB,CACxB,GAAM,CAAC,QAAAC,CAAO,EAAID,EACZ,CAAC,WAAAE,CAAU,EAAI,KAAK,QAC1B,GAAI,CAACA,EAAY,CACf,IAAMC,EAAQT,EAAqB,sBAAsB,EACzD,IAAIO,EAAQ,YAAYD,EAAS,QAASG,EAAO,CAC/C,KAAM,MACR,CAAC,EAAE,MAAMH,CAAQ,CACnB,CACF,CACF,ECrBO,SAASI,EAAcC,EAA8CC,EAAc,CACxF,OAAI,OAAOD,GAAS,SAAiB,GAAGA,CAAI,WAAWC,IAAS,cAAgB,eAAiB,EAAE,UAC1F,OAAOD,GAAS,SACnBC,IAAS,cAAsBD,EAAK,IAC5BA,EAAK,KAEZ,EACT,CJFA,IAAME,EAAM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QL,CAAC,EACxBA,EAAE,IAAIO,GAAM,CACV,GAAI,CAACA,EAAI,OAET,GADcA,EAAG,MAAM,GAAG,EAAE,CAAC,EAAE,SAAS,MAAM,EAE5CF,EAAc,MAAQE,EACtBF,EAAc,KAAO,UAChB,CACL,IAAMC,EAAUC,EAAG,MAAM3B,CAAG,GAAK,CAAC,EAC9B0B,EAAG,OAAS,GACdD,EAAc,OAASC,EAAG,CAAC,EAC3BD,EAAc,MAAQC,EAAG,CAAC,EAC1BD,EAAc,KAAO,OAErBA,EAAc,OAAS,GACvBA,EAAc,MAAQE,EACtBF,EAAc,KAAO,KAEzB,CACAf,EAAa,KAAKe,CAAa,EAC/BA,EAAgB,CAAC,CACnB,CAAC,EACQ,OAAOL,GAAM,UAAYA,EAAE,QACpCK,EAAc,MAAQL,EAAE,MACxBK,EAAc,OAASL,EAAE,OACzBK,EAAc,KAAOL,EAAE,KACvBV,EAAa,KAAKe,CAAa,EAC/BA,EAAgB,CAAC,EAErB,CAEAf,EAAa,IAAIU,GAAK,CAChBA,EAAE,OAAS,KACbhB,EAAW,KAAK,CACd,WAAY,CACV,IAAKgB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBhB,EAAW,KAAK,CACd,WAAY,CACV,KAAMgB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EDjOO,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":["rspack_exports","__export","rspack_default","pluginRspackEmpShare","__toCommonJS","import_rspack","shareGlobalName","importJsVm","content","isDev","log","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","exp","EmpShare","op","store","injectHtml","frameworkLib","url","getRuntimeLib","empRuntime","shareGlobalName","externalsLib","framework","shareLib","runtimeGlobal","frameworkGlobal","externalRuntime","externals","key","value","externalReact","v","runtimeLib","EmpShareRemoteLibPlugin","o","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default"]}
|
package/dist/rspack.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{ModuleFederationPlugin as E}from"@module-federation/enhanced/rspack";var h="EMP_SHARE_RUNTIME";var b=
|
|
2
|
-
`);return b(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:i}=e,{runtimeLib:
|
|
1
|
+
import{ModuleFederationPlugin as E}from"@module-federation/enhanced/rspack";var h="EMP_SHARE_RUNTIME";var b=s=>`data:text/javascript,${s}`;var R=!1,k=R?console.log.bind(console,"[EMP Share]"):()=>{};var d=s=>{let e=[`import '${s}'`].join(`
|
|
2
|
+
`);return b(e)},l=class{options;constructor(e){this.options=e}apply(e){let{webpack:i}=e,{runtimeLib:r}=this.options;if(!r){let o=d("@empjs/share/library");new i.EntryPlugin(e.context,o,{name:void 0}).apply(e)}}};function y(s,e){return typeof s=="string"?`${s}/runtime${e==="development"?".development":""}.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,i){this.op=e||{},this.store=i}setup(){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.op.empRuntime.frameworkLib)return;let{store:e,injectHtml:i}=this,{frameworkLib:r}=this.op.empRuntime;if(r){let o=y(r,e.mode);i.push({attributes:{src:o},tagName:"script"})}}injectGlobalVal(){if(!this.op.empRuntime)return;let{empRuntime:e}=this.op,{injectHtml:i}=this;e.framework=Object.hasOwn(e,"framework")?e.framework:"react",e.runtimeGlobal=e.runtimeGlobal||h,e.frameworkGlobal=e.frameworkGlobal||(e.shareLib?"window":""),e.injectGlobalValToHtml!==!1&&i.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${e.frameworkGlobal}',runtimeLib:'${e.runtimeGlobal}',framework:'${e.framework}'}`})}setExternal(){if(!this.op.empRuntime)return;let{store:e,externalsLib:i}=this,{empRuntime:r}=this.op,{framework:o,shareLib:n,runtimeGlobal:t,frameworkGlobal:a}=r,f={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},p={};for(let[m,u]of Object.entries(f))p[m]=`${t}.${u}`;if(o==="react"&&!n&&a){let m={react:"React","react-dom":"ReactDOM"};for(let[u,j]of Object.entries(m))p[u]=`${a}.${j}`}n&&i.map(m=>{m.type==="js"&&m.module&&m.global&&(p[m.module]=`${a}.${m.global}`)}),r.setExternals&&r.setExternals(p),e.chain.merge({externals:p})}setRuntimeLib(){if(!this.op.empRuntime)return;let{runtimeLib:e,shareLib:i}=this.op.empRuntime,{store:r,injectHtml:o}=this,{empRuntime:n}=this.op;e?e==="useFrameworkLib"&&!i||o.push({tagName:"script",pos:"head",attributes:{src:e}}):r.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:i}=this;if(e.name){let r=i.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},e);r.empRuntime&&delete r.empRuntime,i.chain.plugin("plugin-emp-share").use(E,[r])}}setShareLib(){if(!this.op.empRuntime)return;let{shareLib:e}=this.op.empRuntime,{externalsLib:i,injectHtml:r}=this;if(e&&typeof e=="object"){for(let[o,n]of Object.entries(e)){let t={};if(t.module=o,typeof n=="string"){let a=n.match(g)||[];a.length>0?(t.global=a[1],t.entry=a[2],t.type="js",i.push(t),t={}):(t.global="",t.entry=n,t.type="js",i.push(t),t={})}else Array.isArray(n)?n.map(a=>{if(!a)return;if(a.split("?")[0].endsWith(".css"))t.entry=a,t.type="css";else{let p=a.match(g)||[];p.length>0?(t.global=p[1],t.entry=p[2],t.type="js"):(t.global="",t.entry=a,t.type="js")}i.push(t),t={}}):typeof n=="object"&&n.entry&&(t.entry=n.entry,t.global=n.global,t.type=n.type,i.push(t),t={})}i.map(o=>{o.type==="js"?r.push({attributes:{src:o.entry},tagName:"script"}):o.type==="css"&&r.push({attributes:{href:o.entry,rel:"stylesheet"},tagName:"link"})})}}};var S=(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()}}),A=S;export{A as default,S as pluginRspackEmpShare};
|
|
3
3
|
//# sourceMappingURL=rspack.js.map
|
package/dist/rspack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugins/rspack/share.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts","../src/plugins/rspack/index.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType, ExternalsItemType, ModuleFederationPluginOptions} from './types'\nimport {getRuntimeLib} from './utils'\nconst exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\nexport class EmpShare {\n private op: EMPPluginShareType\n private store: GlobalStore\n /**\n * 注入资源\n */\n private injectHtml: any[] = []\n /**\n * 兼容 shareLib\n */\n private externalsLib: ExternalsItemType[] = []\n constructor(op: EMPPluginShareType, store: GlobalStore) {\n this.op = op || {}\n this.store = store\n }\n setup() {\n this.setMF() // 设置 MF 配置\n this.injectGlobalVal() // 插入全局变量 方便emp外的项目调用\n this.injectFramework() // 插入ui框架库\n this.setShareLib() //兼容 emp Sharelib的共享模型设置\n this.setRuntimeLib() // 设置 MF SDK\n this.injectToHtml() //触发插入动作\n this.setExternal() // 设置 external 降低包体\n }\n private injectToHtml() {\n const {store, injectHtml} = this\n if (injectHtml.length > 0) {\n store.injectTags(injectHtml, 'EMPShare')\n }\n }\n private injectFramework() {\n if (!this.op.empRuntime || !this.op.empRuntime.frameworkLib) return\n const {store, injectHtml} = this\n const {frameworkLib} = this.op.empRuntime\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n })\n }\n }\n private injectGlobalVal() {\n if (!this.op.empRuntime) return\n const {empRuntime} = this.op\n const {injectHtml} = this\n empRuntime.framework = Object.hasOwn(empRuntime, 'framework') ? empRuntime.framework : 'react'\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || (empRuntime.shareLib ? 'window' : '')\n\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${empRuntime.frameworkGlobal}',runtimeLib:'${empRuntime.runtimeGlobal}',framework:'${empRuntime.framework}'}`,\n })\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {framework, shareLib, runtimeGlobal, frameworkGlobal} = empRuntime\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && !shareLib && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${frameworkGlobal}.${v.global}`\n }\n })\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n private setRuntimeLib() {\n if (!this.op.empRuntime) return\n\n const {runtimeLib, shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n }\n private setMF() {\n const o = this.op\n const {store} = this\n if (o.name) {\n const op = store.deepAssign<ModuleFederationPluginOptions & {empRuntime: any}>(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n if (op.empRuntime) {\n delete op.empRuntime\n }\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n }\n private setShareLib() {\n if (!this.op.empRuntime) return\n const {shareLib} = this.op.empRuntime\n const {externalsLib, injectHtml} = this\n if (shareLib && typeof shareLib === 'object') {\n for (const [k, v] of Object.entries(shareLib)) {\n let externalsItem: ExternalsItemType = {}\n externalsItem.module = k\n //增加下划线 支持lodash 等特殊符号的问题 如 _@http\n\n if (typeof v === 'string') {\n const cb: any = v.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n } else {\n externalsItem.global = ''\n externalsItem.entry = v\n externalsItem.type = 'js'\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n } else if (Array.isArray(v)) {\n v.map(vo => {\n if (!vo) return\n const isCSS = vo.split('?')[0].endsWith('.css')\n if (isCSS) {\n externalsItem.entry = vo\n externalsItem.type = 'css'\n } else {\n const cb: any = vo.match(exp) || []\n if (cb.length > 0) {\n externalsItem.global = cb[1]\n externalsItem.entry = cb[2]\n externalsItem.type = 'js'\n } else {\n externalsItem.global = ''\n externalsItem.entry = vo\n externalsItem.type = 'js'\n }\n }\n externalsLib.push(externalsItem)\n externalsItem = {}\n })\n } else if (typeof v === 'object' && v.entry) {\n externalsItem.entry = v.entry\n externalsItem.global = v.global\n externalsItem.type = v.type\n externalsLib.push(externalsItem)\n externalsItem = {}\n }\n }\n // console.log(externalsLib)\n externalsLib.map(v => {\n if (v.type === 'js') {\n injectHtml.push({\n attributes: {\n src: v.entry,\n },\n tagName: 'script',\n })\n } else if (v.type === 'css') {\n injectHtml.push({\n attributes: {\n href: v.entry,\n rel: 'stylesheet',\n },\n tagName: 'link',\n })\n }\n })\n }\n }\n}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n","import type {GlobalStore} from '@empjs/cli'\nimport {EmpShare} from './share'\nimport type {EMPPluginShareType} from './types'\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n //\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 //\n const empShare = new EmpShare(o, store)\n empShare.setup()\n },\n }\n}\nexport default pluginRspackEmpShare\n"],"mappings":"AACA,OAAQ,0BAAAA,MAA6B,qCCD9B,IAAMC,EAAkB,oBCAxB,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GAqBvE,IAAMC,EAAQ,GACRC,EAAMD,EAAQ,QAAQ,IAAI,KAAK,QAAS,aAAa,EAAI,IAAM,CAAC,ECnB7E,IAAME,EAAuBC,GAAO,CA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ACF,CACF,EKtNO,IAAMS,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,GAGjD,IAAIE,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ","names":["ModuleFederationPlugin","shareGlobalName","importJsVm","content","isDev","log","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","exp","EmpShare","op","store","injectHtml","frameworkLib","url","getRuntimeLib","empRuntime","shareGlobalName","externalsLib","framework","shareLib","runtimeGlobal","frameworkGlobal","externalRuntime","externals","key","value","externalReact","v","runtimeLib","EmpShareRemoteLibPlugin","o","ModuleFederationPlugin","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default"]}
|
|
1
|
+
{"version":3,"sources":["../src/plugins/rspack/share.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts","../src/plugins/rspack/index.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType, ExternalsItemType, ModuleFederationPluginOptions} from './types'\nimport {getRuntimeLib} from './utils'\nconst exp = /^([0-9a-zA-Z_\\s]+)@(.*)/\nexport class EmpShare {\n private op: EMPPluginShareType\n private store: GlobalStore\n /**\n * 注入资源\n */\n private injectHtml: any[] = []\n /**\n * 兼容 shareLib\n */\n private externalsLib: ExternalsItemType[] = []\n constructor(op: EMPPluginShareType, store: GlobalStore) {\n this.op = op || {}\n this.store = store\n }\n setup() {\n this.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.op.empRuntime.frameworkLib) return\n const {store, injectHtml} = this\n const {frameworkLib} = this.op.empRuntime\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n })\n }\n }\n private injectGlobalVal() {\n if (!this.op.empRuntime) return\n const {empRuntime} = this.op\n const {injectHtml} = this\n empRuntime.framework = Object.hasOwn(empRuntime, 'framework') ? empRuntime.framework : 'react'\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || (empRuntime.shareLib ? 'window' : '')\n\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${empRuntime.frameworkGlobal}',runtimeLib:'${empRuntime.runtimeGlobal}',framework:'${empRuntime.framework}'}`,\n })\n }\n }\n private setExternal() {\n if (!this.op.empRuntime) return\n const {store, externalsLib} = this\n const {empRuntime} = this.op\n const {framework, shareLib, runtimeGlobal, frameworkGlobal} = empRuntime\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && !shareLib && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (shareLib) {\n externalsLib.map(v => {\n if (v.type === 'js' && v.module && v.global) {\n externals[v.module] = `${frameworkGlobal}.${v.global}`\n }\n })\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n private setRuntimeLib() {\n if (!this.op.empRuntime) return\n\n const {runtimeLib, shareLib} = this.op.empRuntime\n const {store, injectHtml} = this\n const {empRuntime} = this.op\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib' && !shareLib) {\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n }\n private 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 shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n","import type {GlobalStore} from '@empjs/cli'\nimport {EmpShare} from './share'\nimport type {EMPPluginShareType} from './types'\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n //\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,EAAkB,oBCAxB,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GAqBvE,IAAMC,EAAQ,GACRC,EAAMD,EAAQ,QAAQ,IAAI,KAAK,QAAS,aAA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M,EAAc,KAAON,EAAE,KACvBV,EAAa,KAAKgB,CAAa,EAC/BA,EAAgB,CAAC,EAErB,CAEAhB,EAAa,IAAIU,GAAK,CAChBA,EAAE,OAAS,KACbhB,EAAW,KAAK,CACd,WAAY,CACV,IAAKgB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBhB,EAAW,KAAK,CACd,WAAY,CACV,KAAMgB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EKjOO,IAAMS,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","shareGlobalName","importJsVm","content","isDev","log","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","exp","EmpShare","op","store","injectHtml","frameworkLib","url","getRuntimeLib","empRuntime","shareGlobalName","externalsLib","framework","shareLib","runtimeGlobal","frameworkGlobal","externalRuntime","externals","key","value","externalReact","v","runtimeLib","EmpShareRemoteLibPlugin","o","ModuleFederationPlugin","k","externalsItem","cb","vo","pluginRspackEmpShare","o","store","EmpShare","rspack_default"]}
|