1 const webpack = require("webpack");
2 const path = require("path");
3 const MiniCssExtractPlugin = require("mini-css-extract-plugin");
4 const nodeExternals = require("webpack-node-externals");
5 const CopyPlugin = require("copy-webpack-plugin");
6 const RunNodeWebpackPlugin = require("run-node-webpack-plugin");
7 const merge = require("lodash.merge");
8 const { ServiceWorkerPlugin } = require("service-worker-webpack");
9 const BundleAnalyzerPlugin =
10 require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
12 hash:[contentHash], chunkhash:[chunkhash], name:[name], filebase:[base], query:[query], file:[file]
13 Source code: https://github.com/LemmyNet/lemmy-ui
15 @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
20 filename: "js/server.js",
22 hashFunction: "xxhash64",
25 extensions: [".js", ".jsx", ".ts", ".tsx"],
27 "@": path.resolve(__dirname, "src/"),
28 "@utils": path.resolve(__dirname, "src/shared/utils/"),
37 test: /\.(scss|css)$/i,
38 use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
41 test: /\.(js|jsx|tsx|ts)$/, // All ts and tsx files will be process by
42 exclude: /node_modules/, // ignore node_modules
43 loader: "babel-loader",
45 // Due to some weird babel issue: https://github.com/webpack/webpack/issues/11467
49 fullySpecified: false,
55 new MiniCssExtractPlugin({
56 filename: "styles/styles.css",
59 patterns: [{ from: "./src/assets", to: "./assets" }],
61 new webpack.BannerPlugin({
67 const createServerConfig = (_env, mode) => {
68 const config = merge({}, base, {
70 entry: "./src/server/index.tsx",
72 filename: "js/server.js",
75 externals: [nodeExternals(), "inferno-helmet"],
78 if (mode === "development") {
80 // type: "filesystem",
85 new RunNodeWebpackPlugin({
86 runOnlyInWatchMode: true,
94 const createClientConfig = (_env, mode) => {
95 const config = merge({}, base, {
97 entry: "./src/client/index.tsx",
99 filename: "js/client.js",
103 new ServiceWorkerPlugin({
104 enableInDevelopment: mode !== "development", // this may seem counterintuitive, but it is correct
110 include: [/(assets|styles)\/.+\..+|client\.js$/g],
111 inlineWorkboxRuntime: true,
116 url: { pathname, host },
119 (sameOrigin || host.includes("localhost")) &&
121 pathname.includes("pictrs") || pathname.includes("static")
124 handler: "NetworkFirst",
126 cacheName: "instance-cache",
130 urlPattern: ({ url: { pathname, host }, sameOrigin }) =>
131 (sameOrigin || host.includes("localhost")) &&
132 pathname.includes("static"),
133 handler: mode === "development" ? "NetworkFirst" : "CacheFirst",
135 cacheName: "static-cache",
137 maxAgeSeconds: 60 * 60 * 24,
142 urlPattern: ({ url: { pathname }, request: { method } }) =>
143 pathname.includes("pictrs") && method === "GET",
144 handler: "StaleWhileRevalidate",
146 cacheName: "image-cache",
148 maxAgeSeconds: 60 * 60 * 24,
158 if (mode === "none") {
159 config.plugins.push(new BundleAnalyzerPlugin());
165 module.exports = (env, properties) => [
166 createServerConfig(env, properties.mode || "development"),
167 createClientConfig(env, properties.mode || "development"),