vite.config.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { defineConfig, loadEnv, UserConfigExport } from 'vite';
  2. import react from '@vitejs/plugin-react';
  3. import tsconfigPaths from 'vite-tsconfig-paths';
  4. export default defineConfig(({ mode }) => {
  5. process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
  6. const defaultConfig: UserConfigExport = {
  7. plugins: [react(), tsconfigPaths()],
  8. server: {
  9. port: 3000,
  10. },
  11. build: {
  12. outDir: 'build',
  13. rollupOptions: {
  14. output: {
  15. manualChunks: {
  16. vendor: [
  17. 'react',
  18. 'react-router-dom',
  19. 'react-dom',
  20. 'redux',
  21. 'react-redux',
  22. 'styled-components',
  23. 'react-ace',
  24. ],
  25. },
  26. },
  27. },
  28. },
  29. define: {
  30. 'process.env.NODE_ENV': `"${mode}"`,
  31. 'process.env.VITE_TAG': `"${process.env.VITE_TAG}"`,
  32. 'process.env.VITE_COMMIT': `"${process.env.VITE_COMMIT}"`,
  33. },
  34. };
  35. const proxy = process.env.VITE_DEV_PROXY;
  36. if (mode === 'development' && proxy) {
  37. return {
  38. ...defaultConfig,
  39. server: {
  40. ...defaultConfig.server,
  41. open: true,
  42. proxy: {
  43. '/api': {
  44. target: proxy,
  45. changeOrigin: true,
  46. secure: false,
  47. },
  48. },
  49. },
  50. };
  51. }
  52. return defaultConfig;
  53. });