-
Notifications
You must be signed in to change notification settings - Fork 12
/
webpack.common.js
207 lines (205 loc) · 5.97 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const ESLintPlugin = require("eslint-webpack-plugin");
const { ProvidePlugin, DefinePlugin } = require("webpack");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
require("dotenv").config();
module.exports = {
entry: "./src/index.tsx",
mode: "development",
optimization: {
usedExports: true,
splitChunks: {
cacheGroups: {
source: {
test: /[\\/]src[\\/]/,
name: "source",
chunks: "all",
},
"vendor-react-redux": {
test: /[\\/]node_modules[\\/](react|react-dom|react-router|react-router-dom|react-redux|redux|redux-thunk|@reduxjs)[\\/]/,
name: "vendor-react-redux",
chunks: "all",
},
"vendor-stellar": {
test: /[\\/]node_modules[\\/](@stellar|stellar)[\\/]/,
name: "vendor-stellar",
chunks: "all",
},
"vendor-wallets": {
test: /[\\/]node_modules[\\/](@albedo|@ledgerhq|trezor)[\\/]/,
name: "vendor-wallets",
chunks: "all",
},
},
},
},
output: {
filename: "static/[name].[contenthash].js",
path: path.resolve(__dirname, "build"),
// This is needed to set correct path when refreshing on sub-pages (where
// path is not root)
publicPath: "/",
},
module: {
rules: [
{
test: /\.m?js$/,
resolve: {
fullySpecified: false,
},
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: "ts-loader",
options: {
// Disable type checker, we will use it in ForkTsCheckerWebpackPlugin
transpileOnly: true,
},
},
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: "babel-loader",
},
{
test: /\.(scss|css)$/,
use: [
process.env.NODE_ENV !== "production"
? "style-loader"
: MiniCssExtractPlugin.loader,
{
loader: "css-loader",
},
{
loader: "sass-loader",
options: {
sourceMap: true,
},
},
],
},
{
test: /\.(png|jpg|jpeg|gif)$/i,
type: "asset/resource",
},
{
test: /\.svg$/i,
exclude: /node_modules/,
use: [
{
loader: "@svgr/webpack",
options: {
svgoConfig: {
plugins: [
{
name: "removeViewBox",
active: false,
},
],
},
},
},
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "assets/",
},
},
],
},
],
},
resolve: {
alias: {
"react/jsx-dev-runtime.js": "react/jsx-dev-runtime",
"react/jsx-runtime.js": "react/jsx-runtime",
},
extensions: [".tsx", ".ts", ".js"],
plugins: [
// This handles aliases and resolves Design System CSS font paths properly
new TsconfigPathsPlugin({
configFile: path.resolve(__dirname, "./tsconfig.json"),
}),
],
// Adding node.js modules
fallback: {
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
assert: require.resolve("assert"),
http: require.resolve("stream-http"),
https: require.resolve("https-browserify"),
os: require.resolve("os-browserify"),
url: require.resolve("url"),
buffer: require.resolve("buffer/"),
path: require.resolve("path-browserify"),
},
},
plugins: [
new ProvidePlugin({
Buffer: ["buffer", "Buffer"],
process: "process/browser",
}),
new DefinePlugin({
"process.env": {
REACT_APP_DISABLE_WINDOW_ENV: JSON.stringify(
process.env.REACT_APP_DISABLE_WINDOW_ENV || "",
),
REACT_APP_API_URL: JSON.stringify(process.env.REACT_APP_API_URL || ""),
REACT_APP_STELLAR_EXPERT_URL: JSON.stringify(
process.env.REACT_APP_STELLAR_EXPERT_URL || "",
),
REACT_APP_HORIZON_URL: JSON.stringify(
process.env.REACT_APP_HORIZON_URL || "",
),
REACT_APP_RECAPTCHA_SITE_KEY: JSON.stringify(
process.env.REACT_APP_RECAPTCHA_SITE_KEY || "",
),
REACT_APP_SINGLE_TENANT_MODE:
process.env.REACT_APP_SINGLE_TENANT_MODE?.toLowerCase() === "true",
REACT_APP_USE_SSO:
process.env.REACT_APP_USE_SSO?.toLowerCase() === "true",
REACT_APP_OIDC_AUTHORITY: JSON.stringify(
process.env.REACT_APP_OIDC_AUTHORITY || "",
),
REACT_APP_OIDC_CLIENT_ID: JSON.stringify(
process.env.REACT_APP_OIDC_CLIENT_ID || "",
),
REACT_APP_OIDC_REDIRECT_URI: JSON.stringify(
process.env.REACT_APP_OIDC_REDIRECT_URI || "",
),
REACT_APP_OIDC_SCOPE: JSON.stringify(
process.env.REACT_APP_OIDC_SCOPE || "",
),
REACT_APP_OIDC_USERNAME_MAPPING: JSON.stringify(
process.env.REACT_APP_OIDC_USERNAME_MAPPING || "",
),
},
}),
new CopyPlugin({
patterns: [{ from: "./public", to: "./" }],
}),
new MiniCssExtractPlugin({
filename: "static/[name].[contenthash].css",
chunkFilename: "[id].css",
}),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: "./src/index.html",
}),
new ForkTsCheckerWebpackPlugin(),
new ESLintPlugin({
extensions: [".tsx", ".ts", ".js"],
exclude: "node_modules",
configType: "flat",
}),
],
};