-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
154 lines (146 loc) · 3.71 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
// eslint-disable-next-line import/no-extraneous-dependencies
const TerserPlugin = require('terser-webpack-plugin');
const ENV = process.env.npm_lifecycle_event;
const isProd = ENV === 'build';
function setDMode() {
if (isProd) {
return 'production';
}
return 'development';
}
module.exports = {
mode: setDMode(),
devtool: 'source-map',
// https://webpack.js.org/concepts/entry-points/#multi-page-application
entry: {
shared: './src/js/sharedModules/share.js',
home: './src/js/home.js',
contacts: './src/js/contacts.js',
},
// how to write the compiled files to disk
// https://webpack.js.org/concepts/output/
output: {
filename: 'static/js/[name].js',
path: path.resolve(__dirname, 'dist'),
clean: true,
},
// https://webpack.js.org/concepts/loaders/
module: {
rules: [
{
test: /\.html$/i,
loader: 'html-loader',
options: {
esModule: false,
},
},
{
test: /\.s[ac]ss$/i,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '../../',
},
},
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
],
},
{
test: /\.(jpe?g|png|svg|gif)$/,
use: [
{
loader: 'file-loader',
options: {
outputPath: 'static/imgs',
name: '[name].[ext]',
esModule: false,
},
},
{
loader: 'image-webpack-loader',
options: {
bypassOnDebug: true,
mozjpeg: {
progressive: true,
quality: 75,
},
// optipng.enabled: false will disable optipng
optipng: {
enabled: false,
},
pngquant: {
quality: [0.65, 0.90],
speed: 4,
},
gifsicle: {
interlaced: false,
optimizationLevel: 1,
},
// the webp option will enable WEBP
webp: {
quality: 75,
},
},
},
],
},
// ????
// {
// // Load all images as base64 encoding if they are smaller than 4097 bytes
// test: /\.(png|jpe?g|gif|svg)$/i,
// use: [
// {
// loader: 'url-loader',
// options: {
// name: '[name].[hash:20].[ext]',
// esModule: false,
// limit: 4096
// }
// }
// ]
// }
],
},
// https://webpack.js.org/concepts/plugins/
plugins: [
new MiniCssExtractPlugin({
filename: 'static/css/[name].css',
}),
new HtmlWebpackPlugin({
template: './src/pages/contacts/index.html',
filename: './contacts/index.html',
inject: 'body',
chunks: ['shared', 'contacts'],
}),
new HtmlWebpackPlugin({
template: './src/pages/home/index.html',
filename: './home/index.html',
inject: 'body',
chunks: ['home', 'shared'],
}),
],
// https://webpack.js.org/configuration/optimization/
optimization: {
minimize: true,
minimizer: [
new TerserPlugin(),
new CssMinimizerPlugin(),
],
},
};