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.

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