-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemp-config.js
More file actions
88 lines (80 loc) · 1.96 KB
/
emp-config.js
File metadata and controls
88 lines (80 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const path = require('path')
const packagePath = path.join(path.resolve('./'), 'package.json')
const {dependencies} = require(packagePath)
const port = 8001
module.exports = {
/**
* Webpack 配置入口
* @param {*} param0
* @returns
*/
webpack({webpackEnv, config}) {
console.log('webpack', webpackEnv)
// 配置 index.html
config.plugin('html').tap(args => {
args[0] = {
...args[0],
...{
// head 的 title
title: 'EMP-Base-Project',
// 远程调用项目的文件链接
files: {},
},
}
return args
})
return {
devServer: {
port: port,
},
}
},
/**
* 打包相对路径配置
*/
moduleGenerator({webpackEnv}) {
console.log('moduleGenerator', webpackEnv)
return webpackEnv === 'development' ? '/' : `http://localhost:8001/`
},
/**
* moduleFederation 配置
*/
moduleFederation: {
/**
* 项目名
*/
name: 'empReactBase',
/**
* 当前暴露模块索引文件
*/
filename: 'emp.js',
/**
* 引入远程模块入口
* "本项目引用模块命名空间":"远程模块项目名@项目地址"
*/
remotes: {
'@emp/react-project': `empReactProject@http://localhost:8002/emp.js`,
},
/**
* 暴露可以调用模块
* "被远程引用时的路径":"本项目相对路径"
*/
exposes: {
'./configs/index': 'src/configs/index',
'./components/Demo': 'src/components/Demo',
'./components/Hello': 'src/components/Hello',
},
/**
* 共享 lib
*/
/* shared: {
react: {singleton: true, requiredVersion: false},
'react-dom': {singleton: true, requiredVersion: false},
}, */
/* shared: {
react: {requiredVersion: '^17.0.1'},
'react-dom': {requiredVersion: '^17.0.1'},
}, */
// shared: Object.assign({}, shareByVersion('react'), shareByVersion('react-dom')),
},
}