From 2f486132946ee19aa15a115bfb72f40532eb88d7 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 22 Jan 2026 15:52:01 -0800 Subject: [PATCH] Ensure the vite watcher isn't tyring to watch every single file in the whole project. This fixes the memory leak. Added type module to the script so imports work. Fixes #908 --- .../src/components/shared/layout_head.cr.ecr | 2 +- src/browser_app_skeleton/vite.config.js.ecr | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/browser_app_skeleton/src/components/shared/layout_head.cr.ecr b/src/browser_app_skeleton/src/components/shared/layout_head.cr.ecr index 5a053315..f4de97b3 100644 --- a/src/browser_app_skeleton/src/components/shared/layout_head.cr.ecr +++ b/src/browser_app_skeleton/src/components/shared/layout_head.cr.ecr @@ -6,7 +6,7 @@ class Shared::LayoutHead < BaseComponent utf8_charset title "My App - #{@page_title}" css_link asset("css/app.css") - js_link asset("js/app.js"), defer: "true" + js_link asset("js/app.js"), defer: "true", type: "module" csrf_meta_tags responsive_meta_tag diff --git a/src/browser_app_skeleton/vite.config.js.ecr b/src/browser_app_skeleton/vite.config.js.ecr index 2ee711ab..a9405e5f 100644 --- a/src/browser_app_skeleton/vite.config.js.ecr +++ b/src/browser_app_skeleton/vite.config.js.ecr @@ -32,7 +32,7 @@ export default defineConfig({ // Asset output configuration assetsDir: 'assets', // Source maps for production - sourcemap: process.env.NODE_ENV === 'production' ? false : 'inline' + sourcemap: process.env.NODE_ENV === "production" ? false : true, }, // CSS configuration @@ -49,7 +49,18 @@ export default defineConfig({ // Enable HMR hmr: { host: 'localhost' - } + }, + // Exclude non-frontend directories from file watching to prevent memory leaks + watch: { + ignored: [ + "**", // Ignore all files and subdirectories in the root + "!**/src/js/**", // Re-include the 'src/js' directory + "!**/src/css/**", // Re-include the 'src/css' directory + "!**/public/**", // Re-include the 'public' directory + "!**/vite.config.js", // Ensure the config file itself is watched + // Add other specific folders you want to watch with the '!**/{folderName}/**' pattern + ], + }, }, // Preview server configuration (for testing production builds)