vite.config.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.5:10010';
  9. // const target = 'http://1.94.62.58:10014';
  10. // const target = 'http://192.168.2.17: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. rollupOptions: {
  46. output: {
  47. entryFileNames: `assets/[name].[hash].js`,
  48. chunkFileNames: `assets/[name].[hash].js`,
  49. assetFileNames: `assets/[name].[hash].[ext]`,
  50. }
  51. },
  52. },
  53. vue: {
  54. compilerOptions: {
  55. isCustomElement: (tag) => tag == 'ww-open-data' // 排除 ww-open-data
  56. }
  57. },
  58. resolve: {
  59. alias: [
  60. { find: "@", replacement: path.resolve(__dirname, "src") },
  61. { find: "@pages", replacement: path.resolve(__dirname, "src/pages") },
  62. {
  63. find: "@components",
  64. replacement: path.resolve(__dirname, "src/components"),
  65. },
  66. { find: "@hooks", replacement: path.resolve(__dirname, "src/hooks") },
  67. { find: "@utility", replacement: path.resolve(__dirname, "src/utility") },
  68. { find: "@store", replacement: path.resolve(__dirname, "src/store") },
  69. { find: "@lang", replacement: path.resolve(__dirname, "src/lang") },
  70. { find: "@common", replacement: path.resolve(__dirname, "src/common") },
  71. { find: "@api", replacement: path.resolve(__dirname, "src/api") },
  72. ],
  73. },
  74. });