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.

82 lines
2.7 KiB

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