forked from TradeTrust/tradetrust-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
119 lines (115 loc) · 3.47 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
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CompressionPlugin = require("compression-webpack-plugin");
const BrotliPlugin = require("brotli-webpack-plugin");
const webpack = require("webpack");
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 = {
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: /\.(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.IgnorePlugin(/magic-sdk$/), // 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/uploads", to: "static/uploads" },
{ from: "public/static/sitemap.xml", to: "sitemap.xml" },
{ from: "public/static/robots.txt", to: "robots.txt" },
{ from: "public/imd@", to: "imd@" },
],
}),
]
: []),
],
optimization: {
splitChunks: {
cacheGroups: {
vendors: {
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: {
compress: true,
contentBase: path.join(__dirname, "public"),
disableHostCheck: true,
historyApiFallback: true,
hot: true,
inline: true,
port: 3000,
stats: {
colors: true,
progress: true,
},
},
resolve: {
extensions: [".js", ".ts", ".tsx"],
modules: ["node_modules", path.resolve(__dirname, "src")],
alias: {
react: path.resolve("./node_modules/react"),
},
},
bail: true,
};