forked from TradeTrust/tradetrust-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
158 lines (154 loc) · 4.4 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
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
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CompressionPlugin = require("compression-webpack-plugin");
const BrotliPlugin = require("brotli-webpack-plugin");
const path = require("path");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const Mode = require("frontmatter-markdown-loader/mode");
const { IS_DEVELOPMENT, IS_TEST_ENV, IS_DEV_SERVER, GA_MEASUREMENT_ID, GA_CONFIG_OPTION } = require("./src/config");
module.exports = {
resolve: {
alias: {
process: "process/browser",
},
fallback: {
vm: require.resolve("vm-browserify"),
stream: require.resolve("stream-browserify"),
os: require.resolve("os-browserify/browser"),
crypto: require.resolve("crypto-browserify"),
path: require.resolve("path-browserify"),
buffer: require.resolve("buffer"),
},
extensions: [".js", ".ts", ".tsx"],
modules: ["node_modules", path.resolve(__dirname, "src")],
alias: {
react: path.resolve("./node_modules/react"),
},
},
entry: {
app: ["./src/index.tsx"],
},
context: path.resolve(__dirname),
mode: IS_DEVELOPMENT ? "development" : "production",
target: "web",
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].[hash:7].js",
publicPath: "/",
},
module: {
rules: [
{
test: /\.m?js$/,
resolve: {
fullySpecified: false,
},
},
{
test: /\.js$/,
include: [path.resolve(__dirname, "tests")], // Specify the directory where your test files reside
use: {
loader: "babel-loader",
},
},
{
test: /\.(ts|js)x?$/,
include: [path.resolve(__dirname, "src"), path.resolve(__dirname, "node_modules/web-did-resolver")],
use: {
loader: "babel-loader",
},
},
{
test: /\.css$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader", options: { url: false } },
{ loader: "postcss-loader" },
],
},
{
test: /\.md$/,
loader: "frontmatter-markdown-loader",
options: {
mode: [Mode.BODY],
},
},
],
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
new webpack.ProvidePlugin({
os: "os-browserify/browser",
}),
new webpack.ProvidePlugin({
process: "process/browser",
}),
new webpack.IgnorePlugin({
resourceRegExp: /magic-sdk$/, // Adjust the regular expression as needed
}), // HOT FIX (Temp removal of magic demo until we might decide to kill it)
new webpack.EnvironmentPlugin({
// need to define variables here, so later can be overwritten at netlify env var end
// TODO: use dotenv instead
NODE_ENV: "development",
NET: "sepolia",
INFURA_API_KEY: "bb46da3f80e040e8ab73c0a9ff365d18",
}),
new HtmlWebpackPlugin({
filename: "index.html",
template: `${__dirname}/public/static/index.html`,
GA_MEASUREMENT_ID,
GA_CONFIG_OPTION,
}),
...(!IS_DEV_SERVER
? [
new CompressionPlugin({ test: /\.(js|css|html|svg)$/ }),
new BrotliPlugin({ test: /\.(js|css|html|svg)$/ }),
new CopyWebpackPlugin({
patterns: [
{ from: "public/static/common", to: "static/common" },
{ from: "public/static/images", to: "static/images" },
{ from: "public/static/demo", to: "static/demo" },
{ from: "public/static/sitemap.xml", to: "sitemap.xml" },
{ from: "public/static/robots.txt", to: "robots.txt" },
{ from: "public/imd@", to: "imd@" },
],
}),
]
: []),
],
optimization: {
splitChunks: {
cacheGroups: {
defaultVendors: {
test: /\/node_modules\//,
name: "vendor",
chunks: "all",
},
},
},
},
// Using cheap-eval-source-map for build times
// switch to inline-source-map if detailed debugging needed
devtool: !IS_DEVELOPMENT || IS_TEST_ENV ? false : "eval-cheap-source-map",
devServer: {
client: {
overlay: {
errors: true,
warnings: false,
},
},
compress: true,
static: {
directory: path.join(__dirname, "public"),
},
historyApiFallback: true,
hot: true,
port: 3000,
},
stats: {
colors: true,
},
bail: true,
};