chore: mute rollup warnings
This commit is contained in:
parent
e1182a64e4
commit
55d8dee557
@ -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",
|
||||
|
Reference in New Issue
Block a user