index.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { PluginOption } from 'vite';
  2. import vue from '@vitejs/plugin-vue';
  3. import vueJsx from '@vitejs/plugin-vue-jsx';
  4. import purgeIcons from 'vite-plugin-purge-icons';
  5. import UnoCSS from 'unocss/vite';
  6. import { presetTypography, presetUno } from 'unocss';
  7. // 本地调试https配置方法
  8. import VitePluginCertificate from 'vite-plugin-mkcert';
  9. //[issues/555]开发环境,vscode断点调试,文件或行数对不上
  10. import vueSetupExtend from 'vite-plugin-vue-setup-extend-plus';
  11. import { configHtmlPlugin } from './html';
  12. import { configMockPlugin } from './mock';
  13. import { configCompressPlugin } from './compress';
  14. import { configVisualizerConfig } from './visualizer';
  15. import { configThemePlugin } from './theme';
  16. import { configSvgIconsPlugin } from './svgSprite';
  17. // //预编译加载插件(不支持vite3作废)
  18. // import OptimizationPersist from 'vite-plugin-optimize-persist';
  19. // import PkgConfig from 'vite-plugin-package-config';
  20. export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
  21. const { VITE_USE_MOCK, VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE } = viteEnv;
  22. const vitePlugins: (PluginOption | PluginOption[])[] = [
  23. // have to
  24. vue(),
  25. // have to
  26. vueJsx(),
  27. // support name
  28. vueSetupExtend(),
  29. // @ts-ignore
  30. VitePluginCertificate({
  31. source: 'coding',
  32. }),
  33. ];
  34. vitePlugins.push(UnoCSS({ presets: [presetUno(), presetTypography()] }));
  35. // vite-plugin-html
  36. vitePlugins.push(configHtmlPlugin(viteEnv, isBuild));
  37. // vite-plugin-svg-icons
  38. vitePlugins.push(configSvgIconsPlugin(isBuild));
  39. // vite-plugin-mock
  40. VITE_USE_MOCK && vitePlugins.push(configMockPlugin(isBuild));
  41. // vite-plugin-purge-icons
  42. vitePlugins.push(purgeIcons());
  43. // rollup-plugin-visualizer
  44. vitePlugins.push(configVisualizerConfig());
  45. // vite-plugin-theme
  46. vitePlugins.push(configThemePlugin(isBuild));
  47. // The following plugins only work in the production environment
  48. if (isBuild) {
  49. // rollup-plugin-gzip
  50. vitePlugins.push(configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE));
  51. }
  52. // //vite-plugin-theme【预编译加载插件,解决vite首次打开界面加载慢问题】
  53. // vitePlugins.push(PkgConfig());
  54. // vitePlugins.push(OptimizationPersist());
  55. return vitePlugins;
  56. }