vite.config.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. import { ViteEjsPlugin } from 'vite-plugin-ejs';
  10. export default defineConfig(({ mode }) => {
  11. process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
  12. const defaultConfig: UserConfigExport = {
  13. plugins: [
  14. react(),
  15. tsconfigPaths(),
  16. splitVendorChunkPlugin(),
  17. ViteEjsPlugin({
  18. PUBLIC_PATH: mode !== 'development' ? 'PUBLIC-PATH-VARIABLE' : '',
  19. }),
  20. ],
  21. server: {
  22. port: 3000,
  23. },
  24. build: {
  25. outDir: 'build',
  26. rollupOptions: {
  27. output: {
  28. manualChunks: {
  29. ace: ['ace-builds', 'react-ace'],
  30. },
  31. },
  32. },
  33. },
  34. experimental: {
  35. renderBuiltUrl(
  36. filename: string,
  37. {
  38. hostType,
  39. }: {
  40. hostId: string;
  41. hostType: 'js' | 'css' | 'html';
  42. type: 'asset' | 'public';
  43. }
  44. ) {
  45. if (hostType === 'js') {
  46. return {
  47. runtime: `window.__assetsPathBuilder(${JSON.stringify(filename)})`,
  48. };
  49. }
  50. return filename;
  51. },
  52. },
  53. define: {
  54. 'process.env.NODE_ENV': `"${mode}"`,
  55. 'process.env.VITE_TAG': `"${process.env.VITE_TAG}"`,
  56. 'process.env.VITE_COMMIT': `"${process.env.VITE_COMMIT}"`,
  57. },
  58. };
  59. const proxy = process.env.VITE_DEV_PROXY;
  60. if (mode === 'development' && proxy) {
  61. return {
  62. ...defaultConfig,
  63. server: {
  64. ...defaultConfig.server,
  65. open: true,
  66. proxy: {
  67. '/api': {
  68. target: proxy,
  69. changeOrigin: true,
  70. secure: false,
  71. },
  72. '/actuator/info': {
  73. target: proxy,
  74. changeOrigin: true,
  75. secure: false,
  76. },
  77. },
  78. },
  79. };
  80. }
  81. return defaultConfig;
  82. });