| 
									
										
										
										
											2025-07-14 15:25:55 -07:00
										 |  |  | import { codecovVitePlugin } from '@codecov/vite-plugin'; | 
					
						
							|  |  |  | import react from '@vitejs/plugin-react-swc'; | 
					
						
							| 
									
										
										
										
											2024-01-03 17:16:16 -05:00
										 |  |  | import * as path from 'path'; | 
					
						
							|  |  |  | import { defineConfig, loadEnv } from 'vite'; | 
					
						
							|  |  |  | import macrosPlugin from 'vite-plugin-babel-macros'; | 
					
						
							| 
									
										
										
										
											2025-04-16 16:55:38 -07:00
										 |  |  | import svgr from 'vite-plugin-svgr'; | 
					
						
							| 
									
										
										
										
											2024-01-03 17:16:16 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-25 08:46:51 -03:00
										 |  |  | const injectMeticulous = () => { | 
					
						
							|  |  |  |     if (!process.env.REACT_APP_METICULOUS_PROJECT_TOKEN) { | 
					
						
							|  |  |  |         return null; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |         name: 'inject-meticulous', | 
					
						
							|  |  |  |         transformIndexHtml: { | 
					
						
							|  |  |  |             transform(html) { | 
					
						
							|  |  |  |                 const scriptTag = `
 | 
					
						
							|  |  |  |                     <script | 
					
						
							|  |  |  |                         data-recording-token=${process.env.REACT_APP_METICULOUS_PROJECT_TOKEN} | 
					
						
							|  |  |  |                         src="https://snippet.meticulous.ai/v1/meticulous.js"> | 
					
						
							|  |  |  |                     </script> | 
					
						
							|  |  |  |                 `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return html.replace('</head>', `${scriptTag}\n</head>`); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-01 11:08:38 -05:00
										 |  |  | // since we have base: './' for relative paths, vite will set static assets at "./assets/..."
 | 
					
						
							|  |  |  | // with a base path configured we can't find them. We want simple "assets/..."
 | 
					
						
							|  |  |  | export function stripDotSlashFromAssets() { | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |         name: 'strip-dot-slash', | 
					
						
							|  |  |  |         transformIndexHtml(html) { | 
					
						
							|  |  |  |             return html.replace(/src="\.\//g, 'src="').replace(/href="\.\//g, 'href="'); | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-03 17:16:16 -05:00
										 |  |  | // https://vitejs.dev/config/
 | 
					
						
							| 
									
										
										
										
											2025-07-14 15:25:55 -07:00
										 |  |  | export default defineConfig(async ({ mode }) => { | 
					
						
							|  |  |  |     const { viteStaticCopy } = await import('vite-plugin-static-copy'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-03 17:16:16 -05:00
										 |  |  |     // Via https://stackoverflow.com/a/66389044.
 | 
					
						
							|  |  |  |     const env = loadEnv(mode, process.cwd(), ''); | 
					
						
							|  |  |  |     process.env = { ...process.env, ...env }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-14 15:25:55 -07:00
										 |  |  |     const themeConfigFile = `./src/conf/theme/${process.env.REACT_APP_THEME_CONFIG}`; | 
					
						
							| 
									
										
										
										
											2024-01-03 17:16:16 -05:00
										 |  |  |     // eslint-disable-next-line global-require, import/no-dynamic-require, @typescript-eslint/no-var-requires
 | 
					
						
							| 
									
										
										
										
											2025-07-14 15:25:55 -07:00
										 |  |  |     const themeConfig = require(themeConfigFile); | 
					
						
							| 
									
										
										
										
											2024-01-03 17:16:16 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Setup proxy to the datahub-frontend service.
 | 
					
						
							|  |  |  |     const frontendProxy = { | 
					
						
							|  |  |  |         target: process.env.REACT_APP_PROXY_TARGET || 'http://localhost:9002', | 
					
						
							|  |  |  |         changeOrigin: true, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     const proxyOptions = { | 
					
						
							|  |  |  |         '/logIn': frontendProxy, | 
					
						
							|  |  |  |         '/authenticate': frontendProxy, | 
					
						
							|  |  |  |         '/api/v2/graphql': frontendProxy, | 
					
						
							| 
									
										
										
										
											2025-06-23 17:01:38 +05:30
										 |  |  |         '/openapi/v1/tracking/track': frontendProxy, | 
					
						
							| 
									
										
										
										
											2024-01-03 17:16:16 -05:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-25 08:46:51 -03:00
										 |  |  |     const devPlugins = mode === 'development' ? [injectMeticulous()] : []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-03 17:16:16 -05:00
										 |  |  |     return { | 
					
						
							| 
									
										
										
										
											2024-03-26 17:18:54 -07:00
										 |  |  |         appType: 'spa', | 
					
						
							| 
									
										
										
										
											2025-10-01 11:08:38 -05:00
										 |  |  |         base: './', // Always use root - runtime base path detection handles deployment paths
 | 
					
						
							| 
									
										
										
										
											2024-01-03 17:16:16 -05:00
										 |  |  |         plugins: [ | 
					
						
							| 
									
										
										
										
											2025-03-25 08:46:51 -03:00
										 |  |  |             ...devPlugins, | 
					
						
							| 
									
										
										
										
											2024-01-03 17:16:16 -05:00
										 |  |  |             react(), | 
					
						
							|  |  |  |             svgr(), | 
					
						
							|  |  |  |             macrosPlugin(), | 
					
						
							|  |  |  |             viteStaticCopy({ | 
					
						
							|  |  |  |                 targets: [ | 
					
						
							|  |  |  |                     // Self-host images by copying them to the build directory
 | 
					
						
							|  |  |  |                     { src: path.resolve(__dirname, 'src/images/*'), dest: 'assets/platforms' }, | 
					
						
							|  |  |  |                     // Also keep the theme json files in the build directory
 | 
					
						
							|  |  |  |                     { src: path.resolve(__dirname, 'src/conf/theme/*.json'), dest: 'assets/conf/theme' }, | 
					
						
							|  |  |  |                 ], | 
					
						
							|  |  |  |             }), | 
					
						
							|  |  |  |             viteStaticCopy({ | 
					
						
							|  |  |  |                 targets: [ | 
					
						
							|  |  |  |                     // Copy monaco-editor files to the build directory
 | 
					
						
							|  |  |  |                     // Because of the structured option, specifying dest .
 | 
					
						
							|  |  |  |                     // means that it will mirror the node_modules/... structure
 | 
					
						
							|  |  |  |                     // in the build directory.
 | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         src: 'node_modules/monaco-editor/min/vs/', | 
					
						
							|  |  |  |                         dest: '.', | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         src: 'node_modules/monaco-editor/min-maps/vs/', | 
					
						
							|  |  |  |                         dest: '.', | 
					
						
							|  |  |  |                         rename: (name, ext, fullPath) => { | 
					
						
							|  |  |  |                             console.log(name, ext, fullPath); | 
					
						
							|  |  |  |                             return name; | 
					
						
							|  |  |  |                         }, | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                 ], | 
					
						
							|  |  |  |                 structured: true, | 
					
						
							|  |  |  |             }), | 
					
						
							| 
									
										
										
										
											2025-05-27 15:21:04 -04:00
										 |  |  |             codecovVitePlugin({ | 
					
						
							|  |  |  |                 enableBundleAnalysis: true, | 
					
						
							| 
									
										
										
										
											2025-07-14 15:25:55 -07:00
										 |  |  |                 bundleName: 'datahub-react-web', | 
					
						
							| 
									
										
										
										
											2025-05-27 15:21:04 -04:00
										 |  |  |                 uploadToken: process.env.CODECOV_TOKEN, | 
					
						
							| 
									
										
										
										
											2025-07-14 15:25:55 -07:00
										 |  |  |                 gitService: 'github', | 
					
						
							| 
									
										
										
										
											2025-05-27 15:21:04 -04:00
										 |  |  |             }), | 
					
						
							| 
									
										
										
										
											2025-10-01 11:08:38 -05:00
										 |  |  |             stripDotSlashFromAssets(), | 
					
						
							| 
									
										
										
										
											2024-01-03 17:16:16 -05:00
										 |  |  |         ], | 
					
						
							|  |  |  |         // optimizeDeps: {
 | 
					
						
							|  |  |  |         //     include: ['@ant-design/colors', '@ant-design/icons', 'lodash-es', '@ant-design/icons/es/icons'],
 | 
					
						
							|  |  |  |         // },
 | 
					
						
							|  |  |  |         envPrefix: 'REACT_APP_', | 
					
						
							|  |  |  |         build: { | 
					
						
							|  |  |  |             outDir: 'dist', | 
					
						
							| 
									
										
										
										
											2024-12-31 08:50:44 -06:00
										 |  |  |             target: 'esnext', | 
					
						
							|  |  |  |             minify: 'esbuild', | 
					
						
							|  |  |  |             reportCompressedSize: false, | 
					
						
							|  |  |  |             // Limit number of worker threads to reduce CPU pressure
 | 
					
						
							|  |  |  |             workers: 3, // default is number of CPU cores
 | 
					
						
							| 
									
										
										
										
											2024-01-03 17:16:16 -05:00
										 |  |  |         }, | 
					
						
							|  |  |  |         server: { | 
					
						
							|  |  |  |             open: false, | 
					
						
							|  |  |  |             host: false, | 
					
						
							|  |  |  |             port: 3000, | 
					
						
							|  |  |  |             proxy: proxyOptions, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         css: { | 
					
						
							|  |  |  |             preprocessorOptions: { | 
					
						
							|  |  |  |                 less: { | 
					
						
							|  |  |  |                     javascriptEnabled: true, | 
					
						
							|  |  |  |                     // Override antd theme variables.
 | 
					
						
							|  |  |  |                     // https://4x.ant.design/docs/react/customize-theme#Ant-Design-Less-variables
 | 
					
						
							|  |  |  |                     modifyVars: themeConfig.styles, | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         test: { | 
					
						
							|  |  |  |             globals: true, | 
					
						
							|  |  |  |             environment: 'jsdom', | 
					
						
							|  |  |  |             setupFiles: './src/setupTests.ts', | 
					
						
							|  |  |  |             css: true, | 
					
						
							|  |  |  |             // reporters: ['verbose'],
 | 
					
						
							|  |  |  |             coverage: { | 
					
						
							| 
									
										
										
										
											2025-02-19 10:50:13 -08:00
										 |  |  |                 enabled: true, | 
					
						
							|  |  |  |                 provider: 'v8', | 
					
						
							| 
									
										
										
										
											2024-01-03 17:16:16 -05:00
										 |  |  |                 reporter: ['text', 'json', 'html'], | 
					
						
							| 
									
										
										
										
											2025-08-11 13:36:30 -04:00
										 |  |  |                 include: ['src/**/*.ts'], | 
					
						
							| 
									
										
										
										
											2025-02-19 10:50:13 -08:00
										 |  |  |                 reportsDirectory: '../build/coverage-reports/datahub-web-react/', | 
					
						
							| 
									
										
										
										
											2024-01-03 17:16:16 -05:00
										 |  |  |                 exclude: [], | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2024-12-10 15:06:57 -05:00
										 |  |  |         resolve: { | 
					
						
							|  |  |  |             alias: { | 
					
						
							|  |  |  |                 // Root Directories
 | 
					
						
							|  |  |  |                 '@src': path.resolve(__dirname, '/src'), | 
					
						
							|  |  |  |                 '@app': path.resolve(__dirname, '/src/app'), | 
					
						
							|  |  |  |                 '@conf': path.resolve(__dirname, '/src/conf'), | 
					
						
							|  |  |  |                 '@components': path.resolve(__dirname, 'src/alchemy-components'), | 
					
						
							|  |  |  |                 '@graphql': path.resolve(__dirname, 'src/graphql'), | 
					
						
							|  |  |  |                 '@graphql-mock': path.resolve(__dirname, 'src/graphql-mock'), | 
					
						
							|  |  |  |                 '@images': path.resolve(__dirname, 'src/images'), | 
					
						
							|  |  |  |                 '@providers': path.resolve(__dirname, 'src/providers'), | 
					
						
							|  |  |  |                 '@utils': path.resolve(__dirname, 'src/utils'), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // Specific Files
 | 
					
						
							|  |  |  |                 '@types': path.resolve(__dirname, 'src/types.generated.ts'), | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2024-01-03 17:16:16 -05:00
										 |  |  |     }; | 
					
						
							|  |  |  | }); |