index.ts 1014 B

1234567891011121314151617181920212223242526272829303132
  1. import type { PluginOption } from 'vite';
  2. import vue from '@vitejs/plugin-vue';
  3. import vueJsx from '@vitejs/plugin-vue-jsx';
  4. import unocss from '@unocss/vite';
  5. import progress from 'vite-plugin-progress';
  6. import pageRoute from '@soybeanjs/vite-plugin-vue-page-route';
  7. import html from './html';
  8. import unplugin from './unplugin';
  9. import mock from './mock';
  10. import visualizer from './visualizer';
  11. import compress from './compress';
  12. import pwa from './pwa';
  13. /**
  14. * vite插件
  15. * @param viteEnv - 环境变量配置
  16. */
  17. export function setupVitePlugins(viteEnv: ImportMetaEnv): (PluginOption | PluginOption[])[] {
  18. const plugins = [vue(), vueJsx(), html(viteEnv), ...unplugin(viteEnv), unocss(), mock, progress(), pageRoute()];
  19. if (viteEnv.VITE_VISUALIZER === 'Y') {
  20. plugins.push(visualizer as PluginOption);
  21. }
  22. if (viteEnv.VITE_COMPRESS === 'Y') {
  23. plugins.push(compress(viteEnv));
  24. }
  25. if (viteEnv.VITE_PWA === 'Y' || viteEnv.VITE_VERCEL === 'Y') {
  26. plugins.push(pwa());
  27. }
  28. return plugins;
  29. }