vite.config.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * @Author: fxs bjnsfxs@163.com
  3. * @Date: 2024-08-20 14:06:49
  4. * @LastEditors: fxs bjnsfxs@163.com
  5. * @LastEditTime: 2024-09-02 16:27:01
  6. * @FilePath: \Game-Backstage-Management-System\vite.config.ts
  7. * @Description:
  8. *
  9. */
  10. import { defineConfig } from 'vite'
  11. import vue from '@vitejs/plugin-vue'
  12. import { fileURLToPath, URL } from 'node:url'
  13. import AutoImport from 'unplugin-auto-import/vite'
  14. import Components from 'unplugin-vue-components/vite'
  15. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  16. import Icons from 'unplugin-icons/vite'
  17. import IconsResolver from 'unplugin-icons/resolver'
  18. import { visualizer } from 'rollup-plugin-visualizer'
  19. // 打包
  20. import viteCompression from 'vite-plugin-compression'
  21. import { ViteImageOptimizer } from 'vite-plugin-image-optimizer'
  22. const DEFAULT_OPTIONS = {
  23. test: /\.(jpe?g|png|gif|tiff|webp|svg|avif)$/i,
  24. exclude: undefined,
  25. include: undefined,
  26. includePublic: true,
  27. logStats: true,
  28. ansiColors: true,
  29. svg: {
  30. multipass: true,
  31. plugins: [
  32. {
  33. name: 'preset-default',
  34. params: {
  35. overrides: {
  36. cleanupNumericValues: false,
  37. removeViewBox: false // https://github.com/svg/svgo/issues/1128
  38. },
  39. cleanupIDs: {
  40. minify: false,
  41. remove: false
  42. },
  43. convertPathData: false
  44. }
  45. },
  46. 'sortAttrs',
  47. {
  48. name: 'addAttributesToSVGElement',
  49. params: {
  50. attributes: [{ xmlns: 'http://www.w3.org/2000/svg' }]
  51. }
  52. }
  53. ]
  54. },
  55. png: {
  56. // https://sharp.pixelplumbing.com/api-output#png
  57. quality: 100
  58. },
  59. jpeg: {
  60. // https://sharp.pixelplumbing.com/api-output#jpeg
  61. quality: 100
  62. },
  63. jpg: {
  64. // https://sharp.pixelplumbing.com/api-output#jpeg
  65. quality: 100
  66. },
  67. tiff: {
  68. // https://sharp.pixelplumbing.com/api-output#tiff
  69. quality: 100
  70. },
  71. // gif does not support lossless compression
  72. // https://sharp.pixelplumbing.com/api-output#gif
  73. gif: {},
  74. webp: {
  75. // https://sharp.pixelplumbing.com/api-output#webp
  76. lossless: true
  77. },
  78. avif: {
  79. // https://sharp.pixelplumbing.com/api-output#avif
  80. lossless: true
  81. },
  82. cache: false,
  83. cacheLocation: undefined
  84. }
  85. export default defineConfig({
  86. build: {
  87. rollupOptions: {
  88. output: {
  89. manualChunks: {
  90. echarts: ['echarts']
  91. },
  92. chunkFileNames: 'js/[name]-[hash].js', // 引入文件名的名称
  93. entryFileNames: 'js/[name]-[hash].js', // 包的入口文件名称
  94. assetFileNames: '[ext]/[name]-[hash].[ext]' // 资源文件像 字体,图片等
  95. }
  96. },
  97. terserOptions: {
  98. compress: {
  99. drop_console: true,
  100. drop_debugger: true
  101. }
  102. }
  103. },
  104. esbuild: {
  105. drop: ['console', 'debugger']
  106. },
  107. plugins: [
  108. vue(),
  109. ViteImageOptimizer(DEFAULT_OPTIONS),
  110. viteCompression({
  111. verbose: true, // 默认即可
  112. disable: false, // 开启压缩(不禁用),默认即可
  113. deleteOriginFile: false, // 删除源文件
  114. threshold: 5120, // 压缩前最小文件大小
  115. algorithm: 'gzip', // 压缩算法
  116. ext: '.gz' // 文件类型
  117. }),
  118. visualizer({ open: true }),
  119. AutoImport({
  120. resolvers: [ElementPlusResolver()]
  121. }),
  122. Components({
  123. resolvers: [
  124. ElementPlusResolver(),
  125. IconsResolver({
  126. prefix: 'icon'
  127. })
  128. ]
  129. }),
  130. Icons({
  131. autoInstall: true
  132. })
  133. ],
  134. resolve: {
  135. alias: {
  136. '@': fileURLToPath(new URL('./src', import.meta.url))
  137. }
  138. }
  139. })