index.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import type { PluginOption } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import vueJsx from '@vitejs/plugin-vue-jsx'
  4. import progress from 'vite-plugin-progress'
  5. import purgeIcons from 'vite-plugin-purge-icons'
  6. import VitePluginCertificate from 'vite-plugin-mkcert'
  7. import UnoCSS from 'unocss/vite'
  8. import { configPwaConfig } from './pwa'
  9. import { configHtmlPlugin } from './html'
  10. import { configCompressPlugin } from './compress'
  11. import { configVisualizerConfig } from './visualizer'
  12. import { configSvgIconsPlugin } from './svgSprite'
  13. export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
  14. const { VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE } = viteEnv
  15. const vitePlugins: PluginOption[] = [
  16. // have to
  17. vue(),
  18. // have to
  19. vueJsx(),
  20. // UnoCSS
  21. UnoCSS(),
  22. // 打包进度条
  23. progress(),
  24. VitePluginCertificate({
  25. source: 'coding',
  26. }),
  27. ]
  28. // vite-vue-plugin-html
  29. vitePlugins.push(configHtmlPlugin(viteEnv, isBuild))
  30. // vite-plugin-svg-icons
  31. vitePlugins.push(configSvgIconsPlugin(isBuild))
  32. // vite-plugin-purge-icons
  33. vitePlugins.push(purgeIcons())
  34. // rollup-plugin-visualizer
  35. vitePlugins.push(configVisualizerConfig())
  36. // The following plugins only work in the production environment
  37. if (isBuild) {
  38. // rollup-plugin-gzip
  39. vitePlugins.push(configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE))
  40. // vite-plugin-pwa
  41. vitePlugins.push(configPwaConfig(viteEnv))
  42. }
  43. return vitePlugins
  44. }