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.

66 lines
2.0 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 vueJsx from "@vitejs/plugin-vue-jsx";
  7. import { viteMockServe } from "vite-plugin-mock";
  8. import { configCompressPlugin } from "./compress";
  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 DefineOptions from "unplugin-vue-define-options/vite";
  15. import { genScssMultipleScopeVars } from "../src/layout/theme";
  16. export function getPluginsList(
  17. command: string,
  18. VITE_CDN: boolean,
  19. VITE_COMPRESSION: ViteCompression
  20. ) {
  21. const prodMock = true;
  22. const lifecycle = process.env.npm_lifecycle_event;
  23. return [
  24. vue(),
  25. // https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n
  26. VueI18n({
  27. runtimeOnly: true,
  28. compositionOnly: true,
  29. include: [resolve("locales/**")]
  30. }),
  31. // jsx、tsx语法支持
  32. vueJsx(),
  33. VITE_CDN ? cdn : null,
  34. configCompressPlugin(VITE_COMPRESSION),
  35. DefineOptions(),
  36. // 线上环境删除console
  37. removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
  38. viteBuildInfo(),
  39. // 自定义主题
  40. themePreprocessorPlugin({
  41. scss: {
  42. multipleScopeVars: genScssMultipleScopeVars(),
  43. extract: true
  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. lifecycle === "report"
  62. ? visualizer({ open: true, brotliSize: true, filename: "report.html" })
  63. : null
  64. ];
  65. }