vite.config.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { defineConfig } from 'vite';
  2. import vue from '@vitejs/plugin-vue';
  3. import path from 'path';
  4. import vueI18n from '@intlify/vite-plugin-vue-i18n';
  5. import dotenv from 'dotenv';
  6. // 加载环境变量
  7. dotenv.config();
  8. interface ImportMetaEnv {
  9. readonly VITE_API_URL: string; // 示例环境变量
  10. }
  11. interface ImportMeta {
  12. readonly env: ImportMetaEnv;
  13. }
  14. export default defineConfig({
  15. plugins: [
  16. vue(),
  17. vueI18n({
  18. include: path.resolve(__dirname, './src/locales/**'),
  19. }),
  20. ],
  21. resolve: {
  22. alias: {
  23. '@': path.resolve(__dirname, './src'),
  24. },
  25. },
  26. optimizeDeps: {
  27. include: ['quill'],
  28. },
  29. define: {
  30. __API_URL__: JSON.stringify(process.env.VITE_API_URL),
  31. __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false'
  32. },
  33. // 配置前端服务地址和端口
  34. server: {
  35. host: '0.0.0.0',
  36. port: 5173,
  37. // 是否开启 https
  38. https: false,
  39. // 设置反向代理,跨域
  40. proxy: {
  41. '/api1': {
  42. // 后台地址
  43. target: 'http://127.0.0.1:8990/',
  44. changeOrigin: true,
  45. rewrite: path => path.replace(/^\/api1/, '')
  46. },
  47. }
  48. },
  49. });