vite.config.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import UnoCSS from 'unocss/vite'
  4. import { resolve } from 'path'
  5. import config from './src/config'
  6. // https://vitejs.dev/config/
  7. export default defineConfig({
  8. css: {
  9. extract: true,
  10. preprocessorOptions: {
  11. scss: {
  12. additionalData: '@import "./src/styles/app/_var.scss";',
  13. },
  14. },
  15. },
  16. resolve: {
  17. alias: {
  18. '~src':resolve(__dirname, './src'),
  19. '~ass': resolve(__dirname, './src/assets'),
  20. '~com': resolve(__dirname, './src/components'),
  21. '~api': resolve(__dirname, './src/api/modules'),
  22. '~sto': resolve(__dirname, './src/store/modules'),
  23. '~uti': resolve(__dirname, './src/utils'),
  24. },
  25. },
  26. plugins: [
  27. vue(),
  28. UnoCSS(),
  29. ],
  30. build: {
  31. target: 'esnext', // 设置构建目标
  32. minify: 'esbuild', // 使用 esbuild 进行压缩
  33. chunkSizeWarningLimit: 1000, // 将警告的阈值提高到 1000 KB
  34. rollupOptions: {
  35. output: {
  36. manualChunks(id) {
  37. let libStr = '@vue,hc-vue3-ui,element-plus,z-element-plus,echarts,vue-router,pinia,js-web-screen-shot,js-fast-way'
  38. const libs = libStr.split(',')
  39. if (id.includes('node_modules')) {
  40. const arr = id.toString().split('node_modules/')[1].split('/')
  41. if (libs.indexOf(arr[0]) !== -1) {
  42. return '_' + arr[0]
  43. } else {
  44. return '__vendor'
  45. }
  46. }
  47. },
  48. chunkFileNames: 'static/js1/[name]-[hash].js',
  49. entryFileNames: 'static/js2/[name]-[hash].js',
  50. assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
  51. },
  52. },
  53. },
  54. server: {
  55. ...config.vite,
  56. proxy: {
  57. '/api': {
  58. ws: true,
  59. changeOrigin: true,
  60. target: config.target,
  61. rewrite: (path) => path.replace(new RegExp('^/api'), '/'),
  62. // 排除特定文件名
  63. bypass: (req) => {
  64. if (req.originalUrl.endsWith('/humidity.js')) {
  65. return req.originalUrl
  66. }
  67. return null
  68. },
  69. },
  70. '/yunApi': {
  71. ws: true,
  72. changeOrigin: true,
  73. target: 'http://www.0531yun.com',
  74. rewrite: (path) => path.replace(new RegExp('^/yunApi'), '/'),
  75. },
  76. },
  77. },
  78. })