vite.config.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import {
  2. defineConfig,
  3. loadEnv,
  4. UserConfigExport,
  5. splitVendorChunkPlugin,
  6. } from 'vite';
  7. import react from '@vitejs/plugin-react-swc';
  8. import tsconfigPaths from 'vite-tsconfig-paths';
  9. export default defineConfig(({ mode }) => {
  10. process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
  11. const defaultConfig: UserConfigExport = {
  12. plugins: [react(), tsconfigPaths(), splitVendorChunkPlugin()],
  13. server: {
  14. port: 3000,
  15. },
  16. build: {
  17. outDir: 'build',
  18. },
  19. experimental: {
  20. renderBuiltUrl(
  21. filename: string,
  22. {
  23. hostType,
  24. }: {
  25. hostId: string;
  26. hostType: 'js' | 'css' | 'html';
  27. type: 'asset' | 'public';
  28. }
  29. ) {
  30. if (hostType === 'js') {
  31. return {
  32. runtime: `window.__assetsPathBuilder(${JSON.stringify(filename)})`,
  33. };
  34. }
  35. return filename;
  36. },
  37. },
  38. define: {
  39. 'process.env.NODE_ENV': `"${mode}"`,
  40. 'process.env.VITE_TAG': `"${process.env.VITE_TAG}"`,
  41. 'process.env.VITE_COMMIT': `"${process.env.VITE_COMMIT}"`,
  42. },
  43. };
  44. const proxy = process.env.VITE_DEV_PROXY;
  45. if (mode === 'development' && proxy) {
  46. return {
  47. ...defaultConfig,
  48. server: {
  49. ...defaultConfig.server,
  50. open: true,
  51. proxy: {
  52. '/api': {
  53. target: proxy,
  54. changeOrigin: true,
  55. secure: false,
  56. },
  57. '/actuator/info': {
  58. target: proxy,
  59. changeOrigin: true,
  60. secure: false,
  61. },
  62. },
  63. },
  64. };
  65. }
  66. return defaultConfig;
  67. });