vite.config.ts 1.3 KB

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