123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- import path from "path"
- import { glob } from "glob"
- import { fileURLToPath } from "url"
- import { WebpackManifestPlugin } from "webpack-manifest-plugin"
- import FaviconsWebpackPlugin from "favicons-webpack-plugin"
- import RemoveEmptyScriptsPlugin from "webpack-remove-empty-scripts"
- import CopyPlugin from "copy-webpack-plugin"
- import { SRIPlugin, GitVersionPlugin } from "./webpack.plugins.js"
- const __filename = fileURLToPath(import.meta.url)
- const __dirname = path.dirname(__filename)
- 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", "index.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/"]
- },
- target: ["web", "es2017"],
- 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 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
- }
- }
- }),
- 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({
- outputFile: "../VERSION"
- })
- ]
- }
- export default (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: {
- sourceMap: argv.mode === "development" ? true : false,
- sassOptions: {
- outputStyle: argv.mode === "development" ? "expanded" : "compressed"
- }
- }
- }
- ]
- }
- ]
- }
- return config
- }
|