vite.config.ts 3.8 KB

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