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.

79 lines
2.8 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 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. WindiCSS(),
  29. // 线上环境删除console
  30. removeConsole(),
  31. viteBuildInfo(),
  32. // 自定义主题
  33. themePreprocessorPlugin({
  34. scss: {
  35. multipleScopeVars: genScssMultipleScopeVars(),
  36. // 默认取 multipleScopeVars[0].scopeName
  37. defaultScopeName: "",
  38. // 在生产模式是否抽取独立的主题css文件,extract为true以下属性有效
  39. extract: true,
  40. // 独立主题css文件的输出路径,默认取 viteConfig.build.assetsDir 相对于 (viteConfig.build.outDir)
  41. outputDir: "",
  42. // 会选取defaultScopeName对应的主题css文件在html添加link
  43. themeLinkTagId: "head",
  44. // "head"||"head-prepend" || "body" ||"body-prepend"
  45. themeLinkTagInjectTo: "head",
  46. // 是否对抽取的css文件内对应scopeName的权重类名移除
  47. removeCssScopeName: false,
  48. // 可以自定义css文件名称的函数
  49. customThemeCssFileName: scopeName => scopeName
  50. }
  51. }),
  52. // svg组件化支持
  53. svgLoader(),
  54. ElementPlus({}),
  55. // mock支持
  56. viteMockServe({
  57. mockPath: "mock",
  58. localEnabled: command === "serve",
  59. prodEnabled: command !== "serve" && prodMock,
  60. injectCode: `
  61. import { setupProdMockServer } from './mockProdServer';
  62. setupProdMockServer();
  63. `,
  64. logger: true
  65. }),
  66. // 是否为打包后的文件提供传统浏览器兼容性支持
  67. VITE_LEGACY
  68. ? legacy({
  69. targets: ["ie >= 11"],
  70. additionalLegacyPolyfills: ["regenerator-runtime/runtime"]
  71. })
  72. : null,
  73. // 打包分析
  74. lifecycle === "report"
  75. ? visualizer({ open: true, brotliSize: true, filename: "report.html" })
  76. : null
  77. ];
  78. }