v3.1.4
版本后,使用 RspackEmpSharePlugin代替empShare
配置。
基于 module federation
进行二次封装开发、适配更多业务模型
目前支持 基本 module federation
的共享方式、基于cdn的共享方式以及ESM的共享方式
import {defineConfig} from '@empjs/cli'
export default defineConfig(({mode, env}) => {
return {
empShare: {
name: 'unpkglib',
exposes: {
'./App': './src/App',
},
shared: {
react: {singleton: true},
'react-dom': {singleton: true},
},
},
}
})
基于 module federation v2
进行二次封装开发、目前EMP最优的共享模式
import {defineConfig} from '@empjs/cli'
export default defineConfig(({mode, env}) => {
return {
empShare: {
fastMode: {
runtimeHost:'二次封装库、包含基础库、sdk等',
framework: 'react',
},
name: 'unpkglib',
exposes: {
'./App': './src/App',
},
shared: {
react: {singleton: true},
'react-dom': {singleton: true},
},
},
}
})
import {defineConfig} from '@empjs/cli'
export default defineConfig((store) => {
//
const shareLib =
store.mode === 'development'
? {
react: 'React@https://cdn.jsdelivr.net/npm/[email protected]/umd/react.development.min.js',
'react-dom': 'ReactDOM@https://cdn.jsdelivr.net/npm/[email protected]/umd/react-dom.development.js',
}
: {
react: 'React@https://cdn.jsdelivr.net/npm/[email protected]/umd/react.production.min.js',
'react-dom': 'ReactDOM@https://cdn.jsdelivr.net/npm/[email protected]/umd/react-dom.production.min.js',
}
//
return {
empShare: {
name: 'unpkglib',
exposes: {
'./App': './src/App',
},
shareLib,
},
}
})
import {defineConfig} from '@empjs/cli'
export default defineConfig(store => {
return {
build : {
target:'es2015',
},
empShare: {
name: 'unpkglib',
exposes: {
'./App': './src/App',
},
shareLib: {
react: `https://esm.sh/[email protected]${store.mode === 'development' ? '?dev' : ''}`,
'react-dom': `https://esm.sh/[email protected]${store.mode === 'development' ? '?dev' : ''}`,
'react/jsx-dev-runtime': 'https://esm.sh/react/jsx-dev-runtime.js',
'react/jsx-runtime': 'https://esm.sh/react/jsx-runtime.js',
},
//是否开启 importMap
useImportMap:true,
},
}
})