vite.config.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { defineConfig, loadEnv } from 'vite';
  2. import vue from '@vitejs/plugin-vue';
  3. import path from "path";
  4. import { viteMockServe } from 'vite-plugin-mock';
  5. import Components from 'unplugin-vue-components/vite';
  6. import { VantResolver } from 'unplugin-vue-components/resolvers';
  7. // https://vitejs.dev/config/
  8. export default defineConfig(({ command, mode }) => {
  9. // 检查process.cwd()路径下.env.develeport.local、.env.development、.env.local、.env这四个环境文件
  10. loadEnv(mode, process.cwd());
  11. return {
  12. // 静态资源基础路径 base: './' || '',
  13. base: '',
  14. resolve: {
  15. alias: {
  16. // 配置src目录
  17. "@": path.resolve(__dirname, "src"),
  18. // 导入其他目录
  19. "components": path.resolve(__dirname, "components")
  20. }
  21. },
  22. plugins: [
  23. vue(),
  24. Components({
  25. resolvers: [VantResolver()],
  26. }),
  27. viteMockServe({
  28. mockPath: './mock',
  29. supportTs: true,
  30. localEnabled: false
  31. })
  32. ],
  33. // 跨域代理
  34. server: {
  35. host: '0.0.0.0',
  36. proxy: {
  37. '/api': {
  38. target: 'https://api.inews.qq.com',
  39. changeOrigin: true,
  40. rewrite: (path) => path.replace(/^\/api/, '') // 将匹配到的api替换成''
  41. }
  42. }
  43. }
  44. };
  45. });