vite.config.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  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. open: true,
  24. proxy: {
  25. // https://cn.vitejs.dev/config/#server-proxy
  26. '/dev-api': {
  27. target: 'http://localhost:8080',
  28. changeOrigin: true,
  29. rewrite: (p) => p.replace(/^\/dev-api/, '')
  30. }
  31. },
  32. },
  33. }
  34. })