-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
138 lines (135 loc) · 3.58 KB
/
webpack.config.ts
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
import path from "path";
import {
Configuration as WebpackConfiguration,
HotModuleReplacementPlugin,
DefinePlugin
} from "webpack";
import { Configuration as WebpackDevServerConfiguration } from "webpack-dev-server";
import Dotenv from "dotenv-webpack";
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import TerserPlugin from "terser-webpack-plugin";
interface Configuration extends WebpackConfiguration {
devServer?: WebpackDevServerConfiguration;
}
const common: Configuration = {
entry: "./src/index.tsx",
mode: process.env.NODE_ENV === "production" ? "production" : "development",
devtool: process.env.NODE_ENV !== "production" ? "inline-source-map" : "source-map",
target: "web",
output: {
path: path.resolve(__dirname, "public"),
filename: "bundle.js",
},
watchOptions: {
ignored: "/node_modules/",
},
stats: {
colors: true,
},
resolve: {
extensions: [".*", ".js", ".jsx", ".ts", ".tsx"],
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
comparisons: false,
},
mangle: {
safari10: true,
},
output: {
comments: false,
ascii_only: true,
},
},
}),
],
},
devServer: {
compress: true,
hot: true,
port: process.env.UI_PORT || 8080,
https: true,
historyApiFallback: true,
liveReload: true,
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
exclude: /(node_modules|bower_components)/,
presets: [
"@babel/preset-env",
["@babel/preset-react", { "targets": "current node" }],
"@babel/preset-typescript",
],
envName: process.env.NODE_ENV === "production" ? "production" : "development",
plugins: [
"@babel/plugin-syntax-jsx",
["@babel/plugin-transform-runtime", { "useESModules": true, "regenerator": false }]
]
},
},
},
{
test: /\.(jp(e*)g|png|gif|svg|webp)$/i,
use: [
{
loader: "file-loader",
options: {
limit: 10000,
name: "assets/img/[hash]-[name].[ext]",
esModule: false,
},
},
],
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
use: ["svg-url-loader", "babel-loader", "@svgr/webpack", "url-loader", "file-loader"],
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader", "postcss-loader"],
},
{
test: /\.(eot|otf|ttf|woff|woff2)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "file-loader",
},
],
},
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin(),
new HotModuleReplacementPlugin(),
new DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(
process.env.NODE_ENV === "production" ? "production" : "development"
),
}),
new Dotenv({
path: path.resolve(__dirname, "./.env.local"),
}),
new HtmlWebpackPlugin({
title: "CTA Tracker",
template: "./src/index.html",
filename: "./index.html",
inject: "body",
hash: true, // Cache busting
minify: {
removeComments: true,
collapseWhitespace: true,
},
}),
],
};
export default common;