-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
108 lines (98 loc) · 2.68 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
import path from 'path';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import {CleanWebpackPlugin} from 'clean-webpack-plugin';
const JS_DIR = path.resolve('./src/js/pages');
const IMG_DIR = path.resolve('./src/img');
const BUILD_DIR = path.resolve('./assets');
const entry = {
admin: `${JS_DIR}/admin/admin.js`,
novel: `${JS_DIR}/novel/novel.tsx`,
post: `${JS_DIR}/post/post.js`,
page: `${JS_DIR}/page/page.js`,
library: `${JS_DIR}/library/library.js`,
blog: `${JS_DIR}/blog/blog.js`,
default: `${JS_DIR}/default.js`,
calendar: `${JS_DIR}/calendar/calendar.js`,
profile: `${JS_DIR}/profile/profile.tsx`,
add_data: `${JS_DIR}/add_data/add_data.js`,
reading_list: `${JS_DIR}/reading_list/reading_list`,
login: `${JS_DIR}/login/login.js`,
};
const output = {
path: BUILD_DIR,
filename: 'js/[name].js',
};
const rules = [
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'],
},
},
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{loader: 'css-loader', options: {
sourceMap: true,
}},
{loader: 'postcss-loader'},
{loader: 'sass-loader', options: {
sourceMap: true,
}},
],
},
{
test: /\.(png|jpg|svg|jpeg|gif|ICO)$/,
type: 'asset/resource',
generator: {
filename: 'img/[hash][ext][query]',
},
},
{
test: /\.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
exclude: [IMG_DIR, /node_modules/],
type: 'asset/resource',
generator: {
filename: 'font/[hash][ext][query]',
},
},
];
const plugins = (argv) => [
new CleanWebpackPlugin({
cleanStaleWebpackAssets: 'production' === argv.mode,
}),
new MiniCssExtractPlugin({
filename: 'css/[name].css',
}),
];
export default (env, argv) => ({
entry,
output,
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
module: {
rules,
},
optimization: {
minimize: argv.mode === 'production',
minimizer: [
new CssMinimizerPlugin({
parallel: true,
}),
new TerserPlugin(),
],
},
plugins: plugins(argv),
externals: {
jquery: 'jQuery',
},
});