-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.common.js
85 lines (81 loc) · 2.63 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 HtmlWebpackPlugin = require("html-webpack-plugin");
const {CleanWebpackPlugin} = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const SitemapPlugin = require("sitemap-webpack-plugin").default;
const fs = require("fs");
const pages = fs.readdirSync(path.resolve(__dirname, "./src/templates/"), {withFileTypes: true})
.filter(item => !item.isDirectory())
.map(item => item.name.replace(".html", ""));
module.exports = {
entry: pages.reduce((config, page) => {
if (fs.existsSync(path.resolve(`./src/${page}.ts`)))
config[page] = `./src/${page}.ts`;
return config;
}, {}),
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.s?css$/i,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"postcss-loader",
"sass-loader"
],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
generator: {
filename: 'fonts/[name][ext][query]', // Output directory and file naming
},
},
]
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
output: {
filename: "bundle[name].[hash].js",
path: path.resolve(__dirname, "build"),
publicPath: ""
},
optimization: {
splitChunks: {
chunks: "all",
},
},
plugins: [
new CleanWebpackPlugin(),
new CopyPlugin({
patterns: [
{from: path.resolve(__dirname, "./public")},
],
}),
...pages.map(
(page) =>
new HtmlWebpackPlugin({
inject: true,
template: path.resolve(__dirname, `./src/templates/${page}.html`),
// favicon: path.resolve(__dirname, "./public/favicon/favicon.ico"),
filename: `${page}.html`,
chunks: [page],
title: "WMC",
scriptLoading: "defer",
publicPath: "/",
})
),
new MiniCssExtractPlugin({filename: "styles.[contenthash].css"}),
new SitemapPlugin({
base: "https://wmc.tinkerhub.org",
paths: pages.map((p) => `/${p.replace("index", "")}`)
})
]
};