-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.mjs
110 lines (97 loc) · 2.14 KB
/
webpack.config.mjs
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
/*eslint-env node*/
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
import Dotenv from 'dotenv-webpack';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import path from 'path';
import TerserPlugin from 'terser-webpack-plugin';
import webpack from 'webpack';
const mode = process.env.NODE_ENV || 'development';
const devMode = mode === 'development';
const devtool = devMode ? 'source-map' : undefined;
const target = devMode ? 'web' : 'browserslist';
export default {
mode,
devtool,
target,
entry: './src/index.tsx',
output: {
filename: devMode ? '[name].js' : '[name].[contenthash].js',
path: path.resolve(path.dirname('./'), 'dist'),
clean: true,
assetModuleFilename: 'assets/[name][ext]',
},
devServer: {
static: './dist',
hot: true,
},
resolve: {
extensions: ['.js', '.jsx', '.tsx', '.ts'],
},
optimization: {
minimizer: [new CssMinimizerPlugin(), new TerserPlugin()],
},
watchOptions: {
ignored: /node_modules/,
},
module: {
rules: [
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.s?css$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
],
},
{
test: /\.html$/,
loader: 'html-loader',
},
{
test: /\.woff2?$/i,
type: 'asset/resource',
generator: {
filename: 'fonts/[name][ext]',
},
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(path.dirname('./'), 'public', 'index.html'),
minify: {
collapseWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
useShortDoctype: true,
},
}),
new MiniCssExtractPlugin({
filename: 'style.[contenthash].css',
}),
new webpack.ProvidePlugin({
React: 'react',
}),
new Dotenv({
path: './.env.local',
systemvars: true,
}),
new ForkTsCheckerWebpackPlugin({
typescript: {
diagnosticOptions: {
semantic: true,
syntactic: true,
},
},
}),
],
};