This repository has been archived by the owner on Oct 28, 2020. It is now read-only.
forked from igembitsgoa/wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
84 lines (80 loc) · 2.27 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
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",
landing: "./src/js/landing.js",
notebook: "./src/js/notebook.js",
engineering: "./src/js/engineering.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: "Model/index.html",
template: "./src/pages/Model.pug",
chunks: ["landing"],
}),
new HTMLWebpackPlugin({
filename: "Experiments/index.html",
template: "./src/pages/Experiments.pug",
chunks: ["landing"],
}),
new HTMLWebpackPlugin({
filename: "Notebook/index.html",
template: "./src/pages/Notebook.pug",
chunks: ["notebook"],
}),
new HTMLWebpackPlugin({
filename: "Engineering/index.html",
template: "./src/pages/Engineering.pug",
chunks: ["engineering"],
}),
],
module: {
rules: [
{
test: /\.pug$/,
use: ["pug-loader"],
},
],
},
};