-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
111 lines (104 loc) · 2.61 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
const PugPlugin = require("pug-plugin");
const FileManagerPlugin = require("filemanager-webpack-plugin");
const ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");
const path = require("path");
module.exports = {
entry: {
index: path.join(__dirname, "src", "index.pug"),
},
output: {
path: path.join(__dirname, "dist"),
assetModuleFilename: path.join(
"assets",
"images",
"[name].[contenthash][ext]"
),
},
module: {
rules: [
{
test: /\.js$/,
use: "babel-loader",
exclude: /node_modules/,
},
{
test: /\.pug$/,
loader: PugPlugin.loader,
},
{
test: /\.(scss|css)$/,
// Webpack reads this list from right to left
// sass-loader - traspiles sass to valid css
// postcss-loader - makes use of it's preset-env plugin to make css compatible with other browsers
// css-loader - interprets all @import and url() statements
use: ["css-loader", "postcss-loader", "sass-loader"],
},
{
test: /\.(png|jpg|jpeg|gif)$/i,
type: "asset/resource",
},
{
test: /\.svg$/,
type: "asset/resource",
generator: {
filename: path.join("icons", "[name].[contenthash][ext]"),
},
},
{
test: /\.(woff2?|eot|ttf|otf)$/i,
type: "asset/resource",
generator: {
filename: path.join("fonts", "[name].[contenthash][ext]"),
},
},
],
},
plugins: [
new FileManagerPlugin({
events: {
onStart: {
delete: ["dist"],
},
onEnd: {
copy: [
{
source: path.join("src", "assets", "static"),
destination: "dist",
},
],
},
},
}),
new PugPlugin({
// mini-css-extract-plugin replacement
css: {
// output filename of CSS files
filename: "assets/css/[name].[contenthash:8].css",
},
js: {
filename: "assets/js/[name].[contenthash:8].css",
},
}),
],
devServer: {
watchFiles: path.join(__dirname, "src"),
port: 9000,
},
optimization: {
minimizer: [
new ImageMinimizerPlugin({
minimizer: {
implementation: ImageMinimizerPlugin.imageminMinify,
options: {
plugins: [
["gifsicle", { interlaced: true }],
["jpegtran", { progressive: true }],
["optipng", { optimizationLevel: 5 }],
["svgo", { name: "preset-default" }],
],
},
},
}),
],
},
};