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.

73 lines
2.4 KiB

  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 { viteMockServe } from "vite-plugin-mock";
  9. import VueI18n from "@intlify/vite-plugin-vue-i18n";
  10. // import ElementPlus from "unplugin-element-plus/vite";
  11. import { visualizer } from "rollup-plugin-visualizer";
  12. import removeConsole from "vite-plugin-remove-console";
  13. import themePreprocessorPlugin from "@pureadmin/theme";
  14. import { genScssMultipleScopeVars } from "/@/layout/theme";
  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. Unocss(),
  29. // 线上环境删除console
  30. removeConsole(),
  31. viteBuildInfo(),
  32. // 自定义主题
  33. themePreprocessorPlugin({
  34. scss: {
  35. multipleScopeVars: genScssMultipleScopeVars(),
  36. // 在生产模式是否抽取独立的主题css文件,extract为true以下属性有效
  37. extract: true,
  38. // 会选取defaultScopeName对应的主题css文件在html添加link
  39. themeLinkTagId: "head",
  40. // "head"||"head-prepend" || "body" ||"body-prepend"
  41. themeLinkTagInjectTo: "head",
  42. // 是否对抽取的css文件内对应scopeName的权重类名移除
  43. removeCssScopeName: false
  44. }
  45. }),
  46. // svg组件化支持
  47. svgLoader(),
  48. // ElementPlus({}),
  49. // mock支持
  50. viteMockServe({
  51. mockPath: "mock",
  52. localEnabled: command === "serve",
  53. prodEnabled: command !== "serve" && prodMock,
  54. injectCode: `
  55. import { setupProdMockServer } from './mockProdServer';
  56. setupProdMockServer();
  57. `,
  58. logger: false
  59. }),
  60. // 是否为打包后的文件提供传统浏览器兼容性支持
  61. VITE_LEGACY
  62. ? legacy({
  63. targets: ["ie >= 11"],
  64. additionalLegacyPolyfills: ["regenerator-runtime/runtime"]
  65. })
  66. : null,
  67. // 打包分析
  68. lifecycle === "report"
  69. ? visualizer({ open: true, brotliSize: true, filename: "report.html" })
  70. : null
  71. ];
  72. }