|
| 1 | +import { sentryVitePlugin } from '@sentry/vite-plugin'; |
| 2 | +import { type Plugin } from 'vite'; |
| 3 | +import type { SentryReactRouterPluginOptions } from './types'; |
| 4 | + |
| 5 | +/** |
| 6 | + * Create a custom subset of sentry's vite plugins |
| 7 | + */ |
| 8 | +export async function makeCustomSentryVitePlugins(options: SentryReactRouterPluginOptions): Promise<Plugin[]> { |
| 9 | + const { |
| 10 | + debug, |
| 11 | + sourceMapsUploadOptions, |
| 12 | + unstable_sentryVitePluginOptions, |
| 13 | + bundleSizeOptimizations, |
| 14 | + authToken, |
| 15 | + org, |
| 16 | + project, |
| 17 | + } = options; |
| 18 | + |
| 19 | + const sentryVitePlugins = sentryVitePlugin({ |
| 20 | + authToken: authToken ?? process.env.SENTRY_AUTH_TOKEN, |
| 21 | + bundleSizeOptimizations, |
| 22 | + debug: debug ?? false, |
| 23 | + org: org ?? process.env.SENTRY_ORG, |
| 24 | + project: project ?? process.env.SENTRY_PROJECT, |
| 25 | + telemetry: sourceMapsUploadOptions?.telemetry ?? true, |
| 26 | + _metaOptions: { |
| 27 | + telemetry: { |
| 28 | + metaFramework: 'react-router', |
| 29 | + }, |
| 30 | + }, |
| 31 | + |
| 32 | + ...unstable_sentryVitePluginOptions, |
| 33 | + }) as Plugin[]; |
| 34 | + |
| 35 | + // only use a subset of the plugins as all upload and file deletion tasks will be handled in the buildEnd hook |
| 36 | + return [ |
| 37 | + ...sentryVitePlugins.filter(plugin => { |
| 38 | + return [ |
| 39 | + 'sentry-telemetry-plugin', |
| 40 | + 'sentry-vite-release-injection-plugin', |
| 41 | + 'sentry-release-management-plugin', |
| 42 | + 'sentry-vite-debug-id-injection-plugin', |
| 43 | + ].includes(plugin.name); |
| 44 | + }), |
| 45 | + ]; |
| 46 | +} |
0 commit comments