From 1b93e3190b19c58dc0258a70a6d18c7cf3137cfe Mon Sep 17 00:00:00 2001
From: Thomas Hutterer <thutterer@gitlab.com>
Date: Tue, 12 Dec 2023 15:52:44 +0000
Subject: [PATCH] Add vite file watcher ignore config

This makes sure we only watch relevant files and avoids the
"number of file watchers reached" issues seen on Linux systems.

With a custom function we can stop vite from starting recursing down
the whole root folder. This makes the whole thing way more efficient.

We use config/vite.json to define additional paths we want watched.
---
 config/vite.json |  7 +++++++
 vite.config.js   | 16 ++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/config/vite.json b/config/vite.json
index 14b5da38ab26..178f978687fb 100644
--- a/config/vite.json
+++ b/config/vite.json
@@ -1,6 +1,13 @@
 {
   "all": {
     "sourceCodeDir": "app/assets",
+    "watchAdditionalPaths": [
+      "app/graphql/queries",
+      "app/assets",
+      "ee/app/assets",
+      "jh/app/assets",
+      "vendor/assets"
+    ],
     "entrypointsDir": "javascripts/entrypoints",
     "port": 3038,
     "publicOutputDir": "vite-dev",
diff --git a/vite.config.js b/vite.config.js
index 88d264531a63..b70478abe967 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -128,5 +128,21 @@ export default defineConfig({
       protocol: 'ws',
     },
     https: false,
+    watch: {
+      ignored: [
+        '**/*.stories.js',
+        function ignoreRootFolder(x) {
+          /*
+           `vite` watches the root folder of gitlab and all of its sub folders
+           This is not what we want, because we have temp files, and all kind
+           of other stuff. As vite starts its watchers recursively, we just
+           ignore if the path matches exactly the root folder
+
+           Additional folders like `ee/app/assets` are defined in
+           */
+          return x === __dirname;
+        },
+      ],
+    },
   },
 });
-- 
GitLab