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");
10 hash:[contentHash], chunkhash:[chunkhash], name:[name], filebase:[base], query:[query], file:[file]
11 Source code: https://github.com/LemmyNet/lemmy-ui
13 @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
18 filename: "js/server.js",
20 hashFunction: "xxhash64",
23 extensions: [".js", ".jsx", ".ts", ".tsx"],
25 "@": path.resolve(__dirname, "src/"),
26 "@utils": path.resolve(__dirname, "src/shared/utils/"),
35 test: /\.(scss|css)$/i,
36 use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
39 test: /\.(js|jsx|tsx|ts)$/, // All ts and tsx files will be process by
40 exclude: /node_modules/, // ignore node_modules
41 loader: "babel-loader",
43 // Due to some weird babel issue: https://github.com/webpack/webpack/issues/11467
47 fullySpecified: false,
53 new MiniCssExtractPlugin({
54 filename: "styles/styles.css",
57 patterns: [{ from: "./src/assets", to: "./assets" }],
59 new webpack.BannerPlugin({
65 const createServerConfig = (_env, mode) => {
66 const config = merge({}, base, {
68 entry: "./src/server/index.tsx",
70 filename: "js/server.js",
73 externals: [nodeExternals(), "inferno-helmet"],
76 if (mode === "development") {
78 // type: "filesystem",
83 new RunNodeWebpackPlugin({
84 runOnlyInWatchMode: true,
92 const createClientConfig = (_env, mode) => {
93 const config = merge({}, base, {
95 entry: "./src/client/index.tsx",
97 filename: "js/client.js",
101 new ServiceWorkerPlugin({
102 enableInDevelopment: mode !== "development", // this may seem counterintuitive, but it is correct
108 include: [/(assets|styles)\/.+\..+|client\.js$/g],
109 inlineWorkboxRuntime: true,
114 url: { pathname, host },
117 (sameOrigin || host.includes("localhost")) &&
119 pathname.includes("pictrs") || pathname.includes("static")
122 handler: "NetworkFirst",
124 cacheName: "instance-cache",
128 urlPattern: ({ url: { pathname, host }, sameOrigin }) =>
129 (sameOrigin || host.includes("localhost")) &&
130 pathname.includes("static"),
131 handler: mode === "development" ? "NetworkFirst" : "CacheFirst",
133 cacheName: "static-cache",
135 maxAgeSeconds: 60 * 60 * 24,
140 urlPattern: ({ url: { pathname }, request: { method } }) =>
141 pathname.includes("pictrs") && method === "GET",
142 handler: "StaleWhileRevalidate",
144 cacheName: "image-cache",
146 maxAgeSeconds: 60 * 60 * 24,
156 if (mode === "development") {
158 // type: "filesystem",
166 module.exports = (env, properties) => [
167 createServerConfig(env, properties.mode || "development"),
168 createClientConfig(env, properties.mode || "development"),