-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnext.config.js
60 lines (58 loc) · 1.87 KB
/
next.config.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
const packageJsonDeps = require("./package.json").dependencies;
const { NodeModuleFederation } = require("@telenko/node-mf");
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const path = require("path");
module.exports = {
future: { webpack5: true },
webpack: (config, options) => {
const { buildId, dev, isServer, defaultLoaders, webpack } = options;
const mfConf = {
remotes: {
remoteLib: isServer
? "remoteLib@http://localhost:3002/node/remoteEntry.js"
//This is a hack (I cannot run successfully MF in client-side with NextJS and React, maybe doing smth wrong)
: {
external: `external new Promise((r, j) => {
window['remoteLib'].init({
react: {
"${packageJsonDeps.react}": {
get: () => Promise.resolve().then(() => () => globalThis.React),
}
}
});
r({
get: (request) => window['remoteLib'].get(request),
init: (args) => {}
});
})`
}
// : "remoteLib@http://localhost:3001/remoteEntry.js",
},
shared: {
react: {
eager: true,
requiredVersion: packageJsonDeps["react"],
singleton: true,
},
"react-dom": {
eager: true,
requiredVersion: packageJsonDeps["react-dom"],
singleton: true,
},
},
};
return {
...config,
plugins: [
...config.plugins,
new (isServer ? NodeModuleFederation : ModuleFederationPlugin)(mfConf),
],
experiments: { topLevelAwait: true },
};
},
webpackDevMiddleware: (config) => {
// Perform customizations to webpack dev middleware config
// Important: return the modified config
return config;
},
};