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.

102 lines
3.5 KiB

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