forked from thegeeklab/hugo-geekdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
157 lines (143 loc) · 4.21 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const path = require("path")
const glob = require("glob")
const { WebpackManifestPlugin } = require("webpack-manifest-plugin")
const GitVersionPlugin = require("@eloquent/git-version-webpack-plugin")
const WebpackFavicons = require("webpack-favicons")
const RemoveEmptyScriptsPlugin = require("webpack-remove-empty-scripts")
const CopyPlugin = require("copy-webpack-plugin")
const SRIPlugin = require("./webpack.plugins")
const nodeModulesPath = path.resolve(__dirname, "node_modules")
var config = {
entry: {
css: [
path.resolve("src", "sass", "main.scss"),
path.resolve("src", "sass", "mobile.scss"),
path.resolve("src", "sass", "print.scss")
],
main: path.resolve("src", "js", "app.js"),
colortheme: path.resolve("src", "js", "colorTheme.js"),
mermaid: path.resolve("src", "js", "mermaid.js"),
katex: [path.resolve("src", "js", "katex.js")].concat(
glob.sync(path.join(nodeModulesPath, "katex", "dist", "fonts", "*.{woff,woff2}"))
),
search: [path.resolve("src", "js", "search.js")]
},
output: {
filename: "js/[name]-[contenthash:8].bundle.min.js",
chunkFilename: "js/[name]-[contenthash:8].chunk.min.js",
path: path.join(__dirname, "static"),
clean: true
},
watchOptions: {
ignored: ["/exampleSite/", "/node_modules/"]
},
plugins: [
new CopyPlugin({
patterns: [
{
from: "**/*",
context: path.resolve(__dirname, "src", "static")
},
{
from: "fonts/*.{woff,woff2}",
context: path.resolve(__dirname, "build")
},
{
from: "sprites/*.svg",
to: path.resolve(__dirname, "assets"),
context: path.resolve(__dirname, "build")
},
{
from: "img/*.svg",
context: path.resolve(__dirname, "build")
}
]
}),
new WebpackFavicons({
src: path.resolve("src", "static", "favicon", "favicon.svg"),
path: "favicon/",
background: "#2f333e",
theme_color: "#2f333e",
icons: {
android: { offset: 10 },
appleIcon: { offset: 10 },
appleStartup: { offset: 10 },
favicons: true,
windows: { offset: 10 },
yandex: false,
coast: false
}
}),
new RemoveEmptyScriptsPlugin(),
new WebpackManifestPlugin({
fileName: "../data/assets.json",
publicPath: "",
writeToFileEmit: true,
generate(seed, files) {
let manifest = {}
files.forEach(function (element, index) {
if (element.name.endsWith("VERSION")) return
if (element.name.endsWith(".svg")) return
if (element.name.startsWith("fonts/")) return
if (element.name.startsWith("/favicon")) return
Object.assign(manifest, {
[element.name]: { src: element.path }
})
})
return manifest
}
}),
new SRIPlugin({
sourceFile: "data/assets.json"
}),
new GitVersionPlugin({
path: "../VERSION"
})
]
}
module.exports = (env, argv) => {
if (argv.mode === "development") {
config.devtool = "eval-cheap-source-map"
}
config.module = {
rules: [
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: "asset/resource",
generator: {
filename: "fonts/[name][ext]"
}
},
{
test: /\.(sa|sc|c)ss$/i,
type: "asset/resource",
generator: {
filename: "[name]-[contenthash:8].min.css"
},
use: [
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: ["autoprefixer"]
}
}
},
{
loader: "sass-loader",
options: {
sassOptions: {
// FIXME: https://github.com/webpack-contrib/sass-loader/issues/962#issuecomment-1002675051
sourceMap: argv.mode === "development" ? true : false,
sourceMapEmbed: argv.mode === "development" ? true : false,
outputStyle: argv.mode === "development" ? "expanded" : "compressed",
includePaths: [nodeModulesPath]
}
}
}
]
}
]
}
return config
}