vite.config.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. build: {
  9. outDir: 'build',
  10. rollupOptions: {
  11. output: {
  12. manualChunks: {
  13. venod: [
  14. 'react',
  15. 'react-router-dom',
  16. 'react-dom',
  17. 'redux',
  18. 'redux-thunk',
  19. 'react-redux',
  20. 'styled-components',
  21. 'react-ace',
  22. ],
  23. },
  24. },
  25. },
  26. },
  27. define: {
  28. 'process.env.NODE_ENV': `"${mode}"`,
  29. 'process.env.VITE_TAG': `"${process.env.VITE_TAG}"`,
  30. 'process.env.GIT_COMMIT': `"${process.env.VITE_COMMIT}"`,
  31. },
  32. };
  33. const proxy = process.env.VITE_DEV_PROXY;
  34. if (mode === 'development' && proxy) {
  35. return {
  36. ...defaultConfig,
  37. server: {
  38. open: true,
  39. proxy: {
  40. '/api': {
  41. target: proxy,
  42. changeOrigin: true,
  43. secure: false,
  44. },
  45. },
  46. },
  47. };
  48. }
  49. return defaultConfig;
  50. });