vite.config.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. },
  27. experimental: {
  28. renderBuiltUrl(
  29. filename: string,
  30. {
  31. hostType,
  32. }: {
  33. hostId: string;
  34. hostType: 'js' | 'css' | 'html';
  35. type: 'asset' | 'public';
  36. }
  37. ) {
  38. if (hostType === 'js') {
  39. return {
  40. runtime: `window.__assetsPathBuilder(${JSON.stringify(filename)})`,
  41. };
  42. }
  43. return filename;
  44. },
  45. },
  46. define: {
  47. 'process.env.NODE_ENV': `"${mode}"`,
  48. 'process.env.VITE_TAG': `"${process.env.VITE_TAG}"`,
  49. 'process.env.VITE_COMMIT': `"${process.env.VITE_COMMIT}"`,
  50. },
  51. };
  52. const proxy = process.env.VITE_DEV_PROXY;
  53. if (mode === 'development' && proxy) {
  54. return {
  55. ...defaultConfig,
  56. server: {
  57. ...defaultConfig.server,
  58. open: true,
  59. proxy: {
  60. '/api': {
  61. target: proxy,
  62. changeOrigin: true,
  63. secure: false,
  64. },
  65. '/actuator/info': {
  66. target: proxy,
  67. changeOrigin: true,
  68. secure: false,
  69. },
  70. },
  71. },
  72. };
  73. }
  74. return defaultConfig;
  75. });