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"] -}); +}));