plugins.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import Unocss from "unocss/vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import { viteBuildInfo } from "./info";
  4. import svgLoader from "vite-svg-loader";
  5. import legacy from "@vitejs/plugin-legacy";
  6. import vueJsx from "@vitejs/plugin-vue-jsx";
  7. import { visualizer } from "rollup-plugin-visualizer";
  8. import removeConsole from "vite-plugin-remove-console";
  9. import themePreprocessorPlugin from "@pureadmin/theme";
  10. import { genScssMultipleScopeVars } from "/@/layout/theme";
  11. import DefineOptions from "unplugin-vue-define-options/vite";
  12. import OptimizationPersist from "vite-plugin-optimize-persist";
  13. import PkgConfig from "vite-plugin-package-config";
  14. export function getPluginsList(command, VITE_LEGACY) {
  15. const lifecycle = process.env.npm_lifecycle_event;
  16. return [
  17. vue(),
  18. // jsx、tsx语法支持
  19. vueJsx(),
  20. Unocss(),
  21. DefineOptions(),
  22. // 线上环境删除console
  23. removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
  24. viteBuildInfo(),
  25. // 自定义主题
  26. themePreprocessorPlugin({
  27. scss: {
  28. multipleScopeVars: genScssMultipleScopeVars(),
  29. // 在生产模式是否抽取独立的主题css文件,extract为true以下属性有效
  30. extract: true,
  31. // 会选取defaultScopeName对应的主题css文件在html添加link
  32. themeLinkTagId: "head",
  33. // "head"||"head-prepend" || "body" ||"body-prepend"
  34. themeLinkTagInjectTo: "head",
  35. // 是否对抽取的css文件内对应scopeName的权重类名移除
  36. removeCssScopeName: false
  37. }
  38. }),
  39. // svg组件化支持
  40. svgLoader(),
  41. // 依赖预构建
  42. PkgConfig(),
  43. OptimizationPersist(),
  44. // 是否为打包后的文件提供传统浏览器兼容性支持
  45. VITE_LEGACY
  46. ? legacy({
  47. targets: ["ie >= 11"],
  48. additionalLegacyPolyfills: ["regenerator-runtime/runtime"]
  49. })
  50. : null,
  51. // 打包分析
  52. lifecycle === "report"
  53. ? visualizer({ open: true, brotliSize: true, filename: "report.html" })
  54. : null
  55. ];
  56. }