@empjs/share 3.3.1-beta.1 → 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/adapter.cjs +1 -1
- package/dist/adapter.cjs.map +1 -1
- package/dist/adapter.d.cts +2 -7
- package/dist/adapter.d.ts +2 -7
- package/dist/adapter.js +1 -1
- package/dist/adapter.js.map +1 -1
- 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 +38 -22
package/dist/adapter.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var
|
|
1
|
+
"use strict";var p=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var M=(t,e)=>{for(var o in e)p(t,o,{get:e[o],enumerable:!0})},x=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of P(e))!v.call(t,r)&&r!==o&&p(t,r,{get:()=>e[r],enumerable:!(n=E(e,r))||n.enumerable});return t};var S=t=>x(p({},"__esModule",{value:!0}),t);var O={};M(O,{default:()=>C,reactAdapter:()=>m});module.exports=S(O);var h=t=>t?Number(t.split(".")[0]):0,d=t=>t&&Object.prototype.toString.call(t)==="[object Promise]",A=!1,i=A?console.log.bind(console,"[EMP Share]"):()=>{};var y={},b=window;i("process.env.EMPSHARE_ENV","prod");var{EMPShareGlobalVal:l}=b||{};l&&l.frameworkLib&&(y=b[l.frameworkLib]);var u=class{libs={scope:"default",...y};constructor(e){e&&this.setup(e)}setup(e){e&&(typeof e=="string"&&(e=window[e]),this.libs={...this.libs,...e})}get shared(){let{React:e,ReactDOM:o,scope:n}=this.libs;return{react:{lib:()=>e,version:e.version,scope:n,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}},"react-dom":{lib:()=>o,version:o.version,scope:n,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}}}}adapter(e,o=this.libs.scope,n=this.libs.React,r=this.libs.ReactDOM){let a=h(n.version),R=this;class g extends n.Component{containerRef;root;constructor(s){super(s),this.containerRef=n.createRef()}componentDidMount(){i("componentDidMount"),this.mountOriginalComponent(!0)}componentDidUpdate(){i("componentDidUpdate"),this.mountOriginalComponent()}componentWillUnmount(){i("componentWillUnmount"),this.unMountOriginalComponent()}unMountOriginalComponent(){this.containerRef.current&&(a<18?r.unmountComponentAtNode(this.containerRef.current):this.root.unmount())}async mountOriginalComponent(s){d(e)&&(e=await e.then(c=>c[o]));let f=n.createElement(e,this.props);if(a<18)(s?r.render:r.hydrate)(f,this.containerRef.current),i("shouldRender16",s,a);else if(i("shouldRender18",s,a),s){let{createRoot:c}=R.libs;this.root=c(this.containerRef.current),this.root.render(f)}else this.root.render()}render(){return n.createElement("div",{ref:this.containerRef})}}return g}},m=new u;var C=m;0&&(module.exports={reactAdapter});
|
|
2
2
|
//# sourceMappingURL=adapter.cjs.map
|
package/dist/adapter.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapter/index.ts","../src/helper/index.ts","../src/adapter/react.tsx","../src/adapter/vue.ts"],"sourcesContent":["import reactAdapter from 'src/adapter/react'\nimport vueAdapter from 'src/adapter/vue'\nexport {reactAdapter, vueAdapter}\nexport default reactAdapter\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 {checkVersion, isPromise} from 'src/helper'\nimport type {EMPShareRuntimeAdapterReactType, InitOptionsType} from 'src/types'\nimport {log} from '../helper'\n//\nlet globalLib = {}\nconst win: any = window\n//\nlog('process.env.EMPSHARE_ENV', process.env.EMPSHARE_ENV)\n//\nconst {EMPShareGlobalVal} = win || {}\nif (EMPShareGlobalVal && EMPShareGlobalVal.frameworkLib) {\n globalLib = win[EMPShareGlobalVal.frameworkLib]\n}\n//\nexport class ReactAdapter {\n libs: EMPShareRuntimeAdapterReactType = {\n scope: 'default',\n ...globalLib,\n }\n constructor(op?: EMPShareRuntimeAdapterReactType) {\n if (op) this.setup(op)\n }\n public setup(o?: EMPShareRuntimeAdapterReactType | string) {\n if (o) {\n if (typeof o === 'string') o = window[o]\n this.libs = {...this.libs, ...(o as any)}\n }\n }\n get shared(): InitOptionsType['shared'] {\n const {React, ReactDOM, scope} = this.libs as EMPShareRuntimeAdapterReactType\n return {\n react: {\n lib: () => React,\n version: React.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n lib: () => ReactDOM,\n version: ReactDOM.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n }\n }\n adapter<P = any>(\n component: any,\n scope: string = this.libs.scope,\n React: any = this.libs.React,\n ReactDOM: any = this.libs.ReactDOM,\n ): P {\n const reactVersion = checkVersion(React.version)\n const self = this\n class WrappedComponent extends React.Component {\n public containerRef: any\n public root: any\n constructor(props: P) {\n super(props as any)\n this.containerRef = React.createRef()\n }\n\n componentDidMount() {\n log('componentDidMount')\n this.mountOriginalComponent(true)\n }\n\n componentDidUpdate() {\n log('componentDidUpdate')\n this.mountOriginalComponent()\n }\n\n componentWillUnmount() {\n log('componentWillUnmount')\n this.unMountOriginalComponent()\n }\n unMountOriginalComponent() {\n if (!this.containerRef.current) return\n if (reactVersion < 18) {\n ReactDOM.unmountComponentAtNode(this.containerRef.current)\n } else {\n this.root.unmount()\n }\n }\n async mountOriginalComponent(shouldRender?: boolean) {\n if (isPromise(component))\n component = await component.then((m: any) => {\n return m[scope]\n })\n const element = React.createElement(component, this.props)\n\n if (reactVersion < 18) {\n const Render = shouldRender ? ReactDOM.render : ReactDOM.hydrate\n Render(element, this.containerRef.current)\n log('shouldRender16', shouldRender, reactVersion)\n } else {\n log('shouldRender18', shouldRender, reactVersion)\n if (shouldRender) {\n const {createRoot} = self.libs\n this.root = createRoot(this.containerRef.current!)\n this.root.render(element)\n } else {\n // const {hydrateRoot} = self.libs\n // this.root = hydrateRoot(this.containerRef.current!, element)\n this.root.render()\n }\n }\n }\n\n render() {\n return <div ref={this.containerRef} />\n }\n }\n return WrappedComponent as any\n }\n}\n\nexport default new ReactAdapter()\n","const globalVue3Cache: any = {vue: {defineComponent: null, h: null, ref: null}, increaseId: Date.now()}\nconst win = window as any\nfunction bindSlotContext(target: any, context: any) {\n return Object.keys(target).map(key => {\n const vnode = target[key]\n vnode.context = context\n return vnode\n })\n}\n\nfunction vue2ToVue3(WrapperComponent: any, wrapperId: string): any {\n // console.log(`vue2ToVue3`, WrapperComponent, wrapperId);\n\n const Vue2 = win.EMP_ADAPTER_VUE.Vue\n let vm: any\n return {\n mounted() {\n const slots = this.$slots ? bindSlotContext(this.$slots, this.__self) : null\n vm = new Vue2({\n render: (createElement: any) => {\n return createElement(\n WrapperComponent,\n {\n on: this.$attrs,\n attrs: this.$attrs,\n props: this.$props,\n scopedSlots: this.$scopedSlots,\n },\n slots,\n )\n },\n })\n vm.$mount(`#${wrapperId}`)\n },\n props: WrapperComponent.props,\n render() {\n vm && vm.$forceUpdate()\n },\n }\n}\n\nconst initVue2InVue3Adapter = (vue: any) => {\n globalVue3Cache.vue = vue\n}\n// 创建组件\nconst Vue2InVue3Adapter = (() => {\n initVue2InVue3Adapter(win.Vue)\n const {defineComponent, h, ref} = globalVue3Cache.vue\n if (!(defineComponent && h && ref)) {\n console.warn('emp3 Vue2InVue3Adapter has not init')\n return () => {}\n }\n return defineComponent({\n // 声明props\n props: {\n mfComponent: {\n type: Function,\n required: true,\n },\n },\n setup() {\n const renderId = ref(globalVue3Cache.increaseId)\n globalVue3Cache.increaseId++\n return {\n renderId,\n }\n },\n render() {\n const {renderId} = this\n return h('div', [h('div', {id: `vue2-in-vue3${renderId}`})])\n },\n mounted() {\n ;(async () => {\n const fc = await this.mfComponent()\n vue2ToVue3(fc.default, `vue2-in-vue3${this.renderId}`).mounted()\n })()\n },\n })\n})()\n\nconst Vue3InVue2Adapter = () => {console.log('not implement')}\n\nexport default {Vue2InVue3Adapter, Vue3InVue2Adapter}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,iBAAAC,EAAA,eAAAC,IAAA,eAAAC,EAAAL,GCiBO,IAAMM,EAAgBC,GAAqBA,EAAU,OAAOA,EAAQ,MAAM,GAAG,EAAE,CAAC,CAAC,EAAI,EAC/EC,EAAaC,GAAWA,GAAK,OAAO,UAAU,SAAS,KAAKA,CAAC,IAAM,mBAGnEC,EAAQ,GACRC,EAAMD,EAAQ,QAAQ,IAAI,KAAK,QAAS,aAAa,EAAI,IAAM,CAAC,EClB7E,IAAIE,EAAY,CAAC,EACXC,EAAW,OAEjBC,EAAI,2BAA4B,MAAwB,EAExD,GAAM,CAAC,kBAAAC,CAAiB,EAAIF,GAAO,CAAC,EAChCE,GAAqBA,EAAkB,eACzCH,EAAYC,EAAIE,EAAkB,YAAY,GAGzC,IAAMC,EAAN,KAAmB,CACxB,KAAwC,CACtC,MAAO,UACP,GAAGJ,CACL,EACA,YAAYK,EAAsC,CAC5CA,GA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Aa,CAC1Cf,EAAgB,IAAMe,CACxB,EAEMC,GAAqB,IAAM,CAC/BF,EAAsBb,EAAI,GAAG,EAC7B,GAAM,CAAC,gBAAAgB,EAAiB,EAAAC,EAAG,IAAAC,CAAG,EAAInB,EAAgB,IAClD,OAAMiB,GAAmBC,GAAKC,EAIvBF,EAAgB,CAErB,MAAO,CACL,YAAa,CACX,KAAM,SACN,SAAU,EACZ,CACF,EACA,OAAQ,CACN,IAAMG,EAAWD,EAAInB,EAAgB,UAAU,EAC/C,OAAAA,EAAgB,aACT,CACL,SAAAoB,CACF,CACF,EACA,QAAS,CACP,GAAM,CAAC,SAAAA,CAAQ,EAAI,KACnB,OAAOF,EAAE,MAAO,CAACA,EAAE,MAAO,CAAC,GAAI,eAAeE,CAAQ,EAAE,CAAC,CAAC,CAAC,CAC7D,EACA,SAAU,EACN,SAAY,CACZ,IAAMC,EAAK,MAAM,KAAK,YAAY,EAClCd,EAAWc,EAAG,QAAS,eAAe,KAAK,QAAQ,EAAE,EAAE,QAAQ,CACjE,GAAG,CACL,CACF,CAAC,GA5BC,QAAQ,KAAK,qCAAqC,EAC3C,IAAM,CAAC,EA4BlB,GAAG,EAEGC,EAAoB,IAAM,CAAC,QAAQ,IAAI,eAAe,CAAC,EAEtDC,EAAQ,CAAC,kBAAAP,EAAmB,kBAAAM,CAAiB,EH/EpD,IAAOE,EAAQC","names":["adapter_exports","__export","adapter_default","react_default","vue_default","__toCommonJS","checkVersion","version","isPromise","p","isDev","log","globalLib","win","log","EMPShareGlobalVal","ReactAdapter","op","o","React","ReactDOM","scope","component","reactVersion","checkVersion","self","WrappedComponent","props","shouldRender","isPromise","m","element","createRoot","react_default","globalVue3Cache","win","bindSlotContext","target","context","key","vnode","vue2ToVue3","WrapperComponent","wrapperId","Vue2","vm","slots","createElement","initVue2InVue3Adapter","vue","Vue2InVue3Adapter","defineComponent","h","ref","renderId","fc","Vue3InVue2Adapter","vue_default","adapter_default","react_default"]}
|
|
1
|
+
{"version":3,"sources":["../src/adapter/index.ts","../src/helper/index.ts","../src/adapter/react.tsx"],"sourcesContent":["import reactAdapter from 'src/adapter/react'\n// import vueAdapter from 'src/adapter/vue'\nexport {reactAdapter}\nexport default reactAdapter\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 {checkVersion, isPromise} from 'src/helper'\nimport type {EMPShareRuntimeAdapterReactType, InitOptionsType} from 'src/types'\nimport {log} from '../helper'\n//\nlet globalLib = {}\nconst win: any = window\n//\nlog('process.env.EMPSHARE_ENV', process.env.EMPSHARE_ENV)\n//\nconst {EMPShareGlobalVal} = win || {}\nif (EMPShareGlobalVal && EMPShareGlobalVal.frameworkLib) {\n globalLib = win[EMPShareGlobalVal.frameworkLib]\n}\n//\nexport class ReactAdapter {\n libs: EMPShareRuntimeAdapterReactType = {\n scope: 'default',\n ...globalLib,\n }\n constructor(op?: EMPShareRuntimeAdapterReactType) {\n if (op) this.setup(op)\n }\n public setup(o?: EMPShareRuntimeAdapterReactType | string) {\n if (o) {\n if (typeof o === 'string') o = window[o]\n this.libs = {...this.libs, ...(o as any)}\n }\n }\n get shared(): InitOptionsType['shared'] {\n const {React, ReactDOM, scope} = this.libs as EMPShareRuntimeAdapterReactType\n return {\n react: {\n lib: () => React,\n version: React.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n lib: () => ReactDOM,\n version: ReactDOM.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n }\n }\n adapter<P = any>(\n component: any,\n scope: string = this.libs.scope,\n React: any = this.libs.React,\n ReactDOM: any = this.libs.ReactDOM,\n ): P {\n const reactVersion = checkVersion(React.version)\n const self = this\n class WrappedComponent extends React.Component {\n public containerRef: any\n public root: any\n constructor(props: P) {\n super(props as any)\n this.containerRef = React.createRef()\n }\n\n componentDidMount() {\n log('componentDidMount')\n this.mountOriginalComponent(true)\n }\n\n componentDidUpdate() {\n log('componentDidUpdate')\n this.mountOriginalComponent()\n }\n\n componentWillUnmount() {\n log('componentWillUnmount')\n this.unMountOriginalComponent()\n }\n unMountOriginalComponent() {\n if (!this.containerRef.current) return\n if (reactVersion < 18) {\n ReactDOM.unmountComponentAtNode(this.containerRef.current)\n } else {\n this.root.unmount()\n }\n }\n async mountOriginalComponent(shouldRender?: boolean) {\n if (isPromise(component))\n component = await component.then((m: any) => {\n return m[scope]\n })\n const element = React.createElement(component, this.props)\n\n if (reactVersion < 18) {\n const Render = shouldRender ? ReactDOM.render : ReactDOM.hydrate\n Render(element, this.containerRef.current)\n log('shouldRender16', shouldRender, reactVersion)\n } else {\n log('shouldRender18', shouldRender, reactVersion)\n if (shouldRender) {\n const {createRoot} = self.libs\n this.root = createRoot(this.containerRef.current!)\n this.root.render(element)\n } else {\n // const {hydrateRoot} = self.libs\n // this.root = hydrateRoot(this.containerRef.current!, element)\n this.root.render()\n }\n }\n }\n\n render() {\n return <div ref={this.containerRef} />\n }\n }\n return WrappedComponent as any\n }\n}\n\nexport default new ReactAdapter()\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,iBAAAC,IAAA,eAAAC,EAAAJ,GCiBO,IAAMK,EAAgBC,GAAqBA,EAAU,OAAOA,EAAQ,MAAM,GAAG,EAAE,CAAC,CAAC,EAAI,EAC/EC,EAAaC,GAAWA,GAAK,OAAO,UAAU,SAAS,KAAKA,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CAEA,oBAAqB,CACnBA,EAAI,oBAAoB,EACxB,KAAK,uBAAuB,CAC9B,CAEA,sBAAuB,CACrBA,EAAI,sBAAsB,EAC1B,KAAK,yBAAyB,CAChC,CACA,0BAA2B,CACpB,KAAK,aAAa,UACnBS,EAAe,GACjBH,EAAS,uBAAuB,KAAK,aAAa,OAAO,EAEzD,KAAK,KAAK,QAAQ,EAEtB,CACA,MAAM,uBAAuBQ,EAAwB,CAC/CC,EAAUP,CAAS,IACrBA,EAAY,MAAMA,EAAU,KAAMQ,GACzBA,EAAET,CAAK,CACf,GACH,IAAMU,EAAUZ,EAAM,cAAcG,EAAW,KAAK,KAAK,EAEzD,GAAIC,EAAe,IACFK,EAAeR,EAAS,OAASA,EAAS,SAClDW,EAAS,KAAK,aAAa,OAAO,EACzCjB,EAAI,iBAAkBc,EAAcL,CAAY,UAEhDT,EAAI,iBAAkBc,EAAcL,CAAY,EAC5CK,EAAc,CAChB,GAAM,CAAC,WAAAI,CAAU,EAAIP,EAAK,KAC1B,KAAK,KAAOO,EAAW,KAAK,aAAa,OAAQ,EACjD,KAAK,KAAK,OAAOD,CAAO,CAC1B,MAGE,KAAK,KAAK,OAAO,CAGvB,CAEA,QAAS,CACP,OAAOZ,EAAA,cAAC,OAAI,IAAK,KAAK,aAAc,CACtC,CACF,CACA,OAAOO,CACT,CACF,EAEOO,EAAQ,IAAIjB,EFvHnB,IAAOkB,EAAQC","names":["adapter_exports","__export","adapter_default","react_default","__toCommonJS","checkVersion","version","isPromise","p","isDev","log","globalLib","win","log","EMPShareGlobalVal","ReactAdapter","op","o","React","ReactDOM","scope","component","reactVersion","checkVersion","self","WrappedComponent","props","shouldRender","isPromise","m","element","createRoot","react_default","adapter_default","react_default"]}
|
package/dist/adapter.d.cts
CHANGED
|
@@ -9,11 +9,6 @@ declare class ReactAdapter {
|
|
|
9
9
|
get shared(): InitOptionsType['shared'];
|
|
10
10
|
adapter<P = any>(component: any, scope?: string, React?: any, ReactDOM?: any): P;
|
|
11
11
|
}
|
|
12
|
-
declare const _default
|
|
12
|
+
declare const _default: ReactAdapter;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
Vue2InVue3Adapter: any;
|
|
16
|
-
Vue3InVue2Adapter: () => void;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export { _default$1 as default, _default$1 as reactAdapter, _default as vueAdapter };
|
|
14
|
+
export { _default as default, _default as reactAdapter };
|
package/dist/adapter.d.ts
CHANGED
|
@@ -9,11 +9,6 @@ declare class ReactAdapter {
|
|
|
9
9
|
get shared(): InitOptionsType['shared'];
|
|
10
10
|
adapter<P = any>(component: any, scope?: string, React?: any, ReactDOM?: any): P;
|
|
11
11
|
}
|
|
12
|
-
declare const _default
|
|
12
|
+
declare const _default: ReactAdapter;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
Vue2InVue3Adapter: any;
|
|
16
|
-
Vue3InVue2Adapter: () => void;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export { _default$1 as default, _default$1 as reactAdapter, _default as vueAdapter };
|
|
14
|
+
export { _default as default, _default as reactAdapter };
|
package/dist/adapter.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var m=
|
|
1
|
+
var m=o=>o?Number(o.split(".")[0]):0,f=o=>o&&Object.prototype.toString.call(o)==="[object Promise]",g=!1,n=g?console.log.bind(console,"[EMP Share]"):()=>{};var h={},d=window;n("process.env.EMPSHARE_ENV","prod");var{EMPShareGlobalVal:p}=d||{};p&&p.frameworkLib&&(h=d[p.frameworkLib]);var l=class{libs={scope:"default",...h};constructor(e){e&&this.setup(e)}setup(e){e&&(typeof e=="string"&&(e=window[e]),this.libs={...this.libs,...e})}get shared(){let{React:e,ReactDOM:i,scope:t}=this.libs;return{react:{lib:()=>e,version:e.version,scope:t,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}},"react-dom":{lib:()=>i,version:i.version,scope:t,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}}}}adapter(e,i=this.libs.scope,t=this.libs.React,c=this.libs.ReactDOM){let s=m(t.version),b=this;class R extends t.Component{containerRef;root;constructor(r){super(r),this.containerRef=t.createRef()}componentDidMount(){n("componentDidMount"),this.mountOriginalComponent(!0)}componentDidUpdate(){n("componentDidUpdate"),this.mountOriginalComponent()}componentWillUnmount(){n("componentWillUnmount"),this.unMountOriginalComponent()}unMountOriginalComponent(){this.containerRef.current&&(s<18?c.unmountComponentAtNode(this.containerRef.current):this.root.unmount())}async mountOriginalComponent(r){f(e)&&(e=await e.then(a=>a[i]));let u=t.createElement(e,this.props);if(s<18)(r?c.render:c.hydrate)(u,this.containerRef.current),n("shouldRender16",r,s);else if(n("shouldRender18",r,s),r){let{createRoot:a}=b.libs;this.root=a(this.containerRef.current),this.root.render(u)}else this.root.render()}render(){return t.createElement("div",{ref:this.containerRef})}}return R}},y=new l;var A=y;export{A as default,y as reactAdapter};
|
|
2
2
|
//# sourceMappingURL=adapter.js.map
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/helper/index.ts","../src/adapter/react.tsx","../src/adapter/vue.ts","../src/adapter/index.ts"],"sourcesContent":["export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","import {checkVersion, isPromise} from 'src/helper'\nimport type {EMPShareRuntimeAdapterReactType, InitOptionsType} from 'src/types'\nimport {log} from '../helper'\n//\nlet globalLib = {}\nconst win: any = window\n//\nlog('process.env.EMPSHARE_ENV', process.env.EMPSHARE_ENV)\n//\nconst {EMPShareGlobalVal} = win || {}\nif (EMPShareGlobalVal && EMPShareGlobalVal.frameworkLib) {\n globalLib = win[EMPShareGlobalVal.frameworkLib]\n}\n//\nexport class ReactAdapter {\n libs: EMPShareRuntimeAdapterReactType = {\n scope: 'default',\n ...globalLib,\n }\n constructor(op?: EMPShareRuntimeAdapterReactType) {\n if (op) this.setup(op)\n }\n public setup(o?: EMPShareRuntimeAdapterReactType | string) {\n if (o) {\n if (typeof o === 'string') o = window[o]\n this.libs = {...this.libs, ...(o as any)}\n }\n }\n get shared(): InitOptionsType['shared'] {\n const {React, ReactDOM, scope} = this.libs as EMPShareRuntimeAdapterReactType\n return {\n react: {\n lib: () => React,\n version: React.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n lib: () => ReactDOM,\n version: ReactDOM.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n }\n }\n adapter<P = any>(\n component: any,\n scope: string = this.libs.scope,\n React: any = this.libs.React,\n ReactDOM: any = this.libs.ReactDOM,\n ): P {\n const reactVersion = checkVersion(React.version)\n const self = this\n class WrappedComponent extends React.Component {\n public containerRef: any\n public root: any\n constructor(props: P) {\n super(props as any)\n this.containerRef = React.createRef()\n }\n\n componentDidMount() {\n log('componentDidMount')\n this.mountOriginalComponent(true)\n }\n\n componentDidUpdate() {\n log('componentDidUpdate')\n this.mountOriginalComponent()\n }\n\n componentWillUnmount() {\n log('componentWillUnmount')\n this.unMountOriginalComponent()\n }\n unMountOriginalComponent() {\n if (!this.containerRef.current) return\n if (reactVersion < 18) {\n ReactDOM.unmountComponentAtNode(this.containerRef.current)\n } else {\n this.root.unmount()\n }\n }\n async mountOriginalComponent(shouldRender?: boolean) {\n if (isPromise(component))\n component = await component.then((m: any) => {\n return m[scope]\n })\n const element = React.createElement(component, this.props)\n\n if (reactVersion < 18) {\n const Render = shouldRender ? ReactDOM.render : ReactDOM.hydrate\n Render(element, this.containerRef.current)\n log('shouldRender16', shouldRender, reactVersion)\n } else {\n log('shouldRender18', shouldRender, reactVersion)\n if (shouldRender) {\n const {createRoot} = self.libs\n this.root = createRoot(this.containerRef.current!)\n this.root.render(element)\n } else {\n // const {hydrateRoot} = self.libs\n // this.root = hydrateRoot(this.containerRef.current!, element)\n this.root.render()\n }\n }\n }\n\n render() {\n return <div ref={this.containerRef} />\n }\n }\n return WrappedComponent as any\n }\n}\n\nexport default new ReactAdapter()\n","const globalVue3Cache: any = {vue: {defineComponent: null, h: null, ref: null}, increaseId: Date.now()}\nconst win = window as any\nfunction bindSlotContext(target: any, context: any) {\n return Object.keys(target).map(key => {\n const vnode = target[key]\n vnode.context = context\n return vnode\n })\n}\n\nfunction vue2ToVue3(WrapperComponent: any, wrapperId: string): any {\n // console.log(`vue2ToVue3`, WrapperComponent, wrapperId);\n\n const Vue2 = win.EMP_ADAPTER_VUE.Vue\n let vm: any\n return {\n mounted() {\n const slots = this.$slots ? bindSlotContext(this.$slots, this.__self) : null\n vm = new Vue2({\n render: (createElement: any) => {\n return createElement(\n WrapperComponent,\n {\n on: this.$attrs,\n attrs: this.$attrs,\n props: this.$props,\n scopedSlots: this.$scopedSlots,\n },\n slots,\n )\n },\n })\n vm.$mount(`#${wrapperId}`)\n },\n props: WrapperComponent.props,\n render() {\n vm && vm.$forceUpdate()\n },\n }\n}\n\nconst initVue2InVue3Adapter = (vue: any) => {\n globalVue3Cache.vue = vue\n}\n// 创建组件\nconst Vue2InVue3Adapter = (() => {\n initVue2InVue3Adapter(win.Vue)\n const {defineComponent, h, ref} = globalVue3Cache.vue\n if (!(defineComponent && h && ref)) {\n console.warn('emp3 Vue2InVue3Adapter has not init')\n return () => {}\n }\n return defineComponent({\n // 声明props\n props: {\n mfComponent: {\n type: Function,\n required: true,\n },\n },\n setup() {\n const renderId = ref(globalVue3Cache.increaseId)\n globalVue3Cache.increaseId++\n return {\n renderId,\n }\n },\n render() {\n const {renderId} = this\n return h('div', [h('div', {id: `vue2-in-vue3${renderId}`})])\n },\n mounted() {\n ;(async () => {\n const fc = await this.mfComponent()\n vue2ToVue3(fc.default, `vue2-in-vue3${this.renderId}`).mounted()\n })()\n },\n })\n})()\n\nconst Vue3InVue2Adapter = () => {console.log('not implement')}\n\nexport default {Vue2InVue3Adapter, Vue3InVue2Adapter}\n","import reactAdapter from 'src/adapter/react'\nimport vueAdapter from 'src/adapter/vue'\nexport {reactAdapter, vueAdapter}\nexport default reactAdapter\n"],"mappings":"AAiBO,IAAMA,EAAgBC,GAAqBA,EAAU,OAAOA,EAAQ,MAAM,GAAG,EAAE,CAAC,CAAC,EAAI,EAC/EC,EAAaC,GAAWA,GAAK,OAAO,UAAU,SAAS,KAAKA,CAAC,IAAM,mBAGnEC,EAAQ,GACRC,EAAMD,EAAQ,QAAQ,IAAI,KAAK,QAAS,aAAa,EAAI,IAAM,CAAC,EClB7E,IAAIE,EAAY,CAAC,EACXC,EAAW,OAEjBC,EAAI,2BAA4B,MAAwB,EAExD,GAAM,CAAC,kBAAAC,CAAiB,EAAIF,GAAO,CAAC,EAChCE,GAAqBA,EAAkB,eACzCH,EAAYC,EAAIE,EAAkB,YAAY,GAGzC,IAAMC,EAAN,KAAmB,CACxB,KAAwC,CACtC,MAAO,UACP,GAAGJ,CACL,EACA,YAAYK,EAAsC,CAC5CA,GAAI,KAAK,MAAMA,CAAE,CACvB,CACO,MAAMC,EAA8C,CACrDA,IACE,OAAOA,GAAM,WAAUA,EAAI,OAAOA,CAAC,GACvC,KAAK,KAAO,CAAC,GAAG,KAAK,KAAM,GAAIA,CAAS,EAE5C,CACA,IAAI,QAAoC,CACtC,GAAM,CAAC,MAAAC,EAAO,SAAAC,EAAU,MAAAC,CAAK,EAAI,KAAK,KACtC,MAAO,CACL,MAAO,CACL,IAAK,IAAMF,EACX,QAASA,EAAM,QACf,MAAAE,EACA,YAAa,CACX,UAAW,GACX,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AAoB,CACF,CACF,EACA,QAAS,CACP,GAAM,CAAC,SAAAA,CAAQ,EAAI,KACnB,OAAOF,EAAE,MAAO,CAACA,EAAE,MAAO,CAAC,GAAI,eAAeE,CAAQ,EAAE,CAAC,CAAC,CAAC,CAC7D,EACA,SAAU,EACN,SAAY,CACZ,IAAMC,EAAK,MAAM,KAAK,YAAY,EAClCd,EAAWc,EAAG,QAAS,eAAe,KAAK,QAAQ,EAAE,EAAE,QAAQ,CACjE,GAAG,CACL,CACF,CAAC,GA5BC,QAAQ,KAAK,qCAAqC,EAC3C,IAAM,CAAC,EA4BlB,GAAG,EAEGC,EAAoB,IAAM,CAAC,QAAQ,IAAI,eAAe,CAAC,EAEtDC,EAAQ,CAAC,kBAAAP,EAAmB,kBAAAM,CAAiB,EC/EpD,IAAOE,EAAQC","names":["checkVersion","version","isPromise","p","isDev","log","globalLib","win","log","EMPShareGlobalVal","ReactAdapter","op","o","React","ReactDOM","scope","component","reactVersion","checkVersion","self","WrappedComponent","props","shouldRender","isPromise","m","element","createRoot","react_default","globalVue3Cache","win","bindSlotContext","target","context","key","vnode","vue2ToVue3","WrapperComponent","wrapperId","Vue2","vm","slots","createElement","initVue2InVue3Adapter","vue","Vue2InVue3Adapter","defineComponent","h","ref","renderId","fc","Vue3InVue2Adapter","vue_default","adapter_default","react_default"]}
|
|
1
|
+
{"version":3,"sources":["../src/helper/index.ts","../src/adapter/react.tsx","../src/adapter/index.ts"],"sourcesContent":["export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n\n//\nexport const isDev = process.env.EMPSHARE_ENV === 'dev'\nexport const log = isDev ? console.log.bind(console, '[EMP Share]') : () => {}\n","import {checkVersion, isPromise} from 'src/helper'\nimport type {EMPShareRuntimeAdapterReactType, InitOptionsType} from 'src/types'\nimport {log} from '../helper'\n//\nlet globalLib = {}\nconst win: any = window\n//\nlog('process.env.EMPSHARE_ENV', process.env.EMPSHARE_ENV)\n//\nconst {EMPShareGlobalVal} = win || {}\nif (EMPShareGlobalVal && EMPShareGlobalVal.frameworkLib) {\n globalLib = win[EMPShareGlobalVal.frameworkLib]\n}\n//\nexport class ReactAdapter {\n libs: EMPShareRuntimeAdapterReactType = {\n scope: 'default',\n ...globalLib,\n }\n constructor(op?: EMPShareRuntimeAdapterReactType) {\n if (op) this.setup(op)\n }\n public setup(o?: EMPShareRuntimeAdapterReactType | string) {\n if (o) {\n if (typeof o === 'string') o = window[o]\n this.libs = {...this.libs, ...(o as any)}\n }\n }\n get shared(): InitOptionsType['shared'] {\n const {React, ReactDOM, scope} = this.libs as EMPShareRuntimeAdapterReactType\n return {\n react: {\n lib: () => React,\n version: React.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n lib: () => ReactDOM,\n version: ReactDOM.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n }\n }\n adapter<P = any>(\n component: any,\n scope: string = this.libs.scope,\n React: any = this.libs.React,\n ReactDOM: any = this.libs.ReactDOM,\n ): P {\n const reactVersion = checkVersion(React.version)\n const self = this\n class WrappedComponent extends React.Component {\n public containerRef: any\n public root: any\n constructor(props: P) {\n super(props as any)\n this.containerRef = React.createRef()\n }\n\n componentDidMount() {\n log('componentDidMount')\n this.mountOriginalComponent(true)\n }\n\n componentDidUpdate() {\n log('componentDidUpdate')\n this.mountOriginalComponent()\n }\n\n componentWillUnmount() {\n log('componentWillUnmount')\n this.unMountOriginalComponent()\n }\n unMountOriginalComponent() {\n if (!this.containerRef.current) return\n if (reactVersion < 18) {\n ReactDOM.unmountComponentAtNode(this.containerRef.current)\n } else {\n this.root.unmount()\n }\n }\n async mountOriginalComponent(shouldRender?: boolean) {\n if (isPromise(component))\n component = await component.then((m: any) => {\n return m[scope]\n })\n const element = React.createElement(component, this.props)\n\n if (reactVersion < 18) {\n const Render = shouldRender ? ReactDOM.render : ReactDOM.hydrate\n Render(element, this.containerRef.current)\n log('shouldRender16', shouldRender, reactVersion)\n } else {\n log('shouldRender18', shouldRender, reactVersion)\n if (shouldRender) {\n const {createRoot} = self.libs\n this.root = createRoot(this.containerRef.current!)\n this.root.render(element)\n } else {\n // const {hydrateRoot} = self.libs\n // this.root = hydrateRoot(this.containerRef.current!, element)\n this.root.render()\n }\n }\n }\n\n render() {\n return <div ref={this.containerRef} />\n }\n }\n return WrappedComponent as any\n }\n}\n\nexport default new ReactAdapter()\n","import reactAdapter from 'src/adapter/react'\n// import vueAdapter from 'src/adapter/vue'\nexport {reactAdapter}\nexport default reactAdapter\n"],"mappings":"AAiBO,IAAMA,EAAgBC,GAAqBA,EAAU,OAAOA,EAAQ,MAAM,GAAG,EAAE,CAAC,CAAC,EAAI,EAC/EC,EAAaC,GAAWA,GAAK,OAAO,UAAU,SAAS,KAAKA,CAAC,IAAM,mBAGnEC,EAAQ,GACRC,EAAMD,EAAQ,QAAQ,IAAI,KAAK,QAAS,aAAa,EAAI,IAAM,CAAC,EClB7E,IAAIE,EAAY,CAAC,EACXC,EAAW,OAEjBC,EAAI,2BAA4B,MAAwB,EAExD,GAAM,CAAC,kBAAAC,CAAiB,EAAIF,GAAO,CAAC,EAChCE,GAAqBA,EAAkB,eACzCH,EAAYC,EAAIE,EAAkB,YAAY,GAGzC,IAAMC,EAAN,KAAmB,CACxB,KAAwC,CACtC,MAAO,UACP,GAAGJ,CACL,EACA,YAAYK,EAAsC,CAC5CA,GAAI,KAAK,MAAMA,CAAE,CACvB,CACO,MAAMC,EAA8C,CACrDA,IACE,OAAOA,GAAM,WAAUA,EAAI,OAAO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,KAAK,aAAa,OAAO,EACzCjB,EAAI,iBAAkBc,EAAcL,CAAY,UAEhDT,EAAI,iBAAkBc,EAAcL,CAAY,EAC5CK,EAAc,CAChB,GAAM,CAAC,WAAAI,CAAU,EAAIP,EAAK,KAC1B,KAAK,KAAOO,EAAW,KAAK,aAAa,OAAQ,EACjD,KAAK,KAAK,OAAOD,CAAO,CAC1B,MAGE,KAAK,KAAK,OAAO,CAGvB,CAEA,QAAS,CACP,OAAOZ,EAAA,cAAC,OAAI,IAAK,KAAK,aAAc,CACtC,CACF,CACA,OAAOO,CACT,CACF,EAEOO,EAAQ,IAAIjB,ECvHnB,IAAOkB,EAAQC","names":["checkVersion","version","isPromise","p","isDev","log","globalLib","win","log","EMPShareGlobalVal","ReactAdapter","op","o","React","ReactDOM","scope","component","reactVersion","checkVersion","self","WrappedComponent","props","shouldRender","isPromise","m","element","createRoot","react_default","adapter_default","react_default"]}
|
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,EAA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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,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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AMgB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,EKjOO,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,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,C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EAAc,KAAO,OAErBA,EAAc,OAAS,GACvBA,EAAc,MAAQE,EACtBF,EAAc,KAAO,KAEzB,CACAhB,EAAa,KAAKgB,CAAa,EAC/BA,EAAgB,CAAC,CACnB,CAAC,EACQ,OAAON,GAAM,UAAYA,EAAE,QACpCM,EAAc,MAAQN,EAAE,MACxBM,EAAc,OAASN,EAAE,OACzBM,EAAc,KAAON,EAAE,KACvBV,EAAa,KAAKgB,CAAa,EAC/BA,EAAgB,CAAC,EAErB,CAEAhB,EAAa,IAAIU,GAAK,CAChBA,EAAE,OAAS,KACbhB,EAAW,KAAK,CACd,WAAY,CACV,IAAKgB,EAAE,KACT,EACA,QAAS,QACX,CAAC,EACQA,EAAE,OAAS,OACpBhB,EAAW,KAAK,CACd,WAAY,CACV,KAAMgB,EAAE,MACR,IAAK,YACP,EACA,QAAS,MACX,CAAC,CAEL,CAAC,CACH,CACF,CACF,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,CAA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AQ,GAEjD,IAAIE,EAASF,EAAGC,CAAK,EAC7B,MAAM,CACjB,CACF,GAEKE,EAAQJ,ECnBf,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"]}
|
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,EAA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AC3BD,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,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,S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,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
|