vite.config.ts 3.6 KB

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