2022-01-06 13:58:10 +01:00
|
|
|
const path = require("path")
|
|
|
|
const glob = require("glob")
|
|
|
|
|
|
|
|
const { WebpackManifestPlugin } = require("webpack-manifest-plugin")
|
2022-08-29 22:53:07 +02:00
|
|
|
const GitVersionPlugin = require("@eloquent/git-version-webpack-plugin")
|
2022-09-12 09:31:23 +02:00
|
|
|
const WebpackFavicons = require("webpack-favicons")
|
2022-01-06 13:58:10 +01: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")
|
|
|
|
],
|
2022-01-08 21:36:55 +01:00
|
|
|
main: path.resolve("src", "js", "app.js"),
|
2022-11-02 15:48:45 +01:00
|
|
|
colortheme: path.resolve("src", "js", "colorTheme.js"),
|
2022-01-06 13:58:10 +01: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 21:10:45 +01:00
|
|
|
filename: "js/[name]-[contenthash:8].bundle.min.js",
|
|
|
|
chunkFilename: "js/[name]-[contenthash:8].chunk.min.js",
|
2022-01-06 13:58:10 +01:00
|
|
|
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")
|
2022-04-23 15:14:42 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
from: "img/*.svg",
|
|
|
|
context: path.resolve(__dirname, "build")
|
2022-01-06 13:58:10 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
|
2022-09-12 09:31:23 +02:00
|
|
|
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
|
2022-01-06 13:58:10 +01: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 10:15:34 +02:00
|
|
|
if (element.name.endsWith("VERSION")) return
|
2022-01-06 13:58:10 +01:00
|
|
|
if (element.name.endsWith(".svg")) return
|
2022-09-12 10:15:34 +02:00
|
|
|
if (element.name.startsWith("fonts/")) return
|
|
|
|
if (element.name.startsWith("/favicon")) return
|
2022-01-06 13:58:10 +01:00
|
|
|
|
|
|
|
Object.assign(manifest, {
|
|
|
|
[element.name]: { src: element.path }
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
return manifest
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
new SRIPlugin({
|
|
|
|
sourceFile: "data/assets.json"
|
2022-08-29 22:53:07 +02:00
|
|
|
}),
|
|
|
|
|
|
|
|
new GitVersionPlugin({
|
|
|
|
path: "../VERSION"
|
2022-01-06 13:58:10 +01: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 21:44:08 +02:00
|
|
|
outputStyle: argv.mode === "development" ? "expanded" : "compressed",
|
2022-01-06 13:58:10 +01:00
|
|
|
includePaths: [nodeModulesPath]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
return config
|
|
|
|
}
|