-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
82 lines (75 loc) · 1.99 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
77
78
79
80
81
82
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { ModuleFederationPlugin } = webpack.container;
// some webpack5/Node18 quirk, better than going with legacy openssl provider :shrug:
const crypto = require("crypto");
const crypto_orig_createHash = crypto.createHash;
crypto.createHash = algorithm => crypto_orig_createHash(algorithm == "md4" ? "sha256" : algorithm);
module.exports = {
entry: "./index.js",
mode: "development",
devtool: "source-map",
devServer: {
contentBase: path.join(__dirname, "dist"),
port: 1338
},
output: {
publicPath: "auto",
hashFunction: "sha256"
},
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`;
}