From fe47357160496b888292af902422e45fb7137488 Mon Sep 17 00:00:00 2001
From: Marcus Schiesser <mail@marcusschiesser.de>
Date: Tue, 12 Mar 2024 11:10:31 +0700
Subject: [PATCH] refactor: use a function for webpack config (#634)

---
 templates/types/streaming/nextjs/next.config.json   |  8 --------
 templates/types/streaming/nextjs/next.config.mjs    |  9 ++-------
 templates/types/streaming/nextjs/webpack.config.mjs | 10 ++++++++++
 3 files changed, 12 insertions(+), 15 deletions(-)
 create mode 100644 templates/types/streaming/nextjs/webpack.config.mjs

diff --git a/templates/types/streaming/nextjs/next.config.json b/templates/types/streaming/nextjs/next.config.json
index 64b603e1..264e20ef 100644
--- a/templates/types/streaming/nextjs/next.config.json
+++ b/templates/types/streaming/nextjs/next.config.json
@@ -3,13 +3,5 @@
     "outputFileTracingIncludes": {
       "/*": ["./cache/**/*"]
     }
-  },
-  "webpack": {
-    "resolve": {
-      "alias": {
-        "sharp$": false,
-        "onnxruntime-node$": false
-      }
-    }
   }
 }
diff --git a/templates/types/streaming/nextjs/next.config.mjs b/templates/types/streaming/nextjs/next.config.mjs
index f6224537..124122bf 100644
--- a/templates/types/streaming/nextjs/next.config.mjs
+++ b/templates/types/streaming/nextjs/next.config.mjs
@@ -1,13 +1,8 @@
 /** @type {import('next').NextConfig} */
 import fs from "fs";
-import _ from "lodash";
+import webpack from "./webpack.config.mjs";
 
 const nextConfig = JSON.parse(fs.readFileSync("./next.config.json", "utf-8"));
-const webpackConfig = _.cloneDeep(nextConfig.webpack);
-
-// webpack config must be a function in NextJS, to use a JSON as config, we merge the settings from next.config.json
-nextConfig.webpack = (config) => {
-  return _.merge(config, webpackConfig);
-};
+nextConfig.webpack = webpack;
 
 export default nextConfig;
diff --git a/templates/types/streaming/nextjs/webpack.config.mjs b/templates/types/streaming/nextjs/webpack.config.mjs
new file mode 100644
index 00000000..57fa19cf
--- /dev/null
+++ b/templates/types/streaming/nextjs/webpack.config.mjs
@@ -0,0 +1,10 @@
+// webpack config must be a function in NextJS that is used to patch the default webpack config provided by NextJS, see https://nextjs.org/docs/pages/api-reference/next-config-js/webpack
+export default function webpack(config) {
+  // See https://webpack.js.org/configuration/resolve/#resolvealias
+  config.resolve.alias = {
+    ...config.resolve.alias,
+    sharp$: false,
+    "onnxruntime-node$": false,
+  };
+  return config;
+}
-- 
GitLab