Skip to content

Commit

Permalink
Merge pull request #241 from kaffolder7/feature/suppress-warnings-pro…
Browse files Browse the repository at this point in the history
…duction-build

Update: Suppress warnings in production build
  • Loading branch information
rajnandan1 authored Feb 5, 2025
2 parents 4fd9bf2 + 559f5bd commit 3b1d95b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
26 changes: 25 additions & 1 deletion svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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;
31 changes: 28 additions & 3 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,38 @@ 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: {
ignored: ["**/src/lib/server/data/**"] // Adjust the path to the file you want to ignore
}
},
assetsInclude: ["**/*.yaml"]
});
}));

0 comments on commit 3b1d95b

Please sign in to comment.