plugins.ts 1.9 KB

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