vite.config.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { fileURLToPath, URL } from "node:url";
  2. import { defineConfig, loadEnv } from "vite";
  3. import createVitePlugins from "./build/plugins";
  4. import Components from "unplugin-vue-components/vite";
  5. import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
  6. export default defineConfig(({ mode }) => {
  7. // eslint-disable-next-line node/prefer-global/process
  8. const env = loadEnv(mode, process.cwd(), "");
  9. return {
  10. base: "./", // 让 CSS 文件路径正确
  11. ssr: {
  12. noExternal: ["some-package"], // 确保 CSS 相关的库不会被 SSR 处理
  13. },
  14. plugins: [
  15. createVitePlugins(env),
  16. Components({
  17. resolvers: [ElementPlusResolver()],
  18. }),
  19. ],
  20. resolve: {
  21. alias: {
  22. "@": fileURLToPath(new URL("./src", import.meta.url)),
  23. "@iconify-icons": "/node_modules/@iconify-icons", // 设置正确的路径
  24. },
  25. },
  26. server: {
  27. host: "0.0.0.0",
  28. proxy: {
  29. "/api": {
  30. target: env.VITE_BASE_URL,
  31. changeOrigin: true,
  32. rewrite: (path) => path.replace(/^\/api/, ""),
  33. },
  34. // 未知量 //振动、激光测距仪
  35. "/WZLapi": {
  36. target: "http://192.168.50.241:9001", // WZLapi 目标地址
  37. // target: "http://106.120.102.238:18080/WindTransDev", // WZLapi 外网目标地址
  38. changeOrigin: true,
  39. rewrite: (path) => path.replace(/^\/WZLapi/, ""),
  40. },
  41. },
  42. css: {
  43. preprocessorOptions: {
  44. scss: {
  45. api: "modern-compiler",
  46. },
  47. },
  48. },
  49. },
  50. };
  51. });