|
| 1 | +import { sentryVitePlugin } from '@sentry/vite-plugin'; |
1 | 2 | import react from '@vitejs/plugin-react'; |
2 | | -import { visualizer } from 'rollup-plugin-visualizer'; |
3 | | -import { defineConfig } from 'vite'; |
| 3 | +import { defineConfig, loadEnv } from 'vite'; |
4 | 4 | import svgr from 'vite-plugin-svgr'; |
5 | 5 | import tsconfigPaths from 'vite-tsconfig-paths'; |
6 | 6 |
|
7 | 7 | const DEFAULT_PORT = 3000; |
8 | 8 |
|
9 | | -export default defineConfig({ |
10 | | - plugins: [react(), tsconfigPaths(), svgr()], |
11 | | - build: { |
12 | | - rollupOptions: { |
13 | | - output: { |
14 | | - manualChunks(id) { |
15 | | - if (!id.includes('node_modules')) return; |
16 | | - |
17 | | - if (id.includes('react-router')) return 'router'; |
18 | | - if (id.includes('react-datepicker')) return 'dates'; |
19 | | - if ( |
20 | | - id.includes('react-markdown') || |
21 | | - id.includes('remark') || |
22 | | - id.includes('rehype') || |
23 | | - id.includes('unified') || |
24 | | - id.includes('micromark') || |
25 | | - id.includes('mdast') || |
26 | | - id.includes('hast') || |
27 | | - id.includes('parse5') |
28 | | - ) { |
29 | | - return 'markdown'; |
30 | | - } |
31 | | - |
32 | | - if ( |
33 | | - id.includes('node_modules/react/') || |
34 | | - id.includes('node_modules/react-dom/') || |
35 | | - id.includes('scheduler') |
36 | | - ) { |
37 | | - return 'react-vendor'; |
38 | | - } |
39 | | - |
40 | | - if (id.includes('zustand')) return 'state'; |
41 | | - if (id.includes('@tanstack/react-query')) return 'react-query'; |
42 | | - |
43 | | - if (id.includes('mixpanel-browser')) return 'analytics'; |
44 | | - if (id.includes('@sentry')) return 'sentry'; |
45 | | - |
46 | | - if (id.includes('framer-motion') || id.includes('motion-dom')) |
47 | | - return 'motion'; |
48 | | - if (id.includes('swiper')) return 'swiper'; |
49 | | - if (id.includes('date-fns')) return 'dates'; |
50 | | - |
51 | | - return 'vendor'; |
| 9 | +export default defineConfig(({ mode }) => { |
| 10 | + const env = loadEnv(mode, process.cwd(), ''); |
| 11 | + |
| 12 | + const isProduction = mode === 'production'; |
| 13 | + const canUploadSentrySourcemaps = |
| 14 | + isProduction && !!env.SENTRY_AUTH_TOKEN && !!env.VITE_SENTRY_RELEASE; |
| 15 | + |
| 16 | + if (isProduction && !canUploadSentrySourcemaps) { |
| 17 | + console.warn( |
| 18 | + '[sentry-vite-plugin] Missing SENTRY_AUTH_TOKEN or VITE_SENTRY_RELEASE. Skipping sourcemap upload.', |
| 19 | + ); |
| 20 | + } |
| 21 | + |
| 22 | + return { |
| 23 | + plugins: [ |
| 24 | + react(), |
| 25 | + tsconfigPaths(), |
| 26 | + svgr(), |
| 27 | + ...(canUploadSentrySourcemaps |
| 28 | + ? [ |
| 29 | + sentryVitePlugin({ |
| 30 | + org: 'moadong', |
| 31 | + project: 'moadong', |
| 32 | + authToken: env.SENTRY_AUTH_TOKEN, |
| 33 | + release: { |
| 34 | + name: env.VITE_SENTRY_RELEASE, |
| 35 | + }, |
| 36 | + sourcemaps: { |
| 37 | + filesToDeleteAfterUpload: [ |
| 38 | + './**/*.map', |
| 39 | + './**/public/**/*.map', |
| 40 | + './dist/**/*.map', |
| 41 | + ], |
| 42 | + }, |
| 43 | + }), |
| 44 | + ] |
| 45 | + : []), |
| 46 | + ], |
| 47 | + build: { |
| 48 | + sourcemap: canUploadSentrySourcemaps ? 'hidden' : false, |
| 49 | + rollupOptions: { |
| 50 | + output: { |
| 51 | + manualChunks(id) { |
| 52 | + if (!id.includes('node_modules')) return; |
| 53 | + |
| 54 | + if (id.includes('react-router')) return 'router'; |
| 55 | + if (id.includes('react-datepicker')) return 'dates'; |
| 56 | + if ( |
| 57 | + id.includes('react-markdown') || |
| 58 | + id.includes('remark') || |
| 59 | + id.includes('rehype') || |
| 60 | + id.includes('unified') || |
| 61 | + id.includes('micromark') || |
| 62 | + id.includes('mdast') || |
| 63 | + id.includes('hast') || |
| 64 | + id.includes('parse5') |
| 65 | + ) { |
| 66 | + return 'markdown'; |
| 67 | + } |
| 68 | + |
| 69 | + if ( |
| 70 | + id.includes('node_modules/react/') || |
| 71 | + id.includes('node_modules/react-dom/') || |
| 72 | + id.includes('scheduler') |
| 73 | + ) { |
| 74 | + return 'react-vendor'; |
| 75 | + } |
| 76 | + |
| 77 | + if (id.includes('zustand')) return 'state'; |
| 78 | + if (id.includes('@tanstack/react-query')) return 'react-query'; |
| 79 | + |
| 80 | + if (id.includes('mixpanel-browser')) return 'analytics'; |
| 81 | + if (id.includes('@sentry')) return 'sentry'; |
| 82 | + |
| 83 | + if (id.includes('framer-motion') || id.includes('motion-dom')) |
| 84 | + return 'motion'; |
| 85 | + if (id.includes('swiper')) return 'swiper'; |
| 86 | + if (id.includes('date-fns')) return 'dates'; |
| 87 | + |
| 88 | + return 'vendor'; |
| 89 | + }, |
52 | 90 | }, |
53 | 91 | }, |
54 | 92 | }, |
55 | | - }, |
56 | | - server: { |
57 | | - port: DEFAULT_PORT, |
58 | | - }, |
| 93 | + server: { |
| 94 | + port: DEFAULT_PORT, |
| 95 | + }, |
| 96 | + }; |
59 | 97 | }); |
0 commit comments