index.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import type { PluginOption } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import { configViteMockServePlugin } from './viteMockServe'
  4. import { configHtmlPlugin } from './html'
  5. import { configUnocssPlugin } from './unocss'
  6. import { componentResolverPlugin } from './componentResolver'
  7. import { autoImportPlugin } from './autoImport'
  8. import { autoVconsolePlugin } from './autoVconsole'
  9. import { unpluginIcons } from './unpluginIcons'
  10. import { compressionPlugin } from './compression'
  11. export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
  12. const { VITE_USE_MOCK, VITE_USE_GZIP } = viteEnv
  13. const vitePlugins: (PluginOption | PluginOption[])[] = [
  14. vue(),
  15. componentResolverPlugin(),
  16. autoImportPlugin()
  17. // use vueJsx
  18. // vueJsx(),
  19. ]
  20. // vite-plugin-html
  21. vitePlugins.push(configHtmlPlugin(viteEnv, isBuild))
  22. // unocss https://uno.antfu.me/
  23. vitePlugins.push(configUnocssPlugin())
  24. // svg icons
  25. vitePlugins.push(unpluginIcons())
  26. // console
  27. vitePlugins.push(autoVconsolePlugin(isBuild))
  28. // 压缩
  29. vitePlugins.push(compressionPlugin(VITE_USE_GZIP))
  30. // mock
  31. VITE_USE_MOCK && vitePlugins.push(configViteMockServePlugin(isBuild, VITE_USE_MOCK))
  32. return vitePlugins
  33. }