vite.config.ts 1.1 KB

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