vite.config.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. lodash: ['lodash'],
  24. },
  25. },
  26. },
  27. },
  28. define: {
  29. 'process.env.NODE_ENV': `"${mode}"`,
  30. 'process.env.VITE_TAG': `"${process.env.VITE_TAG}"`,
  31. 'process.env.GIT_COMMIT': `"${process.env.VITE_COMMIT}"`,
  32. },
  33. };
  34. const proxy = process.env.VITE_DEV_PROXY;
  35. if (mode === 'development' && proxy) {
  36. return {
  37. ...defaultConfig,
  38. server: {
  39. open: true,
  40. proxy: {
  41. '/api': {
  42. target: proxy,
  43. changeOrigin: true,
  44. secure: false,
  45. },
  46. },
  47. },
  48. };
  49. }
  50. return defaultConfig;
  51. });