This repository has been archived by the owner on Apr 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.common.js
85 lines (81 loc) · 2.33 KB
/
webpack.common.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
const path = require("path");
const fs = require("fs");
var HTMLWebpackPlugin = require("html-webpack-plugin");
// List all files in a directory in Node.js recursively in a synchronous fashion
// https://gist.github.com/kethinov/6658166#gistcomment-1976458
const walkSync = (dir, filelist = []) => {
fs.readdirSync(dir).forEach((file) => {
filelist = fs.statSync(path.join(dir, file)).isDirectory()
? walkSync(path.join(dir, file), filelist)
: filelist.concat(path.join(dir, file));
});
return filelist;
};
const dir = "src/pages";
const pages = walkSync(dir).map((el) => el.slice(dir.length + 1));
console.log(pages);
module.exports = {
entry: {
index: "./src/index.js",
content: "./src/js/content.js",
team: "./src/js/team.js",
parts: "./src/js/parts.js",
poster: "./src/js/poster.js",
human_practices: "./src/js/human_practices.js",
medal_criteria: "./src/js/medal_criteria.js",
},
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "dist"),
},
devtool: "none", // avoid eval statements
// https://stackoverflow.com/questions/44557802/how-to-create-multiple-pages-in-webpack
plugins: [
new HTMLWebpackPlugin({
filename: "index.html",
template: "./src/index.pug",
chunks: ["index"],
}),
...pages.map(
(page) =>
new HTMLWebpackPlugin({
template: "./src/pages/" + page,
filename: page.slice(0, -4) + "/index.html",
chunks: ["content"],
})
),
new HTMLWebpackPlugin({
filename: "Team/index.html",
template: "./src/pages/Team.pug",
chunks: ["team"],
}),
new HTMLWebpackPlugin({
filename: "Parts/index.html",
template: "./src/pages/Parts.pug",
chunks: ["parts"],
}),
new HTMLWebpackPlugin({
filename: "Poster/index.html",
template: "./src/pages/Poster.pug",
chunks: ["poster"],
}),
new HTMLWebpackPlugin({
filename: "Human_Practices/index.html",
template: "./src/pages/Human_Practices.pug",
chunks: ["human_practices"],
}),
new HTMLWebpackPlugin({
filename: "Medal_Criteria/index.html",
template: "./src/pages/Medal_Criteria.pug",
chunks: ["medal_criteria"],
}),
],
module: {
rules: [
{
test: /\.pug$/,
use: ["pug-loader"],
},
],
},
};