-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
106 lines (105 loc) · 2.92 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
const path = require('path');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const HtmlMinimizerPlugin = require("html-minimizer-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
module.exports = {
entry: './src/js/index.js',
output: {
path: path.resolve(__dirname, 'public'),
filename: 'js/index.js',
},
plugins: [
new MiniCssExtractPlugin({
filename: 'css/index.css'
}),
new CleanWebpackPlugin({
verbose: true,
cleanOnceBeforeBuildPatterns: [
'!.gitignore',
],
}),
new CopyPlugin({
patterns: [
{
context: path.resolve(__dirname, "src"),
from: "*.html",
},
{
context: path.resolve(__dirname, "src"),
from: "images/**/*",
},
],
}),
],
devtool: "source-map",
module: {
rules: [
{
test: /\.css$/,
include: path.resolve(__dirname, 'src'),
use: [
MiniCssExtractPlugin.loader,
{loader: "css-loader", options: {sourceMap: true}},
{loader: 'postcss-loader'}
],
},
{
test: /\.html$/i,
type: "asset/resource",
},
],
},
optimization: {
minimize: true,
minimizer: [
new HtmlMinimizerPlugin(),
new CssMinimizerPlugin({
minimizerOptions: {
preset: [
"default",
{
discardComments: {removeAll: true},
},
],
},
}),
new TerserPlugin({
terserOptions: {
format: {
comments: false,
},
},
extractComments: false,
}),
],
},
devServer: {
compress: true,
hot: true,
liveReload: true, // reloads webpage when changes are detected
host: 'portfolio.local',
port: 7000,
allowedHosts: 'all',
open: true,
https: false,
server: 'http',
headers: {
'X-Custom-Foo': 'bar',
},
client: {
logging: 'verbose',
progress: true,
overlay: true,
},
static: {
directory: path.join(__dirname, 'src'),
},
},
watchOptions: {
aggregateTimeout: 1000,
// ignored: '!src',
},
};