diff --git a/vite.config.ts b/vite.config.ts index a5e8d94..91b159f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,13 +1,59 @@ import react from "@vitejs/plugin-react-swc"; -import { defineConfig } from "vite"; +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",