vite.config.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. vue: {
  46. compilerOptions: {
  47. isCustomElement: (tag) => tag == 'ww-open-data' // 排除 ww-open-data
  48. }
  49. },
  50. resolve: {
  51. alias: [
  52. { find: "@", replacement: path.resolve(__dirname, "src") },
  53. { find: "@pages", replacement: path.resolve(__dirname, "src/pages") },
  54. {
  55. find: "@components",
  56. replacement: path.resolve(__dirname, "src/components"),
  57. },
  58. { find: "@hooks", replacement: path.resolve(__dirname, "src/hooks") },
  59. { find: "@utility", replacement: path.resolve(__dirname, "src/utility") },
  60. { find: "@store", replacement: path.resolve(__dirname, "src/store") },
  61. { find: "@lang", replacement: path.resolve(__dirname, "src/lang") },
  62. { find: "@common", replacement: path.resolve(__dirname, "src/common") },
  63. { find: "@api", replacement: path.resolve(__dirname, "src/api") },
  64. ],
  65. },
  66. });