forked from FirstWhack/Module-Federation-MobX-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
76 lines (70 loc) · 1.7 KB
/
webpack.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { ModuleFederationPlugin } = webpack.container;
module.exports = {
entry: "./index.js",
mode: "development",
devtool: "source-map",
devServer: {
contentBase: path.join(__dirname, "dist"),
port: 1338
},
output: {
publicPath: "auto"
},
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/
},
{
test: /\.jsx?$/,
loader: "babel-loader",
exclude: /node_modules/,
options: {
presets: ["@babel/preset-react"]
}
}
]
},
resolve: {
extensions: [".tsx", ".ts", ".js", ".jsx"]
},
plugins: [
new ModuleFederationPlugin({
name: "app2",
filename: "remoteEntry.js",
exposes: {
"./Users": "./app"
},
remotes: {
store: `store@${getRemoteEntryUrl(1339)}`
},
shared: [
{
react: { singleton: true, eager: true },
"react-dom": { singleton: true, eager: true },
mobx: { eager: true },
"mobx-react": { eager: true }
}
]
}),
new HtmlWebpackPlugin({
template: "./index.html"
})
]
};
function getRemoteEntryUrl(port) {
const { CODESANDBOX_SSE, HOSTNAME = "" } = process.env;
// Check if the example is running on codesandbox
// https://codesandbox.io/docs/environment
if (!CODESANDBOX_SSE) {
return `//localhost:${port}/remoteEntry.js`;
}
const parts = HOSTNAME.split("-");
const codesandboxId = parts[parts.length - 1];
return `//${codesandboxId}-${port}.sse.codesandbox.io/remoteEntry.js`;
}