-
Notifications
You must be signed in to change notification settings - Fork 19
/
webpack.config.js
117 lines (112 loc) · 3.29 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
const { resolve, join } = require("path");
const plugins = {
html: require("html-webpack-plugin"),
css: require("mini-css-extract-plugin"),
copy: require("copy-webpack-plugin"),
json: require("json-minimizer-webpack-plugin")
}
module.exports = {
entry: {
index: "./src/app/index.js",
spaHandler: "./src/app/spaHandler.js",
},
output: {
path: resolve(__dirname, "dist"),
filename: "js/[name].js",
chunkFilename: "js/[chunkhash].js"
},
mode: "development",
plugins: [
new plugins.html({
template: "src/templates/index.ejs",
filename: "index.html",
excludeChunks: ["spaHandler"],
title: "Elias Portfolio",
'meta': {
'viewport': 'width=device-width, initial-scale=1, shrink-to-fit=no',
'theme-color': '#C778DD',
}
}),
new plugins.html({
template: "src/templates/404.ejs",
filename: "404.html",
chunks: ["spaHandler"]
}),
new plugins.css({
filename: "css/[name].css",
chunkFilename: (pathData) => {
if (typeof pathData.chunk.id === "number") return "css/[name].css"
const name = pathData.chunk.id.split("_").at(-2).toLowerCase()
return `css/${name}.css`
}
}),
new plugins.copy({
patterns: [
{ from: "src/assets/images", to: "images" },
{ from: "src/assets/locales", to: "locales" },
],
})
],
module: {
rules: [
{
test: /\.(sass)$/,
use: [plugins.css.loader, "css-loader", "sass-loader"],
include: [
join(__dirname, "src/assets/styles")
]
},
{
test: /\.json$/i,
type: "asset/resource",
include: [
join(__dirname, "src/assets/locales")
]
},
{
test: /\.(png|svg|jpe?g|gif)$/i,
include: [
join(__dirname, "src/assets/images")
],
type: "asset/resource",
generator: {
filename: "images/[contenthash][ext]",
}
},
{
test: /\.(woff(2)?|eot|(o|t)tf)$/i,
type: "asset/resource",
include: [
join(__dirname, "src/assets/fonts/")
],
generator: {
filename: "fonts/[contenthash][ext]",
}
},
],
},
devServer: {
static: {
directory: join(__dirname, 'dist'),
},
port: 9000,
historyApiFallback: {
rewrites: [
{ from: /./, to: "/404.html" },
],
}
},
resolve: {
alias: {
"@": resolve(__dirname, "src/app/"),
styles: resolve(__dirname, "src/assets/styles/"),
fonts: resolve(__dirname, "src/assets/fonts/fira-code/")
},
},
optimization: {
minimize: true,
minimizer: [
new plugins.json(),
],
},
};