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.

75 lines
2.6 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. import DefineOptions from "unplugin-vue-define-options/vite";
  16. export function getPluginsList(command, VITE_LEGACY) {
  17. const prodMock = true;
  18. const lifecycle = process.env.npm_lifecycle_event;
  19. return [
  20. vue(),
  21. // https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n
  22. VueI18n({
  23. runtimeOnly: true,
  24. compositionOnly: true,
  25. include: [resolve("locales/**")]
  26. }),
  27. // jsx、tsx语法支持
  28. vueJsx(),
  29. Unocss(),
  30. DefineOptions(),
  31. // 线上环境删除console
  32. removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
  33. viteBuildInfo(),
  34. // 自定义主题
  35. themePreprocessorPlugin({
  36. scss: {
  37. multipleScopeVars: genScssMultipleScopeVars(),
  38. // 在生产模式是否抽取独立的主题css文件,extract为true以下属性有效
  39. extract: true,
  40. // 会选取defaultScopeName对应的主题css文件在html添加link
  41. themeLinkTagId: "head",
  42. // "head"||"head-prepend" || "body" ||"body-prepend"
  43. themeLinkTagInjectTo: "head",
  44. // 是否对抽取的css文件内对应scopeName的权重类名移除
  45. removeCssScopeName: false
  46. }
  47. }),
  48. // svg组件化支持
  49. svgLoader(),
  50. // ElementPlus({}),
  51. // mock支持
  52. viteMockServe({
  53. mockPath: "mock",
  54. localEnabled: command === "serve",
  55. prodEnabled: command !== "serve" && prodMock,
  56. injectCode: `
  57. import { setupProdMockServer } from './mockProdServer';
  58. setupProdMockServer();
  59. `,
  60. logger: false
  61. }),
  62. // 是否为打包后的文件提供传统浏览器兼容性支持
  63. VITE_LEGACY
  64. ? legacy({
  65. targets: ["ie >= 11"],
  66. additionalLegacyPolyfills: ["regenerator-runtime/runtime"]
  67. })
  68. : null,
  69. // 打包分析
  70. lifecycle === "report"
  71. ? visualizer({ open: true, brotliSize: true, filename: "report.html" })
  72. : null
  73. ];
  74. }