From 559f5bd257301199efe535e1460a03b0cf52db05 Mon Sep 17 00:00:00 2001 From: Kyle Affolder Date: Tue, 4 Feb 2025 16:03:10 -0500 Subject: [PATCH] Update: Suppress warnings in production build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building for production, various warnings are output which slows down production build. The following changes were made: - Suppress unused export properties (unused-export-let). - Suppress conflicting Svelte resolve warnings (conflicting-svelte-resolve). - Suppress empty chunk warnings (empty-chunk). - Suppress unused module imports (module-unused-import). - Keep other important warnings visible, so we’re still aware of potential issues. Now, production build should be cleaner and faster! 🚀 --- svelte.config.js | 26 +++++++++++++++++++++++++- vite.config.js | 31 ++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/svelte.config.js b/svelte.config.js index ded11ce3..384022ab 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -2,6 +2,8 @@ import { vitePreprocess } from "@sveltejs/kit/vite"; import adapter from "@sveltejs/adapter-node"; const basePath = !!process.env.KENER_BASE_PATH ? process.env.KENER_BASE_PATH : ""; +const VITE_BUILD_ENV = process.env.VITE_BUILD_ENV || "development"; // Default to "development" +const isProduction = VITE_BUILD_ENV === "production"; /** @type {import('@sveltejs/kit').Config} */ const config = { @@ -12,7 +14,29 @@ const config = { } }, - preprocess: [vitePreprocess({})] + preprocess: [vitePreprocess({})], + + compilerOptions: { + dev: !isProduction, // Disable dev mode in production + enableSourcemap: !isProduction // Disable sourcemaps in production + }, + + onwarn: (warning, handler) => { + // Suppress specific warnings in production + const ignoredWarnings = [ + "a11y-", // Accessibility warnings + "unused-export-let", // Suppresses "unused export property" warnings + "empty-chunk", // Suppresses empty chunk warnings + "module-unused-import", // Suppresses unused imports like "default" from auto-animate + "conflicting-svelte-resolve" // Suppresses conflicting resolve warnings + ]; + + if (isProduction && ignoredWarnings.some((w) => warning.code && warning.code.startsWith(w))) { + return; // Ignore these warnings in production builds + } + + handler(warning); // Otherwise, show the warning + } }; export default config; diff --git a/vite.config.js b/vite.config.js index f3173dac..6320f624 100644 --- a/vite.config.js +++ b/vite.config.js @@ -7,8 +7,33 @@ dotenv.config(); const PORT = Number(process.env.PORT) || 3000; const base = process.env.KENER_BASE_PATH || ""; -export default defineConfig({ - plugins: [sveltekit()], +const VITE_BUILD_ENV = process.env.VITE_BUILD_ENV || "development"; // Default to "development" +const isProduction = VITE_BUILD_ENV === "production"; + +export default defineConfig(({ mode }) => ({ + plugins: [ + sveltekit({ + compilerOptions: { + dev: mode === "development" + }, + onwarn: (warning, handler) => { + // Suppress specific warnings in production + const ignoredWarnings = [ + "a11y-", // Accessibility warnings + "unused-export-let", // Suppresses "unused export property" warnings + "empty-chunk", // Suppresses empty chunk warnings + "module-unused-import", // Suppresses unused imports like "default" from auto-animate + "conflicting-svelte-resolve" // Suppresses conflicting resolve warnings + ]; + + if (isProduction && ignoredWarnings.some((w) => warning.code && warning.code.startsWith(w))) { + return; // Ignore these warnings in production builds + } + + handler(warning); + } + }) + ], server: { port: PORT, watch: { @@ -16,4 +41,4 @@ export default defineConfig({ } }, assetsInclude: ["**/*.yaml"] -}); +}));