-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
119 lines (112 loc) · 2.67 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
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
let htmlPageNames = [
'about',
'services',
'gallery',
'contact',
'404',
'privacy',
];
let multipleHtmlPlugins = htmlPageNames.map((name) => {
let chunks = ['main'];
if (name === 'contact') {
chunks.push('contact');
}
if (name === 'gallery') {
chunks.push('gallery');
}
return new HtmlWebpackPlugin({
template: `./src/${name}.html`, // relative path to the HTML files
filename: `${name}.html`, // output HTML files
chunks: chunks, // respective JS files
});
});
const config = {
entry: {
index: './src/js/index.js',
contact: './src/js/contact.js',
main: './src/js/main.js',
gallery: './src/js/gallery.js',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].bundle.js', // Using [name] placeholder for dynamic filenames
clean: true,
},
devServer: {
watchFiles: ['src/**/*'],
},
module: {
rules: [
{
test: /\.css$/i,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 1,
},
},
'postcss-loader',
],
},
{
test: /\.html$/i,
use: {
loader: 'html-loader',
// options: {
// sources: {
// list: [
// // Configure which tags to process
// { tag: 'video', attribute: 'src', type: 'src' },
// ],
// },
// },
},
},
{
test: /\.(png|svg|jpg|jpeg|gif|mp4|webp)$/i,
type: 'asset/resource',
generator: {
filename: 'images/[name][ext]',
},
},
{
test: /\.(webmanifest|xml|ico)$/i,
type: 'asset/resource',
generator: {
filename: 'favicons/[name][ext]',
},
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: 'src/index.html',
filename: 'index.html',
chunks: ['main', 'index'], // Include 'main' and 'index' entry point in this HTML file
}),
...multipleHtmlPlugins, // array of html plugins
new MiniCssExtractPlugin({
filename: '[name].css', // Output CSS file name using
}),
new FaviconsWebpackPlugin('./src/images/kangaHeadnew.png'),
new CopyWebpackPlugin({
patterns: [
// Copy all files within src/images over to the dist folder
{ from: 'src/images', to: 'images' },
// Copy sitemap.xml to the root of the dist folder
{ from: 'sitemap.xml', to: './' },
// // Copy robots.txt to the root of the dist folder
{ from: 'robots.txt', to: './' },
],
}),
],
};
module.exports = config;