From: Daniele Basso <d.bass05@proton.me>
Date: Thu, 13 Jul 2023 20:05:28 +0000 (+0000)
Subject: Remove lodash.merge dependency (#1911)
X-Git-Url: http://these/git/%22https:/www.exeterceilidhs.net/%22%7B%7D/readmes/README.es.md?a=commitdiff_plain;h=dbeab6450bce05c7bca898935e8b4f6d3d72ff5a;p=lemmy-ui.git

Remove lodash.merge dependency (#1911)

Remove lodash.merge dependency from webpack.config.js file, replacing it with using spread sintax (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax)
---

diff --git a/package.json b/package.json
index fdc1dfd..5c932a9 100644
--- a/package.json
+++ b/package.json
@@ -69,7 +69,6 @@
     "jwt-decode": "^3.1.2",
     "lemmy-js-client": "0.18.1",
     "lodash.isequal": "^4.5.0",
-    "lodash.merge": "^4.6.2",
     "markdown-it": "^13.0.1",
     "markdown-it-container": "^3.0.0",
     "markdown-it-emoji": "^2.0.2",
diff --git a/webpack.config.js b/webpack.config.js
index a67ed2e..267a144 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -1,10 +1,9 @@
 const webpack = require("webpack");
-const path = require("path");
+const { resolve } = require("path");
 const MiniCssExtractPlugin = require("mini-css-extract-plugin");
 const nodeExternals = require("webpack-node-externals");
 const CopyPlugin = require("copy-webpack-plugin");
 const RunNodeWebpackPlugin = require("run-node-webpack-plugin");
-const merge = require("lodash.merge");
 const { ServiceWorkerPlugin } = require("service-worker-webpack");
 
 const banner = `
@@ -14,8 +13,10 @@ const banner = `
   @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
   `;
 
-function getBase(env, mode) {
-  return {
+module.exports = (env, argv) => {
+  const mode = argv.mode;
+
+  const base = {
     output: {
       filename: "js/server.js",
       publicPath: "/",
@@ -24,8 +25,8 @@ function getBase(env, mode) {
     resolve: {
       extensions: [".js", ".jsx", ".ts", ".tsx"],
       alias: {
-        "@": path.resolve(__dirname, "src/"),
-        "@utils": path.resolve(__dirname, "src/shared/utils/"),
+        "@": resolve(__dirname, "src/"),
+        "@utils": resolve(__dirname, "src/shared/utils/"),
       },
     },
     performance: {
@@ -67,40 +68,19 @@ function getBase(env, mode) {
       }),
     ],
   };
-}
 
-const createServerConfig = (env, mode) => {
-  const base = getBase(env, mode);
-  const config = merge({}, base, {
-    mode,
+  const serverConfig = {
+    ...base,
     entry: "./src/server/index.tsx",
     output: {
       filename: "js/server.js",
     },
     target: "node",
     externals: [nodeExternals(), "inferno-helmet"],
-  });
-
-  if (mode === "development") {
-    // config.cache = {
-    //   type: "filesystem",
-    //   name: "server",
-    // };
-
-    config.plugins.push(
-      new RunNodeWebpackPlugin({
-        runOnlyInWatchMode: true,
-      })
-    );
-  }
-
-  return config;
-};
+  };
 
-const createClientConfig = (env, mode) => {
-  const base = getBase(env, mode);
-  const config = merge({}, base, {
-    mode,
+  const clientConfig = {
+    ...base,
     entry: "./src/client/index.tsx",
     output: {
       filename: "js/client.js",
@@ -158,18 +138,21 @@ const createClientConfig = (env, mode) => {
         },
       }),
     ],
-  });
+  };
+
+  if (mode === "development") {
+    // serverConfig.cache = {
+    //   type: "filesystem",
+    //   name: "server",
+    // };
 
-  if (mode === "none") {
-    const BundleAnalyzerPlugin =
-      require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
-    config.plugins.push(new BundleAnalyzerPlugin());
+    serverConfig.plugins.push(
+      new RunNodeWebpackPlugin({ runOnlyInWatchMode: true })
+    );
+  } else if (mode === "none") {
+    const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
+    serverConfig.plugins.push(new BundleAnalyzerPlugin());
   }
 
-  return config;
+  return [serverConfig, clientConfig];
 };
-
-module.exports = (env, properties) => [
-  createServerConfig(env, properties.mode || "development"),
-  createClientConfig(env, properties.mode || "development"),
-];