@@ -2,13 +2,36 @@ import 'dotenv/config'
22import { reactRouter } from '@react-router/dev/vite'
33import { sentryVitePlugin } from '@sentry/vite-plugin'
44import tailwindcss from '@tailwindcss/vite'
5- import { glob } from 'glob'
65import { defineConfig } from 'vite'
76import { envOnlyMacros } from 'vite-env-only'
87import { cjsInterop } from 'vite-plugin-cjs-interop'
98import tsconfigPaths from 'vite-tsconfig-paths'
109
1110const MODE = process . env . NODE_ENV
11+ const SENTRY_UPLOAD =
12+ process . env . SENTRY_UPLOAD === 'true' || process . env . SENTRY_UPLOAD === '1'
13+
14+ if ( SENTRY_UPLOAD && MODE === 'production' ) {
15+ const authToken = process . env . SENTRY_AUTH_TOKEN
16+ const project = process . env . SENTRY_PROJECT
17+ const org = process . env . SENTRY_ORG
18+ // New-style Sentry auth tokens (prefix "sntrys_") embed the org, so SENTRY_ORG
19+ // is not required when using one.
20+ const tokenImpliesOrg = Boolean ( authToken ?. startsWith ( 'sntrys_' ) )
21+
22+ // If upload is "on" but required settings are missing, the Sentry plugin will
23+ // just warn + skip the upload. Fail fast so we don't silently deploy without
24+ // sourcemaps in Sentry.
25+ if ( ! authToken ) {
26+ throw new Error ( 'SENTRY_UPLOAD is enabled, but SENTRY_AUTH_TOKEN is missing' )
27+ }
28+ if ( ! project ) {
29+ throw new Error ( 'SENTRY_UPLOAD is enabled, but SENTRY_PROJECT is missing' )
30+ }
31+ if ( ! org && ! tokenImpliesOrg ) {
32+ throw new Error ( 'SENTRY_UPLOAD is enabled, but SENTRY_ORG is missing' )
33+ }
34+ }
1235
1336export default defineConfig ( async ( ) => {
1437 return {
@@ -24,28 +47,31 @@ export default defineConfig(async () => {
2447 tailwindcss ( ) ,
2548 reactRouter ( ) ,
2649 tsconfigPaths ( ) ,
27- process . env . SENTRY_UPLOAD
50+ SENTRY_UPLOAD
2851 ? sentryVitePlugin ( {
2952 disable : MODE !== 'production' ,
3053 authToken : process . env . SENTRY_AUTH_TOKEN ,
3154 org : process . env . SENTRY_ORG ,
3255 project : process . env . SENTRY_PROJECT ,
56+ // By default the bundler plugin logs and continues on upload/release
57+ // errors. Fail the build so we don't deploy with broken symbolication.
58+ errorHandler : ( err ) => {
59+ throw err
60+ } ,
3361 release : {
3462 name : process . env . COMMIT_SHA ,
3563 setCommits : {
3664 auto : true ,
3765 } ,
3866 } ,
39- sourcemaps : {
40- filesToDeleteAfterUpload : await glob ( [
41- './build/**/*.map' ,
42- '.server-build/**/*.map' ,
43- ] ) ,
44- } ,
4567 } )
4668 : null ,
4769 ] ,
4870 build : {
71+ // This is an OSS project, so it's fine to generate "regular" sourcemaps.
72+ // If we ever want sourcemaps upload without exposing them publicly, switch
73+ // to `sourcemap: 'hidden'` (and keep uploading to Sentry).
74+ sourcemap : true ,
4975 cssMinify : MODE === 'production' ,
5076 rollupOptions : {
5177 external : [ / n o d e : .* / , 'stream' , 'crypto' ] ,
0 commit comments