# API-webpack
# wpm-plugin
// webpack.config.js
const WpmPlugin = require("wpm-plugin")
module.exports = {
plugins: [
new WpmPlugin({
env: "online" || "qa",
autoUpload: true,
systemRemotes: {
"@wemo-ui/klein": "@wemo-ui/klein@0.1.0"
},
shared: ["react", "react-dom"],
exposes: {
"./App": "./src/App"
}
})
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| 配置项 | 类型 | 默认值 | 作用 |
|---|---|---|---|
| env | function(){}:string | undefined | "qa" 或 "online" |
| autoUpload | bool | false | 打包完成后是否自动上传 |
| systemRemotes、mfRemotes、jsonRemotes | Object | {} | 使用WPM远程模块 (opens new window) |
| shared | object | {} | module-federation的shared (opens new window) |
| exposes | object | {} | module-federation的exposes |
| remotes | object | {} | module-federation的remotes, 一般使用systemRemotes |
WARNING
因为微盟B端微前端将script加载拦截为xhr, 所以如果你上传的包需要在微前端环境进行调试的话, 需要设置devServer的CORS跨域
// webpack.config.js
{
devServer:{
allowedHosts: 'all',
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
}
}
}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10