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");
11 hash:[contentHash], chunkhash:[chunkhash], name:[name], filebase:[base], query:[query], file:[file]
12 Source code: https://github.com/LemmyNet/lemmy-ui
14 @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
19 filename: "js/server.js",
21 hashFunction: "xxhash64",
24 extensions: [".js", ".jsx", ".ts", ".tsx"],
26 "@": path.resolve(__dirname, "src/"),
27 "@utils": path.resolve(__dirname, "src/shared/utils/"),
36 test: /\.(scss|css)$/i,
37 use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
40 test: /\.(js|jsx|tsx|ts)$/, // All ts and tsx files will be process by
41 exclude: /node_modules/, // ignore node_modules
42 loader: "babel-loader",
44 // Due to some weird babel issue: https://github.com/webpack/webpack/issues/11467
48 fullySpecified: false,
54 new MiniCssExtractPlugin({
55 filename: "styles/styles.css",
58 patterns: [{ from: "./src/assets", to: "./assets" }],
60 new webpack.BannerPlugin({
66 const createServerConfig = (_env, mode) => {
67 const config = merge({}, base, {
69 entry: "./src/server/index.tsx",
71 filename: "js/server.js",
74 externals: [nodeExternals(), "inferno-helmet"],
77 if (mode === "development") {
79 // type: "filesystem",
84 new RunNodeWebpackPlugin({
85 runOnlyInWatchMode: true,
93 const createClientConfig = (_env, mode) => {
94 const config = merge({}, base, {
96 entry: "./src/client/index.tsx",
98 filename: "js/client.js",
99 publicPath: "/static/",
103 new ServiceWorkerPlugin({
104 enableInDevelopment: mode !== "development", // this may seem counterintuitive, but it is correct
110 include: [/(assets|styles|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 const BundleAnalyzerPlugin =
160 require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
161 config.plugins.push(new BundleAnalyzerPlugin());
167 module.exports = (env, properties) => [
168 createServerConfig(env, properties.mode || "development"),
169 createClientConfig(env, properties.mode || "development"),