vite.config.js 2.1 KB

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