vite.config.ts 1.3 KB

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