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.

118 lines
4.1 KiB

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