A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
at lambda-fork/main 101 lines 3.6 kB view raw
1const path = require("path"); 2const webpack = require("webpack"); 3const pkg = require("./package.json"); 4const MiniCssExtractPlugin = require("mini-css-extract-plugin"); 5const {CleanWebpackPlugin} = require("clean-webpack-plugin"); 6// const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin; 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 output: { 15 publicPath: "auto", 16 filename: "[name].js", 17 path: path.resolve(__dirname, "stage/build/export"), 18 libraryTarget: "umd", 19 library: "Protyle", 20 libraryExport: "default", 21 }, 22 entry: { 23 "protyle-method": "./src/protyle/method.ts", 24 }, 25 optimization: { 26 minimize: true, 27 minimizer: [ 28 new EsbuildPlugin({ 29 target: "es6", 30 sourcemap: argv.mode !== "production", 31 }), 32 ], 33 }, 34 resolve: { 35 fallback: { 36 "path": require.resolve("path-browserify"), 37 }, 38 extensions: [".ts", ".js", ".scss"], 39 }, 40 module: { 41 rules: [ 42 { 43 test: /\.ts(x?)$/, 44 include: [path.resolve(__dirname, "src")], 45 use: [ 46 { 47 loader: "esbuild-loader", 48 options: { 49 target: "es6", 50 sourcemap: argv.mode !== "production", 51 } 52 }, 53 { 54 loader: "ifdef-loader", 55 options: { 56 "ifdef-verbose": false, 57 BROWSER: true, 58 MOBILE: true, 59 }, 60 }, 61 ], 62 }, 63 { 64 test: /\.scss$/, 65 include: [ 66 path.resolve(__dirname, "src/assets/scss"), 67 ], 68 use: [ 69 MiniCssExtractPlugin.loader, 70 { 71 loader: "css-loader", // translates CSS into CommonJS 72 options: { 73 sourceMap: argv.mode !== "production", 74 }, 75 }, 76 { 77 loader: "sass-loader", // compiles Sass to CSS 78 options: { 79 sourceMap: argv.mode !== "production", 80 }, 81 }, 82 ], 83 }, 84 ], 85 }, 86 plugins: [ 87 // new BundleAnalyzerPlugin(), 88 new CleanWebpackPlugin({ 89 cleanOnceBeforeBuildPatterns: [ 90 path.join(__dirname, "stage/build/export")], 91 }), 92 new webpack.DefinePlugin({ 93 NODE_ENV: JSON.stringify(argv.mode), 94 SIYUAN_VERSION: JSON.stringify(pkg.version), 95 }), 96 new MiniCssExtractPlugin({ 97 filename: "base.css", 98 }), 99 ], 100 }; 101};