A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
1const path = require("path");
2const webpack = require("webpack");
3const pkg = require("./package.json");
4const MiniCssExtractPlugin = require("mini-css-extract-plugin");
5const HtmlWebpackPlugin = require("html-webpack-plugin");
6const {CleanWebpackPlugin} = require("clean-webpack-plugin");
7const {EsbuildPlugin} = require("esbuild-loader");
8
9module.exports = (env, argv) => {
10 return {
11 mode: argv.mode || "development",
12 watch: argv.mode !== "production",
13 devtool: argv.mode !== "production" ? "eval-source-map" : false,
14 target: "electron-renderer",
15 output: {
16 publicPath: "auto",
17 filename: "[name].[chunkhash].js",
18 path: path.resolve(__dirname, "stage/build/app"),
19 },
20 entry: {
21 "main": "./src/index.ts",
22 "window": "./src/window/index.ts",
23 },
24 resolve: {
25 extensions: [".ts", ".js", ".tpl", ".scss", ".png", ".svg"],
26 },
27 optimization: {
28 minimize: argv.mode === "production",
29 minimizer: [
30 new EsbuildPlugin({
31 target: "es2021",
32 sourcemap: argv.mode !== "production",
33 }),
34 ],
35 },
36 module: {
37 rules: [
38 {
39 test: /\.tpl/,
40 include: [
41 path.resolve(__dirname, "src/assets/template/app/index.tpl"),
42 path.resolve(__dirname, "src/assets/template/app/window.tpl")],
43 loader: "html-loader",
44 options: {
45 sources: false,
46 },
47 },
48 {
49 test: /\.ts(x?)$/,
50 include: [path.resolve(__dirname, "src")],
51 use: [
52 {
53 loader: "esbuild-loader",
54 options: {
55 target: "es2021",
56 sourcemap: argv.mode !== "production",
57 },
58 },
59 {
60 loader: "ifdef-loader", options: {
61 BROWSER: false,
62 MOBILE: false,
63 },
64 },
65 ],
66 },
67 {
68 test: /\.scss$/,
69 include: [
70 path.resolve(__dirname, "src/assets/scss"),
71 ],
72 use: [
73 MiniCssExtractPlugin.loader,
74 {
75 loader: "css-loader", // translates CSS into CommonJS
76 options: {
77 sourceMap: argv.mode !== "production",
78 },
79 },
80 {
81 loader: "sass-loader", // compiles Sass to CSS
82 options: {
83 sourceMap: argv.mode !== "production",
84 },
85 },
86 ],
87 },
88 {
89 test: /\.(png|svg)$/,
90 use: [
91 {
92 loader: "file-loader",
93 options: {
94 name: "[name].[ext]",
95 outputPath: "../../",
96 },
97 },
98 ],
99 },
100 ],
101 },
102 plugins: [
103 new CleanWebpackPlugin({
104 cleanStaleWebpackAssets: false,
105 cleanOnceBeforeBuildPatterns: [
106 path.join(__dirname, "stage/build/app")],
107 }),
108 new webpack.DefinePlugin({
109 SIYUAN_VERSION: JSON.stringify(pkg.version),
110 NODE_ENV: JSON.stringify(argv.mode),
111 }),
112 new MiniCssExtractPlugin({
113 filename: "base.[contenthash].css",
114 }),
115 new HtmlWebpackPlugin({
116 inject: "head",
117 chunks: ["main"],
118 filename: "index.html",
119 template: "src/assets/template/app/index.tpl",
120 }),
121 new HtmlWebpackPlugin({
122 inject: "head",
123 chunks: ["window"],
124 filename: "window.html",
125 template: "src/assets/template/app/window.tpl",
126 }),
127 ],
128 };
129};