-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
131 lines (126 loc) · 3.52 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
import path from "path";
import { Configuration } from "webpack";
import HtmlWebpackPlugin from "html-webpack-plugin";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
import type { Configuration as DevServerConfiguration } from "webpack-dev-server";
import CopyPlugin from "copy-webpack-plugin";
import ESLintPlugin from "eslint-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import ImageMinimizerPlugin from "image-minimizer-webpack-plugin";
import CompressionPlugin from "compression-webpack-plugin";
import * as dotenv from "dotenv";
import webpack from "webpack";
dotenv.config();
const isProduction = process.env.NODE_ENV === "production";
const devServer: DevServerConfiguration = {
historyApiFallback: true,
open: true,
port: 3000,
};
const config: Configuration = {
mode: isProduction ? "production" : "development",
output: {
path: path.resolve(__dirname, "build"),
filename: "static/js/main.[contenthash].js",
clean: true,
assetModuleFilename: "static/media/[name].[contenthash][ext]",
},
entry: path.resolve(__dirname, "src/index.tsx"),
devtool: "source-map",
devServer,
module: {
rules: [
{
test: /\.(ts|js)x?$/i,
exclude: /node_modules/,
use: "babel-loader",
},
{
test: /\.(s(a|c)ss|css)$/i,
exclude: /node_modules/,
use: [
isProduction ? MiniCssExtractPlugin.loader : "style-loader",
"css-loader",
"postcss-loader",
"sass-loader",
],
},
{
test: /\.(svg|png|jpg|jpeg|gif)$/i,
exclude: /node_modules/,
type: "asset",
parser: {
dataUrlCondition: {
maxSize: 10 * 1024,
},
},
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
exclude: /node_modules/,
type: "asset/inline",
},
],
},
resolve: {
extensions: [".tsx", ".ts", "jsx", ".js"],
},
plugins: [
new HtmlWebpackPlugin({
filename: "./index.html",
template: "./public/index.html",
}),
new CopyPlugin({
patterns: [
{ from: "./public/manifest.json", to: "./" },
{ from: "./public/robots.txt", to: "./" },
{ from: "./public/logo192.png", to: "./" },
{ from: "./public/logo512.png", to: "./" },
],
}),
new webpack.DefinePlugin({
"process.env": JSON.stringify(process.env),
}),
new ESLintPlugin({
extensions: ["js", "jsx", "ts", "tsx"],
}),
...(!isProduction
? [
new ForkTsCheckerWebpackPlugin({
async: false,
}),
]
: []),
...(isProduction
? [
new MiniCssExtractPlugin({
filename: "static/css/main.[contenthash].css",
}),
new ImageMinimizerPlugin({
minimizer: {
implementation: ImageMinimizerPlugin.imageminMinify,
options: {
plugins: [
["gifsicle", { interlaced: true }],
["jpegtran", { progressive: true }],
["optipng", { optimizationLevel: 5 }],
[
"svgo",
{
multipass: true,
plugins: ["preset-default"],
},
],
],
},
},
}),
new CompressionPlugin({
algorithm: "gzip",
threshold: 1 * 1024,
}),
]
: []),
],
};
export default config;