plugins.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { cdn } from "./cdn";
  2. import vue from "@vitejs/plugin-vue";
  3. import { viteBuildInfo } from "./info";
  4. import svgLoader from "vite-svg-loader";
  5. import type { PluginOption } from "vite";
  6. import vueJsx from "@vitejs/plugin-vue-jsx";
  7. import { configCompressPlugin } from "./compress";
  8. import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
  9. import { visualizer } from "rollup-plugin-visualizer";
  10. import removeConsole from "vite-plugin-remove-console";
  11. import { themePreprocessorPlugin } from "@pureadmin/theme";
  12. import { genScssMultipleScopeVars } from "../src/layout/theme";
  13. import path from "path";
  14. export function getPluginsList(
  15. command: string,
  16. VITE_CDN: boolean,
  17. VITE_COMPRESSION: ViteCompression
  18. ): PluginOption[] {
  19. const lifecycle = process.env.npm_lifecycle_event;
  20. return [
  21. vue(),
  22. // jsx、tsx语法支持
  23. vueJsx(),
  24. VITE_CDN ? cdn : null,
  25. configCompressPlugin(VITE_COMPRESSION),
  26. // 线上环境删除console
  27. removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
  28. viteBuildInfo(),
  29. // 自定义主题
  30. themePreprocessorPlugin({
  31. scss: {
  32. multipleScopeVars: genScssMultipleScopeVars(),
  33. extract: true
  34. }
  35. }),
  36. // svg组件化支持
  37. svgLoader(),
  38. // ElementPlus({}),
  39. createSvgIconsPlugin({
  40. // 指定需要缓存的图标文件夹
  41. iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
  42. // 指定symbolId格式
  43. symbolId: "icon-[dir]-[name]"
  44. }),
  45. // 打包分析
  46. lifecycle === "report"
  47. ? visualizer({ open: true, brotliSize: true, filename: "report.html" })
  48. : null
  49. ];
  50. }