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)
This commit is contained in:
Daniele Basso 2023-07-13 20:05:28 +00:00 committed by Dessalines
parent 196ca6b028
commit df7c4c8e3a
2 changed files with 26 additions and 44 deletions

View file

@ -69,7 +69,6 @@
"jwt-decode": "^3.1.2", "jwt-decode": "^3.1.2",
"lemmy-js-client": "0.18.1", "lemmy-js-client": "0.18.1",
"lodash.isequal": "^4.5.0", "lodash.isequal": "^4.5.0",
"lodash.merge": "^4.6.2",
"markdown-it": "^13.0.1", "markdown-it": "^13.0.1",
"markdown-it-container": "^3.0.0", "markdown-it-container": "^3.0.0",
"markdown-it-emoji": "^2.0.2", "markdown-it-emoji": "^2.0.2",

View file

@ -1,10 +1,9 @@
const webpack = require("webpack"); const webpack = require("webpack");
const path = require("path"); const { resolve } = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const nodeExternals = require("webpack-node-externals"); const nodeExternals = require("webpack-node-externals");
const CopyPlugin = require("copy-webpack-plugin"); const CopyPlugin = require("copy-webpack-plugin");
const RunNodeWebpackPlugin = require("run-node-webpack-plugin"); const RunNodeWebpackPlugin = require("run-node-webpack-plugin");
const merge = require("lodash.merge");
const { ServiceWorkerPlugin } = require("service-worker-webpack"); const { ServiceWorkerPlugin } = require("service-worker-webpack");
const banner = ` const banner = `
@ -14,8 +13,10 @@ const banner = `
@license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0 @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
`; `;
function getBase(env, mode) { module.exports = (env, argv) => {
return { const mode = argv.mode;
const base = {
output: { output: {
filename: "js/server.js", filename: "js/server.js",
publicPath: "/", publicPath: "/",
@ -24,8 +25,8 @@ function getBase(env, mode) {
resolve: { resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"], extensions: [".js", ".jsx", ".ts", ".tsx"],
alias: { alias: {
"@": path.resolve(__dirname, "src/"), "@": resolve(__dirname, "src/"),
"@utils": path.resolve(__dirname, "src/shared/utils/"), "@utils": resolve(__dirname, "src/shared/utils/"),
}, },
}, },
performance: { performance: {
@ -67,40 +68,19 @@ function getBase(env, mode) {
}), }),
], ],
}; };
}
const createServerConfig = (env, mode) => { const serverConfig = {
const base = getBase(env, mode); ...base,
const config = merge({}, base, {
mode,
entry: "./src/server/index.tsx", entry: "./src/server/index.tsx",
output: { output: {
filename: "js/server.js", filename: "js/server.js",
}, },
target: "node", target: "node",
externals: [nodeExternals(), "inferno-helmet"], externals: [nodeExternals(), "inferno-helmet"],
}); };
if (mode === "development") { const clientConfig = {
// config.cache = { ...base,
// 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,
entry: "./src/client/index.tsx", entry: "./src/client/index.tsx",
output: { output: {
filename: "js/client.js", filename: "js/client.js",
@ -158,18 +138,21 @@ const createClientConfig = (env, mode) => {
}, },
}), }),
], ],
}); };
if (mode === "none") { if (mode === "development") {
const BundleAnalyzerPlugin = // serverConfig.cache = {
require("webpack-bundle-analyzer").BundleAnalyzerPlugin; // type: "filesystem",
config.plugins.push(new BundleAnalyzerPlugin()); // name: "server",
// };
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"),
];