vite.config.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import path from "path";
  2. import { defineConfig } from "vite";
  3. import vue from "@vitejs/plugin-vue";
  4. import Components from "unplugin-vue-components/vite";
  5. import { VantResolver } from "unplugin-vue-components/resolvers";
  6. import { postcssConfig } from "./postcss.config.js";
  7. const target = 'http://192.168.2.7:10010';
  8. // const target = 'http://192.168.2.17:10010';
  9. // const target = 'http://47.101.180.183:10010';
  10. export default defineConfig({
  11. define: {
  12. "import.meta.env.postConfig": postcssConfig,
  13. },
  14. plugins: [
  15. vue(),
  16. Components({
  17. resolvers: [VantResolver()],
  18. }),
  19. ],
  20. css:{
  21. preprocessorOptions:{
  22. scss:{
  23. api:"modern-compiler",
  24. silenceDeprecations: ["legacy-js-api"],
  25. additionalData: `@use "./src/assets/scss/iframe.scss" as *;`
  26. }
  27. }
  28. },
  29. server: {
  30. host: '0.0.0.0',
  31. port: 19017,
  32. open: true,
  33. proxy: {
  34. '/api': {
  35. // 这里的'/api'表示需要转发到的接口路径前缀
  36. target, // 将请求转发到的目标地址
  37. changeOrigin: true, // 支持跨域
  38. rewrite: (path) => path.replace(/^\/api/, '') // 去除请求路径中的'/api'前缀
  39. }
  40. }
  41. },
  42. build: {
  43. chunkSizeWarningLimit: 1600,
  44. },
  45. resolve: {
  46. alias: [
  47. { find: "@", replacement: path.resolve(__dirname, "src") },
  48. { find: "@pages", replacement: path.resolve(__dirname, "src/pages") },
  49. {
  50. find: "@components",
  51. replacement: path.resolve(__dirname, "src/components"),
  52. },
  53. { find: "@hooks", replacement: path.resolve(__dirname, "src/hooks") },
  54. { find: "@utility", replacement: path.resolve(__dirname, "src/utility") },
  55. { find: "@store", replacement: path.resolve(__dirname, "src/store") },
  56. { find: "@lang", replacement: path.resolve(__dirname, "src/lang") },
  57. { find: "@common", replacement: path.resolve(__dirname, "src/common") },
  58. { find: "@api", replacement: path.resolve(__dirname, "src/api") },
  59. ],
  60. },
  61. });