-
Notifications
You must be signed in to change notification settings - Fork 24
/
webpack.common.js
161 lines (160 loc) · 4.27 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
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 = require("webpack").ProvidePlugin;
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
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"),
},
module: {
rules: [
{
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|svg|jpg|jpeg|gif)$/i,
type: "asset/resource",
},
{
test: /\.svg$/i,
exclude: /node_modules/,
use: [
{
loader: "@svgr/webpack",
options: {
svgoConfig: {
plugins: {
removeViewBox: false,
},
},
},
},
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "assets/",
},
},
],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: "asset/resource",
generator: {
filename: "assets/fonts/[name].[ext]",
},
},
],
},
resolve: {
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/"),
},
},
plugins: [
// Buffer
new ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
new CopyPlugin({
patterns: [
{ from: "./public", to: "./" },
{ from: "./src/assets", to: "./assets" },
],
}),
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",
}),
],
};