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");
8 const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
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 plugins: [new TsconfigPathsPlugin()],
24 extensions: [".js", ".jsx", ".ts", ".tsx"],
32 test: /\.(scss|css)$/i,
33 use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
36 test: /\.(js|jsx|tsx|ts)$/, // All ts and tsx files will be process by
37 exclude: /node_modules/, // ignore node_modules
38 loader: "babel-loader",
40 // Due to some weird babel issue: https://github.com/webpack/webpack/issues/11467
44 fullySpecified: false,
50 new MiniCssExtractPlugin({
51 filename: "styles/styles.css",
54 patterns: [{ from: "./src/assets", to: "./assets" }],
56 new webpack.BannerPlugin({
62 const createServerConfig = (_env, mode) => {
63 const config = merge({}, base, {
65 entry: "./src/server/index.tsx",
67 filename: "js/server.js",
70 externals: [nodeExternals(), "inferno-helmet"],
73 if (mode === "development") {
75 // type: "filesystem",
80 new RunNodeWebpackPlugin({
81 runOnlyInWatchMode: true,
89 const createClientConfig = (_env, mode) => {
90 const config = merge({}, base, {
92 entry: "./src/client/index.tsx",
94 filename: "js/client.js",
98 new ServiceWorkerPlugin({
99 enableInDevelopment: mode !== "development", // this may seem counterintuitive, but it is correct
105 include: [/(assets|styles)\/.+\..+|client\.js$/g],
106 inlineWorkboxRuntime: true,
111 url: { pathname, host },
114 (sameOrigin || host.includes("localhost")) &&
116 pathname.includes("pictrs") || pathname.includes("static")
119 handler: "NetworkFirst",
121 cacheName: "instance-cache",
125 urlPattern: ({ url: { pathname, host }, sameOrigin }) =>
126 (sameOrigin || host.includes("localhost")) &&
127 pathname.includes("static"),
128 handler: mode === "development" ? "NetworkFirst" : "CacheFirst",
130 cacheName: "static-cache",
132 maxAgeSeconds: 60 * 60 * 24,
137 urlPattern: ({ url: { pathname }, request: { method } }) =>
138 pathname.includes("pictrs") && method === "GET",
139 handler: "StaleWhileRevalidate",
141 cacheName: "image-cache",
143 maxAgeSeconds: 60 * 60 * 24,
153 if (mode === "development") {
155 // type: "filesystem",
163 module.exports = (env, properties) => [
164 createServerConfig(env, properties.mode || "development"),
165 createClientConfig(env, properties.mode || "development"),