This repository has been archived on 2024-03-17. You can view files and clone it, but cannot push or open issues or pull requests.
woj-ui/vite.config.ts

67 lines
2.3 KiB
TypeScript
Raw Normal View History

2023-12-23 16:01:48 +08:00
import react from "@vitejs/plugin-react-swc";
2024-01-28 21:24:02 +08:00
import { defineConfig, Plugin } from "vite";
2023-07-16 19:33:43 +08:00
import { sentryVitePlugin } from "@sentry/vite-plugin";
2023-12-23 16:01:48 +08:00
import packageJson from "./package.json";
2023-07-15 20:55:17 +08:00
2024-01-28 21:24:02 +08:00
// 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"],
];
2023-07-15 20:55:17 +08:00
// https://vitejs.dev/config/
export default defineConfig({
2023-07-16 19:33:43 +08:00
build: { sourcemap: true },
plugins: [
react(),
2024-01-28 21:24:02 +08:00
muteWarningsPlugin(warningsToIgnore),
2023-07-16 19:33:43 +08:00
sentryVitePlugin({
authToken: process.env.SENTRY_AUTH_TOKEN,
2023-12-20 23:23:04 +08:00
org: "0x7f",
2023-07-16 19:33:43 +08:00
project: "woj-ui",
}),
],
2023-12-23 16:01:48 +08:00
define: {
"import.meta.env.PACKAGE_VERSION": JSON.stringify(packageJson.version),
},
2023-07-16 19:33:43 +08:00
});