@empjs/share 3.1.5 → 3.1.7
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.map +1 -1
- package/output/sdk.js.map +1 -1
- package/output/sdkPolyfill.js.map +1 -1
- package/package.json +18 -33
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var
|
|
2
|
-
`);return d(e)},m=class{options;constructor(e){this.options=e}apply(e){let{webpack:
|
|
1
|
+
"use strict";var u=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var S=(t,e)=>{for(var r in e)u(t,r,{get:e[r],enumerable:!0})},M=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of k(e))!x.call(t,o)&&o!==r&&u(t,o,{get:()=>e[o],enumerable:!(n=j(e,o))||n.enumerable});return t};var P=t=>M(u({},"__esModule",{value:!0}),t);var O={};S(O,{default:()=>H,pluginRspackEmpShare:()=>f});module.exports=P(O);var g=require("@module-federation/enhanced/rspack");var y="EMP_SHARE_RUNTIME";var d=t=>`data:text/javascript,${t}`;var w=t=>{let e=[`import '${t}'`].join(`
|
|
2
|
+
`);return d(e)},m=class{options;constructor(e){this.options=e}apply(e){let{webpack:r}=e,{runtimeLib:n}=this.options;if(!n){let o=w("@empjs/share/library");new r.EntryPlugin(e.context,o,{name:void 0}).apply(e)}}};function R(t,e){return typeof t=="string"?`${t}/runtime${e==="development"?".development":""}.umd.js`:typeof t=="object"?e==="development"?t.dev:t.prod:""}var G=(t={})=>({name:"@empjs/share",async rsConfig(e){if(t.name){let n=e.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},t);delete n.empRuntime,e.chain.plugin("plugin-emp-share").use(g.ModuleFederationPlugin,[n])}let{empRuntime:r}=t;if(r){let n=[],o=r.framework||"react",{frameworkLib:b,runtimeLib:p}=r,l=r.runtimeGlobal||y,a=r.frameworkGlobal||"";if(r.injectGlobalValToHtml!==!1&&n.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${a}',runtimeLib:'${l}',framework:'${o}'}`}),b){let i=R(b,e.mode);n.push({attributes:{src:i},tagName:"script"})}p?p==="useFrameworkLib"?l=a:n.push({tagName:"script",pos:"head",attributes:{src:p}}):e.chain.plugin("plugin-emp-share-framework").use(m,[r]),n.length>0&&e.injectTags(n,"EMPShare");let E={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},s={};for(let[i,c]of Object.entries(E))s[i]=`${l}.${c}`;if(o==="react"&&a){let i={react:"React","react-dom":"ReactDOM"};for(let[c,h]of Object.entries(i))s[c]=`${a}.${h}`}r.setExternals&&r.setExternals(s),e.chain.merge({externals:s})}}}),f=G;var H=f;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/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts"],"sourcesContent":["import {default as pluginRspackEmpShare} from 'src/plugins/rspack'\nexport default pluginRspackEmpShare\nexport {pluginRspackEmpShare}\n","import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\nimport {getRuntimeLib} from './utils'\n//\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n if (o.name) {\n const op: any = store.deepAssign(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n delete op.empRuntime\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n const {empRuntime} = o\n if (empRuntime) {\n const injectHtml: any[] = []\n const framework = empRuntime.framework || 'react'\n const {frameworkLib, runtimeLib} = empRuntime\n //\n let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n const frameworkGlobal = empRuntime.frameworkGlobal || ''\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n type: 'js',\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/plugins/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts"],"sourcesContent":["import {default as pluginRspackEmpShare} from 'src/plugins/rspack'\nexport default pluginRspackEmpShare\nexport {pluginRspackEmpShare}\n","import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\nimport {getRuntimeLib} from './utils'\n//\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n if (o.name) {\n const op: any = store.deepAssign(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n delete op.empRuntime\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n const {empRuntime} = o\n if (empRuntime) {\n const injectHtml: any[] = []\n const framework = empRuntime.framework || 'react'\n const {frameworkLib, runtimeLib} = empRuntime\n //\n let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n const frameworkGlobal = empRuntime.frameworkGlobal || ''\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${frameworkGlobal}',runtimeLib:'${runtimeGlobal}',framework:'${framework}'}`,\n })\n }\n /**\n * frameworkLib & runtimeLib 的全局引用\n */\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n // type: 'js',\n // src: url,\n })\n }\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n //\n\n // store.chain.optimization.merge({\n // splitChunks: {\n // cacheGroups: {\n // moduleFederation: {\n // name: 'mfRuntime',\n // test: /[\\\\/]node_modules[\\\\/](@module-federation)[\\\\/]/,\n // priority: 0,\n // chunks: 'all',\n // },\n // },\n // },\n // })\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib') {\n runtimeGlobal = frameworkGlobal\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n if (injectHtml.length > 0) {\n store.injectTags(injectHtml, 'EMPShare')\n }\n /**\n * 设置 externals\n */\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n },\n }\n}\n\nexport default pluginRspackEmpShare\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,yBAAAC,IAAA,eAAAC,EAAAJ,GCCA,IAAAK,EAAqC,8CCD9B,IAAMC,E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,GAZ8BA,EAAW,wBAA0B,IAGjEC,EAAW,KAAK,CAEd,QAAS,SACT,UAAW,oCAAoCM,CAAe,iBAAiBF,CAAa,gBAAgBH,CAAS,IACvH,CAAC,EAKCC,EAAc,CAChB,IAAMK,EAAMC,EAAcN,EAAcL,EAAM,IAAI,EAClDG,EAAW,KAAK,CACd,WAAY,CACV,IAAKO,CACP,EACA,QAAS,QAGX,CAAC,CACH,CACKJ,EAmBIA,IAAe,kBACtBC,EAAgBE,EAGhBN,EAAW,KAAK,CAAC,QAAS,SAAU,IAAK,OAAQ,WAAY,CAAC,IAAKG,CAAU,CAAC,CAAC,EArB/EN,EAAM,MAAM,OAAO,4BAA4B,EAAE,IAAIY,EAAyB,CAACV,CAAU,CAAC,EAuBxFC,EAAW,OAAS,GACtBH,EAAM,WAAWG,EAAY,UAAU,EAKzC,IAAMU,EAAkB,CACtB,6BAA8B,YAC9B,yBAA0B,OAC5B,EACMC,EAAY,CAAC,EACnB,OAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQH,CAAe,EACvDC,EAAUC,CAAG,EAAI,GAAGR,CAAa,IAAIS,CAAK,GAE5C,GAAIZ,IAAc,SAAWK,EAAiB,CAC5C,IAAMQ,EAAgB,CACpB,MAAO,QACP,YAAa,UACf,EACA,OAAW,CAACF,EAAKC,CAAK,IAAK,OAAO,QAAQC,CAAa,EACrDH,EAAUC,CAAG,EAAI,GAAGN,CAAe,IAAIO,CAAK,EAEhD,CACId,EAAW,cAAcA,EAAW,aAAaY,CAAS,EAG9Dd,EAAM,MAAM,MAAM,CAAC,UAAAc,CAAS,CAAC,CAC/B,CACF,CACF,GAGKI,EAAQpB,EDjHf,IAAOqB,EAAQC","names":["src_exports","__export","src_default","rspack_default","__toCommonJS","import_rspack","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","pluginRspackEmpShare","o","store","op","empRuntime","injectHtml","framework","frameworkLib","runtimeLib","runtimeGlobal","shareGlobalName","frameworkGlobal","url","getRuntimeLib","EmpShareRemoteLibPlugin","externalRuntime","externals","key","value","externalReact","rspack_default","src_default","rspack_default"]}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{ModuleFederationPlugin as
|
|
2
|
-
`);return b(e)},m=class{options;constructor(e){this.options=e}apply(e){let{webpack:
|
|
1
|
+
import{ModuleFederationPlugin as h}from"@module-federation/enhanced/rspack";var f="EMP_SHARE_RUNTIME";var b=t=>`data:text/javascript,${t}`;var E=t=>{let e=[`import '${t}'`].join(`
|
|
2
|
+
`);return b(e)},m=class{options;constructor(e){this.options=e}apply(e){let{webpack:r}=e,{runtimeLib:n}=this.options;if(!n){let i=E("@empjs/share/library");new r.EntryPlugin(e.context,i,{name:void 0}).apply(e)}}};function y(t,e){return typeof t=="string"?`${t}/runtime${e==="development"?".development":""}.umd.js`:typeof t=="object"?e==="development"?t.dev:t.prod:""}var j=(t={})=>({name:"@empjs/share",async rsConfig(e){if(t.name){let n=e.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},t);delete n.empRuntime,e.chain.plugin("plugin-emp-share").use(h,[n])}let{empRuntime:r}=t;if(r){let n=[],i=r.framework||"react",{frameworkLib:u,runtimeLib:p}=r,l=r.runtimeGlobal||f,a=r.frameworkGlobal||"";if(r.injectGlobalValToHtml!==!1&&n.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${a}',runtimeLib:'${l}',framework:'${i}'}`}),u){let o=y(u,e.mode);n.push({attributes:{src:o},tagName:"script"})}p?p==="useFrameworkLib"?l=a:n.push({tagName:"script",pos:"head",attributes:{src:p}}):e.chain.plugin("plugin-emp-share-framework").use(m,[r]),n.length>0&&e.injectTags(n,"EMPShare");let R={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},s={};for(let[o,c]of Object.entries(R))s[o]=`${l}.${c}`;if(i==="react"&&a){let o={react:"React","react-dom":"ReactDOM"};for(let[c,g]of Object.entries(o))s[c]=`${a}.${g}`}r.setExternals&&r.setExternals(s),e.chain.merge({externals:s})}}}),d=j;var v=d;export{v as default,d as pluginRspackEmpShare};
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugins/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts","../src/index.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\nimport {getRuntimeLib} from './utils'\n//\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n if (o.name) {\n const op: any = store.deepAssign(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n delete op.empRuntime\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n const {empRuntime} = o\n if (empRuntime) {\n const injectHtml: any[] = []\n const framework = empRuntime.framework || 'react'\n const {frameworkLib, runtimeLib} = empRuntime\n //\n let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n const frameworkGlobal = empRuntime.frameworkGlobal || ''\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n type: 'js',\n
|
|
1
|
+
{"version":3,"sources":["../src/plugins/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts","../src/index.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\nimport {getRuntimeLib} from './utils'\n//\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n if (o.name) {\n const op: any = store.deepAssign(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n delete op.empRuntime\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n const {empRuntime} = o\n if (empRuntime) {\n const injectHtml: any[] = []\n const framework = empRuntime.framework || 'react'\n const {frameworkLib, runtimeLib} = empRuntime\n //\n let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n const frameworkGlobal = empRuntime.frameworkGlobal || ''\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${frameworkGlobal}',runtimeLib:'${runtimeGlobal}',framework:'${framework}'}`,\n })\n }\n /**\n * frameworkLib & runtimeLib 的全局引用\n */\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n // type: 'js',\n // src: url,\n })\n }\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n //\n\n // store.chain.optimization.merge({\n // splitChunks: {\n // cacheGroups: {\n // moduleFederation: {\n // name: 'mfRuntime',\n // test: /[\\\\/]node_modules[\\\\/](@module-federation)[\\\\/]/,\n // priority: 0,\n // chunks: 'all',\n // },\n // },\n // },\n // })\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib') {\n runtimeGlobal = frameworkGlobal\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n if (injectHtml.length > 0) {\n store.injectTags(injectHtml, 'EMPShare')\n }\n /**\n * 设置 externals\n */\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n },\n }\n}\n\nexport default pluginRspackEmpShare\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n","import {default as pluginRspackEmpShare} from 'src/plugins/rspack'\nexport default pluginRspackEmpShare\nexport {pluginRspackEmpShare}\n"],"mappings":"AACA,OAAQ,0BAAAA,MAA6B,qCCD9B,IAAMC,EAAkB,oBCAxB,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GCG9E,IAAMC,EAAuBC,GAAO,CAClC,IAAMC,EAAU,CAAC,WAAWD,CAAG,GAAG,EAAE,KAAK;AAAA,CAAI,EAC7C,OAAOE,EAAWD,CAAO,CAC3B,EACaE,EAAN,KAA8B,CACnC,QACA,YAAYC,EAA4B,CACtC,KAAK,QAAUA,CACjB,CACA,MAAMC,EAAoB,CACxB,GAAM,CAAC,QAAAC,CAAO,EAAID,EACZ,CAAC,WAAAE,CAAU,EAAI,KAAK,QAC1B,GAAI,CAACA,EAAY,CACf,IAAMC,EAAQT,EAAqB,sBAAsB,EACzD,IAAIO,EAAQ,YAAYD,EAAS,QAASG,EAAO,CAC/C,KAAM,MACR,CAAC,EAAE,MAAMH,CAAQ,CACnB,CACF,CACF,ECrBO,SAASI,EAAcC,EAA8CC,EAAc,CACxF,OAAI,OAAOD,GAAS,SAAiB,GAAGA,CAAI,WAAWC,IAAS,cAAgB,eAAiB,EAAE,UAC1F,OAAOD,GAAS,SACnBC,IAAS,cAAsBD,EAAK,IAC5BA,EAAK,KAEZ,EACT,CJDO,IAAME,EAAuB,CAACC,EAAwB,CAA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B,CAC5C,IAAMQ,EAAgB,CACpB,MAAO,QACP,YAAa,UACf,EACA,OAAW,CAACF,EAAKC,CAAK,IAAK,OAAO,QAAQC,CAAa,EACrDH,EAAUC,CAAG,EAAI,GAAGN,CAAe,IAAIO,CAAK,EAEhD,CACId,EAAW,cAAcA,EAAW,aAAaY,CAAS,EAG9Df,EAAM,MAAM,MAAM,CAAC,UAAAe,CAAS,CAAC,CAC/B,CACF,CACF,GAGKI,EAAQrB,EKjHf,IAAOsB,EAAQC","names":["ModuleFederationPlugin","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","pluginRspackEmpShare","o","store","op","ModuleFederationPlugin","empRuntime","injectHtml","framework","frameworkLib","runtimeLib","runtimeGlobal","shareGlobalName","frameworkGlobal","url","getRuntimeLib","EmpShareRemoteLibPlugin","externalRuntime","externals","key","value","externalReact","rspack_default","src_default","rspack_default"]}
|
package/dist/rspack.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var
|
|
2
|
-
`);return y(e)},m=class{options;constructor(e){this.options=e}apply(e){let{webpack:n}=e,{runtimeLib:
|
|
1
|
+
"use strict";var u=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var M=(t,e)=>{for(var n in e)u(t,n,{get:e[n],enumerable:!0})},P=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of k(e))!x.call(t,o)&&o!==n&&u(t,o,{get:()=>e[o],enumerable:!(r=j(e,o))||r.enumerable});return t};var S=t=>P(u({},"__esModule",{value:!0}),t);var H={};M(H,{default:()=>G,pluginRspackEmpShare:()=>g});module.exports=S(H);var R=require("@module-federation/enhanced/rspack");var b="EMP_SHARE_RUNTIME";var y=t=>`data:text/javascript,${t}`;var w=t=>{let e=[`import '${t}'`].join(`
|
|
2
|
+
`);return y(e)},m=class{options;constructor(e){this.options=e}apply(e){let{webpack:n}=e,{runtimeLib:r}=this.options;if(!r){let o=w("@empjs/share/library");new n.EntryPlugin(e.context,o,{name:void 0}).apply(e)}}};function d(t,e){return typeof t=="string"?`${t}/runtime${e==="development"?".development":""}.umd.js`:typeof t=="object"?e==="development"?t.dev:t.prod:""}var g=(t={})=>({name:"@empjs/share",async rsConfig(e){if(t.name){let r=e.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},t);delete r.empRuntime,e.chain.plugin("plugin-emp-share").use(R.ModuleFederationPlugin,[r])}let{empRuntime:n}=t;if(n){let r=[],o=n.framework||"react",{frameworkLib:f,runtimeLib:p}=n,l=n.runtimeGlobal||b,s=n.frameworkGlobal||"";if(n.injectGlobalValToHtml!==!1&&r.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${s}',runtimeLib:'${l}',framework:'${o}'}`}),f){let i=d(f,e.mode);r.push({attributes:{src:i},tagName:"script"})}p?p==="useFrameworkLib"?l=s:r.push({tagName:"script",pos:"head",attributes:{src:p}}):e.chain.plugin("plugin-emp-share-framework").use(m,[n]),r.length>0&&e.injectTags(r,"EMPShare");let E={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},a={};for(let[i,c]of Object.entries(E))a[i]=`${l}.${c}`;if(o==="react"&&s){let i={react:"React","react-dom":"ReactDOM"};for(let[c,h]of Object.entries(i))a[c]=`${s}.${h}`}n.setExternals&&n.setExternals(a),e.chain.merge({externals:a})}}}),G=g;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/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\nimport {getRuntimeLib} from './utils'\n//\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n if (o.name) {\n const op: any = store.deepAssign(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n delete op.empRuntime\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n const {empRuntime} = o\n if (empRuntime) {\n const injectHtml: any[] = []\n const framework = empRuntime.framework || 'react'\n const {frameworkLib, runtimeLib} = empRuntime\n //\n let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n const frameworkGlobal = empRuntime.frameworkGlobal || ''\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n type: 'js',\n
|
|
1
|
+
{"version":3,"sources":["../src/plugins/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\nimport {getRuntimeLib} from './utils'\n//\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n if (o.name) {\n const op: any = store.deepAssign(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n delete op.empRuntime\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n const {empRuntime} = o\n if (empRuntime) {\n const injectHtml: any[] = []\n const framework = empRuntime.framework || 'react'\n const {frameworkLib, runtimeLib} = empRuntime\n //\n let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n const frameworkGlobal = empRuntime.frameworkGlobal || ''\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${frameworkGlobal}',runtimeLib:'${runtimeGlobal}',framework:'${framework}'}`,\n })\n }\n /**\n * frameworkLib & runtimeLib 的全局引用\n */\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n // type: 'js',\n // src: url,\n })\n }\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n //\n\n // store.chain.optimization.merge({\n // splitChunks: {\n // cacheGroups: {\n // moduleFederation: {\n // name: 'mfRuntime',\n // test: /[\\\\/]node_modules[\\\\/](@module-federation)[\\\\/]/,\n // priority: 0,\n // chunks: 'all',\n // },\n // },\n // },\n // })\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib') {\n runtimeGlobal = frameworkGlobal\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n if (injectHtml.length > 0) {\n store.injectTags(injectHtml, 'EMPShare')\n }\n /**\n * 设置 externals\n */\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n },\n }\n}\n\nexport default pluginRspackEmpShare\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAA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EAAc,WAAAC,CAAU,EAAIJ,EAE/BK,EAAgBL,EAAW,eAAiBM,EAC1CC,EAAkBP,EAAW,iBAAmB,GAatD,GAZ8BA,EAAW,wBAA0B,IAGjEC,EAAW,KAAK,CAEd,QAAS,SACT,UAAW,oCAAoCM,CAAe,iBAAiBF,CAAa,gBAAgBH,CAAS,IACvH,CAAC,EAKCC,EAAc,CAChB,IAAMK,EAAMC,EAAcN,EAAcL,EAAM,IAAI,EAClDG,EAAW,KAAK,CACd,WAAY,CACV,IAAKO,CACP,EACA,QAAS,QAGX,CAAC,CACH,CACKJ,EAmBIA,IAAe,kBACtBC,EAAgBE,EAGhBN,EAAW,KAAK,CAAC,QAAS,SAAU,IAAK,OAAQ,WAAY,CAAC,IAAKG,CAAU,CAAC,CAAC,EArB/EN,EAAM,MAAM,OAAO,4BAA4B,EAAE,IAAIY,EAAyB,CAACV,CAAU,CAAC,EAuBxFC,EAAW,OAAS,GACtBH,EAAM,WAAWG,EAAY,UAAU,EAKzC,IAAMU,EAAkB,CACtB,6BAA8B,YAC9B,yBAA0B,OAC5B,EACMC,EAAY,CAAC,EACnB,OAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQH,CAAe,EACvDC,EAAUC,CAAG,EAAI,GAAGR,CAAa,IAAIS,CAAK,GAE5C,GAAIZ,IAAc,SAAWK,EAAiB,CAC5C,IAAMQ,EAAgB,CACpB,MAAO,QACP,YAAa,UACf,EACA,OAAW,CAACF,EAAKC,CAAK,IAAK,OAAO,QAAQC,CAAa,EACrDH,EAAUC,CAAG,EAAI,GAAGN,CAAe,IAAIO,CAAK,EAEhD,CACId,EAAW,cAAcA,EAAW,aAAaY,CAAS,EAG9Dd,EAAM,MAAM,MAAM,CAAC,UAAAc,CAAS,CAAC,CAC/B,CACF,CACF,GAGKI,EAAQpB","names":["rspack_exports","__export","rspack_default","pluginRspackEmpShare","__toCommonJS","import_rspack","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","pluginRspackEmpShare","o","store","op","empRuntime","injectHtml","framework","frameworkLib","runtimeLib","runtimeGlobal","shareGlobalName","frameworkGlobal","url","getRuntimeLib","EmpShareRemoteLibPlugin","externalRuntime","externals","key","value","externalReact","rspack_default"]}
|
package/dist/rspack.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{ModuleFederationPlugin as E}from"@module-federation/enhanced/rspack";var f="EMP_SHARE_RUNTIME";var b=t=>`data:text/javascript,${t}`;var
|
|
2
|
-
`);return b(e)},m=class{options;constructor(e){this.options=e}apply(e){let{webpack:n}=e,{runtimeLib:
|
|
1
|
+
import{ModuleFederationPlugin as E}from"@module-federation/enhanced/rspack";var f="EMP_SHARE_RUNTIME";var b=t=>`data:text/javascript,${t}`;var g=t=>{let e=[`import '${t}'`].join(`
|
|
2
|
+
`);return b(e)},m=class{options;constructor(e){this.options=e}apply(e){let{webpack:n}=e,{runtimeLib:r}=this.options;if(!r){let i=g("@empjs/share/library");new n.EntryPlugin(e.context,i,{name:void 0}).apply(e)}}};function y(t,e){return typeof t=="string"?`${t}/runtime${e==="development"?".development":""}.umd.js`:typeof t=="object"?e==="development"?t.dev:t.prod:""}var h=(t={})=>({name:"@empjs/share",async rsConfig(e){if(t.name){let r=e.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},t);delete r.empRuntime,e.chain.plugin("plugin-emp-share").use(E,[r])}let{empRuntime:n}=t;if(n){let r=[],i=n.framework||"react",{frameworkLib:u,runtimeLib:p}=n,l=n.runtimeGlobal||f,s=n.frameworkGlobal||"";if(n.injectGlobalValToHtml!==!1&&r.push({tagName:"script",innerHTML:`EMPShareGlobalVal={frameworkLib:'${s}',runtimeLib:'${l}',framework:'${i}'}`}),u){let o=y(u,e.mode);r.push({attributes:{src:o},tagName:"script"})}p?p==="useFrameworkLib"?l=s:r.push({tagName:"script",pos:"head",attributes:{src:p}}):e.chain.plugin("plugin-emp-share-framework").use(m,[n]),r.length>0&&e.injectTags(r,"EMPShare");let d={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},a={};for(let[o,c]of Object.entries(d))a[o]=`${l}.${c}`;if(i==="react"&&s){let o={react:"React","react-dom":"ReactDOM"};for(let[c,R]of Object.entries(o))a[c]=`${s}.${R}`}n.setExternals&&n.setExternals(a),e.chain.merge({externals:a})}}}),T=h;export{T as default,h as pluginRspackEmpShare};
|
|
3
3
|
//# sourceMappingURL=rspack.js.map
|
package/dist/rspack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugins/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\nimport {getRuntimeLib} from './utils'\n//\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n if (o.name) {\n const op: any = store.deepAssign(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n delete op.empRuntime\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n const {empRuntime} = o\n if (empRuntime) {\n const injectHtml: any[] = []\n const framework = empRuntime.framework || 'react'\n const {frameworkLib, runtimeLib} = empRuntime\n //\n let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n const frameworkGlobal = empRuntime.frameworkGlobal || ''\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n type: 'js',\n
|
|
1
|
+
{"version":3,"sources":["../src/plugins/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\nimport {getRuntimeLib} from './utils'\n//\nexport const pluginRspackEmpShare = (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n if (o.name) {\n const op: any = store.deepAssign(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n delete op.empRuntime\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n const {empRuntime} = o\n if (empRuntime) {\n const injectHtml: any[] = []\n const framework = empRuntime.framework || 'react'\n const {frameworkLib, runtimeLib} = empRuntime\n //\n let runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n const frameworkGlobal = empRuntime.frameworkGlobal || ''\n const injectGlobalValToHtml = empRuntime.injectGlobalValToHtml === false ? false : true\n // 插入全局引用变量 让 empRuntime 可以提前实例化 不需要在页面重复实例化\n if (injectGlobalValToHtml) {\n injectHtml.push({\n // type: 'js',\n tagName: 'script',\n innerHTML: `EMPShareGlobalVal={frameworkLib:'${frameworkGlobal}',runtimeLib:'${runtimeGlobal}',framework:'${framework}'}`,\n })\n }\n /**\n * frameworkLib & runtimeLib 的全局引用\n */\n if (frameworkLib) {\n const url = getRuntimeLib(frameworkLib, store.mode)\n injectHtml.push({\n attributes: {\n src: url,\n },\n tagName: 'script',\n // type: 'js',\n // src: url,\n })\n }\n if (!runtimeLib) {\n // 内置 runtimeLib\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n //\n\n // store.chain.optimization.merge({\n // splitChunks: {\n // cacheGroups: {\n // moduleFederation: {\n // name: 'mfRuntime',\n // test: /[\\\\/]node_modules[\\\\/](@module-federation)[\\\\/]/,\n // priority: 0,\n // chunks: 'all',\n // },\n // },\n // },\n // })\n }\n // 统一封装到 frameworkLib\n else if (runtimeLib === 'useFrameworkLib') {\n runtimeGlobal = frameworkGlobal\n } else {\n // 插入 runtime\n injectHtml.push({tagName: 'script', pos: 'head', attributes: {src: runtimeLib}})\n }\n if (injectHtml.length > 0) {\n store.injectTags(injectHtml, 'EMPShare')\n }\n /**\n * 设置 externals\n */\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = {}\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${runtimeGlobal}.${value}`\n }\n if (framework === 'react' && frameworkGlobal) {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${frameworkGlobal}.${value}`\n }\n }\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n //\n // console.log('externals in plugin', externals)\n store.chain.merge({externals})\n }\n },\n }\n}\n\nexport default pluginRspackEmpShare\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n"],"mappings":"AACA,OAAQ,0BAAAA,MAA6B,qCCD9B,IAAMC,EAAkB,oBCAxB,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GCG9E,IAAMC,EAAuBC,GAAO,CAClC,IAAMC,EAAU,CAAC,WAAWD,CAAG,GAAG,EAAE,KAAK;AAAA,CAAI,EAC7C,OAAOE,EAAWD,CAAO,CAC3B,EACaE,EAAN,KAA8B,CACnC,QACA,YAAYC,EAA4B,CACtC,KAAK,QAAUA,CACjB,CACA,MAAMC,EAAoB,CACxB,GAAM,CAAC,QAAAC,CAAO,EAAID,EACZ,CAAC,WAAAE,CAAU,EAAI,KAAK,QAC1B,GAAI,CAACA,EAAY,CACf,IAAMC,EAAQT,EAAqB,sBAAsB,EACzD,IAAIO,EAAQ,YAAYD,EAAS,QAASG,EAAO,CAC/C,KAAM,MACR,CAAC,EAAE,MAAMH,CAAQ,CACnB,CACF,CACF,ECrBO,SAASI,EAAcC,EAA8CC,EAAc,CACxF,OAAI,OAAOD,GAAS,SAAiB,GAAGA,CAAI,WAAWC,IAAS,cAAgB,eAAiB,EAAE,UAC1F,OAAOD,GAAS,SACnBC,IAAS,cAAsBD,EAAK,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I,GAAGR,CAAa,IAAIS,CAAK,GAE5C,GAAIZ,IAAc,SAAWK,EAAiB,CAC5C,IAAMQ,EAAgB,CACpB,MAAO,QACP,YAAa,UACf,EACA,OAAW,CAACF,EAAKC,CAAK,IAAK,OAAO,QAAQC,CAAa,EACrDH,EAAUC,CAAG,EAAI,GAAGN,CAAe,IAAIO,CAAK,EAEhD,CACId,EAAW,cAAcA,EAAW,aAAaY,CAAS,EAG9Df,EAAM,MAAM,MAAM,CAAC,UAAAe,CAAS,CAAC,CAC/B,CACF,CACF,GAGKI,EAAQrB","names":["ModuleFederationPlugin","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","pluginRspackEmpShare","o","store","op","ModuleFederationPlugin","empRuntime","injectHtml","framework","frameworkLib","runtimeLib","runtimeGlobal","shareGlobalName","frameworkGlobal","url","getRuntimeLib","EmpShareRemoteLibPlugin","externalRuntime","externals","key","value","externalReact","rspack_default"]}
|