vite.config.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { defineConfig } from 'vite';
  2. import vue from '@vitejs/plugin-vue';
  3. import { resolve } from 'path';
  4. // const target = 'http://192.168.2.40:10099';
  5. // const target = 'http://192.168.2.17:10010';
  6. // const target = "http://127.0.0.1:10010";
  7. // const target = "http://192.168.2.178:10010";
  8. const target = 'http://47.101.180.183:10014';
  9. export default defineConfig({
  10. plugins: [vue({
  11. template: {
  12. compilerOptions: {
  13. isCustomElement: (tag) => tag === 'ww-open-data'
  14. }
  15. }
  16. })],
  17. optimizeDeps: {
  18. include: ['vue-draggable-plus']
  19. },
  20. server: {
  21. host: '0.0.0.0',
  22. port: 19123,
  23. open: true,
  24. proxy: {
  25. '/api': {
  26. // 这里的'/api'表示需要转发到的接口路径前缀
  27. target, // 将请求转发到的目标地址
  28. changeOrigin: true, // 支持跨域
  29. rewrite: (path) => path.replace(/^\/api/, '') // 去除请求路径中的'/api'前缀
  30. }
  31. }
  32. },
  33. resolve: {
  34. alias: {
  35. '@': resolve(__dirname, './src')
  36. },
  37. extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  38. },
  39. css: {
  40. preprocessorOptions: {
  41. scss: {
  42. // additionalData: '@import "@/styles/global.scss";'
  43. additionalData: '@use "@/styles/global.scss" as *;', // 使用 @use 语法
  44. api: "modern-compiler"
  45. }
  46. }
  47. },
  48. build: {
  49. rollupOptions: {
  50. output: {
  51. entryFileNames: `assets/[name].${new Date().getTime()}.js`,
  52. chunkFileNames: `assets/[name].${new Date().getTime()}.js`,
  53. assetFileNames: `assets/[name].${new Date().getTime()}.[ext]`,
  54. compact: true,
  55. manualChunks: {
  56. vue: ['vue', 'vue-router', 'vuex'],
  57. echarts: ['echarts']
  58. }
  59. }
  60. }
  61. }
  62. });