1 const webpack = require("webpack");
2 const MiniCssExtractPlugin = require("mini-css-extract-plugin");
3 const nodeExternals = require("webpack-node-externals");
4 const CopyPlugin = require("copy-webpack-plugin");
5 const RunNodeWebpackPlugin = require("run-node-webpack-plugin");
6 const merge = require("lodash/merge");
7 const { ServiceWorkerPlugin } = require("service-worker-webpack");
9 hash:[contentHash], chunkhash:[chunkhash], name:[name], filebase:[base], query:[query], file:[file]
10 Source code: https://github.com/LemmyNet/lemmy-ui
12 @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
17 filename: "js/server.js",
19 hashFunction: "xxhash64",
22 extensions: [".js", ".jsx", ".ts", ".tsx"],
30 test: /\.(scss|css)$/i,
31 use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
34 test: /\.(js|jsx|tsx|ts)$/, // All ts and tsx files will be process by
35 exclude: /node_modules/, // ignore node_modules
36 loader: "babel-loader",
38 // Due to some weird babel issue: https://github.com/webpack/webpack/issues/11467
42 fullySpecified: false,
48 new MiniCssExtractPlugin({
49 filename: "styles/styles.css",
52 patterns: [{ from: "./src/assets", to: "./assets" }],
54 new webpack.BannerPlugin({
60 const createServerConfig = (_env, mode) => {
61 const config = merge({}, base, {
63 entry: "./src/server/index.tsx",
65 filename: "js/server.js",
68 externals: [nodeExternals(), "inferno-helmet"],
71 if (mode === "development") {
78 new RunNodeWebpackPlugin({
79 runOnlyInWatchMode: true,
87 const createClientConfig = (_env, mode) => {
88 const config = merge({}, base, {
90 entry: "./src/client/index.tsx",
92 filename: "js/client.js",
96 new ServiceWorkerPlugin({
97 enableInDevelopment: true,
103 include: [/(assets|styles)\/.+\..+|client\.js$/g],
104 inlineWorkboxRuntime: true,
109 url: { pathname, host },
112 (sameOrigin || host.includes("localhost")) &&
114 pathname.includes("pictrs") || pathname.includes("static")
117 handler: "NetworkFirst",
119 cacheName: "instance-cache",
123 urlPattern: ({ url: { pathname, host }, sameOrigin }) =>
124 (sameOrigin || host.includes("localhost")) &&
125 pathname.includes("static"),
126 handler: mode === "development" ? "NetworkFirst" : "CacheFirst",
128 cacheName: "static-cache",
130 maxAgeSeconds: 60 * 60 * 24,
135 urlPattern: ({ url: { pathname }, request: { method } }) =>
136 pathname.includes("pictrs") && method === "GET",
137 handler: "StaleWhileRevalidate",
139 cacheName: "image-cache",
141 maxAgeSeconds: 60 * 60 * 24,
151 if (mode === "development") {
161 module.exports = (env, properties) => [
162 createServerConfig(env, properties.mode || "development"),
163 createClientConfig(env, properties.mode || "development"),