vite.config.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { defineConfig, loadEnv } from 'vite'
  2. import path from 'path'
  3. import createVitePlugins from './vite/plugins'
  4. // https://vitejs.dev/config/
  5. export default defineConfig(({ mode, command }) => {
  6. const env = loadEnv(mode, process.cwd())
  7. return {
  8. plugins: createVitePlugins(env, command === 'build'),
  9. resolve: {
  10. // https://cn.vitejs.dev/config/#resolve-alias
  11. alias: {
  12. // 设置路径
  13. '~': path.resolve(__dirname, './'),
  14. // 设置别名
  15. '@': path.resolve(__dirname, './src')
  16. },
  17. // https://cn.vitejs.dev/config/#resolve-extensions
  18. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  19. },
  20. // vite 相关配置
  21. server: {
  22. port: 80,
  23. host: true,
  24. open: true,
  25. proxy: {
  26. // https://cn.vitejs.dev/config/#server-proxy
  27. '/dev-api': {
  28. target: 'http://localhost:8080',
  29. changeOrigin: true,
  30. rewrite: (p) => p.replace(/^\/dev-api/, '')
  31. }
  32. },
  33. },
  34. }
  35. })