import react from "@vitejs/plugin-react-swc"; import { defineConfig, Plugin } from "vite"; import { sentryVitePlugin } from "@sentry/vite-plugin"; import packageJson from "./package.json"; // https://github.com/vitejs/vite/issues/15012#issuecomment-1825035992 const muteWarningsPlugin = (warningsToIgnore: string[][]): Plugin => { const mutedMessages = new Set(); return { name: "mute-warnings", enforce: "pre", config: (userConfig) => ({ build: { rollupOptions: { onwarn(warning, defaultHandler) { if (warning.code) { const muted = warningsToIgnore.find( ([code, message]) => code == warning.code && warning.message.includes(message), ); if (muted) { mutedMessages.add(muted.join()); return; } } if (userConfig.build?.rollupOptions?.onwarn) { userConfig.build.rollupOptions.onwarn(warning, defaultHandler); } else { defaultHandler(warning); } }, }, }, }), closeBundle() { const diff = warningsToIgnore.filter((x) => !mutedMessages.has(x.join())); if (diff.length > 0) { this.warn("Some of your muted warnings never appeared during the build process:"); diff.forEach((m) => this.warn(`- ${m.join(": ")}`)); } }, }; }; const warningsToIgnore = [ ["SOURCEMAP_ERROR", "Can't resolve original location of error"], ["INVALID_ANNOTATION", "contains an annotation that Rollup cannot interpret"], ]; // https://vitejs.dev/config/ export default defineConfig({ build: { sourcemap: true }, plugins: [ react(), muteWarningsPlugin(warningsToIgnore), sentryVitePlugin({ authToken: process.env.SENTRY_AUTH_TOKEN, org: "0x7f", project: "woj-ui", }), ], define: { "import.meta.env.PACKAGE_VERSION": JSON.stringify(packageJson.version), }, });