vite.config.js 2.4 KB

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