2022-01-06 12:58:10 +00:00
|
|
|
const path = require("path")
|
|
|
|
const glob = require("glob")
|
|
|
|
|
|
|
|
const { WebpackManifestPlugin } = require("webpack-manifest-plugin")
|
2022-08-29 20:53:07 +00:00
|
|
|
const GitVersionPlugin = require("@eloquent/git-version-webpack-plugin")
|
2023-12-06 08:58:15 +00:00
|
|
|
const FaviconsWebpackPlugin = require("favicons-webpack-plugin")
|
2022-01-06 12:58:10 +00:00
|
|
|
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")
|
|
|
|
],
|
2024-01-09 13:29:53 +00:00
|
|
|
main: path.resolve("src", "js", "index.js"),
|
2022-11-02 14:48:45 +00:00
|
|
|
colortheme: path.resolve("src", "js", "colorTheme.js"),
|
2022-01-06 12:58:10 +00:00
|
|
|
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: {
|
2022-01-13 20:10:45 +00:00
|
|
|
filename: "js/[name]-[contenthash:8].bundle.min.js",
|
|
|
|
chunkFilename: "js/[name]-[contenthash:8].chunk.min.js",
|
2022-01-06 12:58:10 +00:00
|
|
|
path: path.join(__dirname, "static"),
|
|
|
|
clean: true
|
|
|
|
},
|
|
|
|
watchOptions: {
|
|
|
|
ignored: ["/exampleSite/", "/node_modules/"]
|
|
|
|
},
|
2024-01-09 13:29:53 +00:00
|
|
|
target: ["web", "es2017"],
|
2022-01-06 12:58:10 +00:00
|
|
|
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")
|
2022-04-23 13:14:42 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
from: "img/*.svg",
|
|
|
|
context: path.resolve(__dirname, "build")
|
2022-01-06 12:58:10 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
|
2023-12-06 08:58:15 +00:00
|
|
|
new FaviconsWebpackPlugin({
|
|
|
|
logo: path.resolve("src", "static", "favicon", "favicon.svg"),
|
|
|
|
prefix: "favicon/",
|
|
|
|
inject: false,
|
|
|
|
favicons: {
|
|
|
|
background: "#efefef",
|
|
|
|
theme_color: "#efefef",
|
|
|
|
icons: {
|
|
|
|
android: { offset: 10 },
|
|
|
|
appleIcon: { offset: 10 },
|
|
|
|
appleStartup: { offset: 10 },
|
|
|
|
favicons: true,
|
|
|
|
windows: { offset: 10 },
|
|
|
|
yandex: false
|
|
|
|
}
|
2022-01-06 12:58:10 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
new RemoveEmptyScriptsPlugin(),
|
|
|
|
|
|
|
|
new WebpackManifestPlugin({
|
|
|
|
fileName: "../data/assets.json",
|
|
|
|
publicPath: "",
|
|
|
|
writeToFileEmit: true,
|
|
|
|
generate(seed, files) {
|
|
|
|
let manifest = {}
|
|
|
|
|
|
|
|
files.forEach(function (element, index) {
|
2022-09-12 08:15:34 +00:00
|
|
|
if (element.name.endsWith("VERSION")) return
|
2022-01-06 12:58:10 +00:00
|
|
|
if (element.name.endsWith(".svg")) return
|
2022-09-12 08:15:34 +00:00
|
|
|
if (element.name.startsWith("fonts/")) return
|
|
|
|
if (element.name.startsWith("/favicon")) return
|
2022-01-06 12:58:10 +00:00
|
|
|
|
|
|
|
Object.assign(manifest, {
|
|
|
|
[element.name]: { src: element.path }
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
return manifest
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
new SRIPlugin({
|
|
|
|
sourceFile: "data/assets.json"
|
2022-08-29 20:53:07 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
new GitVersionPlugin({
|
|
|
|
path: "../VERSION"
|
2022-01-06 12:58:10 +00:00
|
|
|
})
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2022-06-10 19:44:08 +00:00
|
|
|
outputStyle: argv.mode === "development" ? "expanded" : "compressed",
|
2022-01-06 12:58:10 +00:00
|
|
|
includePaths: [nodeModulesPath]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
return config
|
|
|
|
}
|