plugins.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 removeNoMatch from "vite-plugin-router-warn";
  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 { vitePluginFakeServer } from "vite-plugin-fake-server";
  14. export function getPluginsList(
  15. VITE_CDN: boolean,
  16. VITE_COMPRESSION: ViteCompression
  17. ): PluginOption[] {
  18. const lifecycle = process.env.npm_lifecycle_event;
  19. return [
  20. vue(),
  21. // jsx、tsx语法支持
  22. vueJsx(),
  23. viteBuildInfo(),
  24. /**
  25. * 开发环境下移除非必要的vue-router动态路由警告No match found for location with path
  26. * 非必要具体看 https://github.com/vuejs/router/issues/521 和 https://github.com/vuejs/router/issues/359
  27. * vite-plugin-router-warn只在开发环境下启用,只处理vue-router文件并且只在服务启动或重启时运行一次,性能消耗可忽略不计
  28. */
  29. removeNoMatch(),
  30. // mock支持
  31. vitePluginFakeServer({
  32. logger: false,
  33. include: "mock",
  34. infixName: false,
  35. enableProd: true
  36. }),
  37. // 自定义主题
  38. themePreprocessorPlugin({
  39. scss: {
  40. multipleScopeVars: genScssMultipleScopeVars(),
  41. extract: true
  42. }
  43. }),
  44. // svg组件化支持
  45. svgLoader(),
  46. VITE_CDN ? cdn : null,
  47. configCompressPlugin(VITE_COMPRESSION),
  48. // 线上环境删除console
  49. removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
  50. // 打包分析
  51. lifecycle === "report"
  52. ? visualizer({ open: true, brotliSize: true, filename: "report.html" })
  53. : (null as any)
  54. ];
  55. }