plugins.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { getCdnPlugin } from "./cdn";
  2. import vue from "@vitejs/plugin-vue";
  3. import { viteBuildInfo } from "./info";
  4. import svgLoader from "vite-svg-loader";
  5. import vueJsx from "@vitejs/plugin-vue-jsx";
  6. import { configCompressPlugin } from "./compress";
  7. // import ElementPlus from "unplugin-element-plus/vite";
  8. import { visualizer } from "rollup-plugin-visualizer";
  9. import removeConsole from "vite-plugin-remove-console";
  10. import { themePreprocessorPlugin } from "@pureadmin/theme";
  11. import { genScssMultipleScopeVars } from "../src/layout/theme";
  12. export function getPluginsList(
  13. VITE_CDN: boolean,
  14. VITE_COMPRESSION: ViteCompression
  15. ) {
  16. const lifecycle = process.env.npm_lifecycle_event;
  17. return [
  18. vue(),
  19. // jsx、tsx语法支持
  20. vueJsx(),
  21. VITE_CDN ? getCdnPlugin() : null,
  22. configCompressPlugin(VITE_COMPRESSION),
  23. // 线上环境删除console
  24. removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
  25. viteBuildInfo(),
  26. // 自定义主题
  27. themePreprocessorPlugin({
  28. scss: {
  29. multipleScopeVars: genScssMultipleScopeVars(),
  30. extract: true
  31. }
  32. }),
  33. // svg组件化支持
  34. svgLoader(),
  35. // ElementPlus({}),
  36. // mock支持
  37. // 打包分析
  38. lifecycle === "report"
  39. ? visualizer({ open: true, brotliSize: true, filename: "report.html" })
  40. : null
  41. ];
  42. }