11import { consoleSandbox } from '@sentry/core' ;
22import { sentryVitePlugin } from '@sentry/vite-plugin' ;
3- import type { Plugin , UserConfig } from 'vite' ;
3+ import { loadConfigFromFile , type Plugin , type UserConfig } from 'vite' ;
44import type { SentryReactRouterPluginOptions } from './types' ;
55
66/**
77 * Creates sentry's vite plugins
88 */
9- export function makeSentryVitePlugins ( options : SentryReactRouterPluginOptions , viteConfig : UserConfig ) : Plugin [ ] {
9+ export async function makeSentryVitePlugins ( options : SentryReactRouterPluginOptions ) : Promise < Plugin [ ] > {
1010 const {
1111 debug,
1212 sourceMapsUploadOptions,
@@ -19,11 +19,24 @@ export function makeSentryVitePlugins(options: SentryReactRouterPluginOptions, v
1919
2020 let updatedFilesToDeleteAfterUpload : string [ ] | undefined = undefined ;
2121
22+ let loadedConfig : { path : string ; config : UserConfig ; dependencies : string [ ] } | null = null ;
23+
24+ try {
25+ loadedConfig = await loadConfigFromFile ( { mode : 'production' , command : 'build' } ) ;
26+ } catch ( error ) {
27+ if ( debug ) {
28+ consoleSandbox ( ( ) => {
29+ // eslint-disable-next-line no-console
30+ console . log ( '[Sentry] could not load Vite config during build' ) ;
31+ } ) ;
32+ }
33+ }
34+
2235 if (
2336 typeof sourceMapsUploadOptions ?. filesToDeleteAfterUpload === 'undefined' &&
2437 typeof unstable_sentryVitePluginOptions ?. sourcemaps ?. filesToDeleteAfterUpload === 'undefined' &&
2538 // Only if source maps were previously not set, we update the "filesToDeleteAfterUpload" (as we override the setting with "hidden")
26- typeof viteConfig . build ?. sourcemap === 'undefined'
39+ typeof loadedConfig ?. config . build ?. sourcemap === 'undefined'
2740 ) {
2841 // For .output, .vercel, .netlify etc.
2942 updatedFilesToDeleteAfterUpload = [ '.*/**/*.map' ] ;
@@ -58,6 +71,7 @@ export function makeSentryVitePlugins(options: SentryReactRouterPluginOptions, v
5871 metaFramework : 'react-router' ,
5972 } ,
6073 } ,
74+
6175 ...unstable_sentryVitePluginOptions ,
6276 } ) ,
6377 ] ;
0 commit comments