-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
125 lines (122 loc) · 3.56 KB
/
webpack.common.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const path = require("path");
const DotenvPlugin = require("dotenv-webpack");
const HTMLWebpackPlugin = require("html-webpack-plugin");
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
const { ModuleFederationPlugin } = require("webpack").container;
const ESLintPlugin = require("eslint-webpack-plugin");
const DOTENV = require("dotenv");
const ESLintConfig = require("./.eslintrc.js");
const { dependencies } = require("./package.json");
module.exports = (env) => {
const NODE_ENV = env.NODE_ENV || "local";
const isDevelopment = NODE_ENV !== "production";
const dotenvPath = `./.env${isDevelopment ? "" : `.${env.NODE_ENV}`}`;
const { parsed: currentDotenv } = DOTENV.config({ path: dotenvPath });
process.stdout.write(
`${"\n\n***-------------------------------------------***\n"}
BUILD start for environment: ${NODE_ENV}
${"\n***-------------------------------------------***\n\n\n"}`
);
return {
entry: "./src",
module: {
rules: [
{
test: /\.[tj]s(x?)$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
presets: [
"@babel/preset-env",
[
"@babel/preset-react",
{
runtime: "automatic",
},
],
"@babel/preset-typescript",
],
plugins: [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime",
isDevelopment && require.resolve("react-refresh/babel"),
].filter(Boolean),
},
},
],
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
{
test: /\.(png|woff|woff2|eot|ttf)$/,
use: "url-loader",
},
{
test: /\.svg$/i,
type: "asset",
resourceQuery: /url/,
},
{
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
resourceQuery: { not: [/url/] },
use: ["@svgr/webpack"],
},
],
},
resolve: {
extensions: [".ts", ".tsx", ".js"],
alias: {
"@utils": path.resolve(__dirname, "./src/utils"),
},
},
plugins: [
new ModuleFederationPlugin({
name: "mf_portal",
filename: "remoteEntry.js",
exposes: {
"./App": "./src/App.tsx",
},
remotes: {
mf: `mf_portal@${currentDotenv.MF_URL}/remoteEntry.js`,
},
shared: {
...dependencies,
"react-dom": {
requiredVersion: dependencies["react-dom"],
singleton: true,
eager: true,
},
react: {
requiredVersion: dependencies.react,
singleton: true,
eager: true,
},
},
}),
new ESLintPlugin({
extensions: ["ts", "js", "tsx"],
formatter: "pretty",
overrideConfig: { ...ESLintConfig },
quiet: true,
}),
new DotenvPlugin({
path: `./.env${isDevelopment ? "" : `.${env.NODE_ENV}`}`,
systemvars: true,
safe: !(env && env.NODE_ENV),
}),
new HTMLWebpackPlugin({
template: "./public/template.html",
publicPath: "/",
}),
isDevelopment &&
new ReactRefreshWebpackPlugin({
exclude: [/node_modules/, /bootstrap\.js$/],
}),
].filter(Boolean),
};
};