You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.8 KiB

  1. import vue from "@vitejs/plugin-vue";
  2. import { viteBuildInfo } from "./info";
  3. import svgLoader from "vite-svg-loader";
  4. import legacy from "@vitejs/plugin-legacy";
  5. import vueJsx from "@vitejs/plugin-vue-jsx";
  6. import WindiCSS from "vite-plugin-windicss";
  7. import { viteMockServe } from "vite-plugin-mock";
  8. import liveReload from "vite-plugin-live-reload";
  9. import ElementPlus from "unplugin-element-plus/vite";
  10. import { visualizer } from "rollup-plugin-visualizer";
  11. import removeConsole from "vite-plugin-remove-console";
  12. import themePreprocessorPlugin from "@zougt/vite-plugin-theme-preprocessor";
  13. export function getPluginsList(command, VITE_LEGACY) {
  14. const prodMock = true;
  15. const lifecycle = process.env.npm_lifecycle_event;
  16. return [
  17. vue(),
  18. // jsx、tsx语法支持
  19. vueJsx(),
  20. WindiCSS(),
  21. // 线上环境删除console
  22. removeConsole(),
  23. viteBuildInfo(),
  24. // 修改layout文件夹下的文件时自动重载浏览器 解决 https://github.com/xiaoxian521/vue-pure-admin/issues/170
  25. liveReload(["src/layout/**/*", "src/router/**/*"]),
  26. // 自定义主题
  27. themePreprocessorPlugin({
  28. scss: {
  29. multipleScopeVars: [
  30. {
  31. scopeName: "layout-theme-default",
  32. path: "src/layout/theme/default-vars.scss"
  33. },
  34. {
  35. scopeName: "layout-theme-light",
  36. path: "src/layout/theme/light-vars.scss"
  37. },
  38. {
  39. scopeName: "layout-theme-dusk",
  40. path: "src/layout/theme/dusk-vars.scss"
  41. },
  42. {
  43. scopeName: "layout-theme-volcano",
  44. path: "src/layout/theme/volcano-vars.scss"
  45. },
  46. {
  47. scopeName: "layout-theme-yellow",
  48. path: "src/layout/theme/yellow-vars.scss"
  49. },
  50. {
  51. scopeName: "layout-theme-mingQing",
  52. path: "src/layout/theme/mingQing-vars.scss"
  53. },
  54. {
  55. scopeName: "layout-theme-auroraGreen",
  56. path: "src/layout/theme/auroraGreen-vars.scss"
  57. },
  58. {
  59. scopeName: "layout-theme-pink",
  60. path: "src/layout/theme/pink-vars.scss"
  61. },
  62. {
  63. scopeName: "layout-theme-saucePurple",
  64. path: "src/layout/theme/saucePurple-vars.scss"
  65. }
  66. ],
  67. // 默认取 multipleScopeVars[0].scopeName
  68. defaultScopeName: "",
  69. // 在生产模式是否抽取独立的主题css文件,extract为true以下属性有效
  70. extract: true,
  71. // 独立主题css文件的输出路径,默认取 viteConfig.build.assetsDir 相对于 (viteConfig.build.outDir)
  72. outputDir: "",
  73. // 会选取defaultScopeName对应的主题css文件在html添加link
  74. themeLinkTagId: "head",
  75. // "head"||"head-prepend" || "body" ||"body-prepend"
  76. themeLinkTagInjectTo: "head",
  77. // 是否对抽取的css文件内对应scopeName的权重类名移除
  78. removeCssScopeName: false,
  79. // 可以自定义css文件名称的函数
  80. customThemeCssFileName: scopeName => scopeName
  81. }
  82. }),
  83. // svg组件化支持
  84. svgLoader(),
  85. ElementPlus({}),
  86. // mock支持
  87. viteMockServe({
  88. mockPath: "mock",
  89. localEnabled: command === "serve",
  90. prodEnabled: command !== "serve" && prodMock,
  91. injectCode: `
  92. import { setupProdMockServer } from './mockProdServer';
  93. setupProdMockServer();
  94. `,
  95. logger: true
  96. }),
  97. // 是否为打包后的文件提供传统浏览器兼容性支持
  98. VITE_LEGACY
  99. ? legacy({
  100. targets: ["ie >= 11"],
  101. additionalLegacyPolyfills: ["regenerator-runtime/runtime"]
  102. })
  103. : null,
  104. // 打包分析
  105. lifecycle === "report"
  106. ? visualizer({ open: true, brotliSize: true, filename: "report.html" })
  107. : null
  108. ];
  109. }