-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
66 lines (56 loc) · 1.93 KB
/
index.js
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
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const paths = require("react-scripts/config/paths");
const getModuleFederationConfigPath = (additionalPaths = []) => {
const path = require("node:path");
const fs = require("node:fs");
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath);
const moduleFederationConfigFiles = [
"modulefederation.config.js",
...additionalPaths,
];
return moduleFederationConfigFiles
.map(resolveApp)
.filter(fs.existsSync)
.shift();
};
module.exports = {
overrideWebpackConfig: ({ webpackConfig, pluginOptions }) => {
const moduleFederationConfigPath = getModuleFederationConfigPath();
if (moduleFederationConfigPath) {
webpackConfig.output.publicPath = "auto";
if (pluginOptions?.useNamedChunkIds) {
webpackConfig.optimization.chunkIds = "named";
}
const htmlWebpackPlugin = webpackConfig.plugins.find(
(plugin) => plugin.constructor.name === "HtmlWebpackPlugin"
);
htmlWebpackPlugin.userOptions = {
...htmlWebpackPlugin.userOptions,
publicPath: paths.publicUrlOrPath,
excludeChunks: [require(moduleFederationConfigPath).name],
};
webpackConfig.plugins = [
...webpackConfig.plugins,
new ModuleFederationPlugin(require(moduleFederationConfigPath)),
];
// webpackConfig.module = {
// ...webpackConfig.module,
// generator: {
// "asset/resource": {
// publicPath: paths.publicUrlOrPath,
// },
// },
// };
}
return webpackConfig;
},
overrideDevServerConfig: ({ devServerConfig }) => {
devServerConfig.headers = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Headers": "*",
};
return devServerConfig;
},
};