info.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import type { Plugin } from "vite";
  2. import dayjs, { Dayjs } from "dayjs";
  3. import utils from "@pureadmin/utils";
  4. import duration from "dayjs/plugin/duration";
  5. import { green, blue, bold } from "picocolors";
  6. dayjs.extend(duration);
  7. export function viteBuildInfo(): Plugin {
  8. let config: { command: string };
  9. let startTime: Dayjs;
  10. let endTime: Dayjs;
  11. let outDir: string;
  12. return {
  13. name: "vite:buildInfo",
  14. configResolved(resolvedConfig) {
  15. config = resolvedConfig;
  16. outDir = resolvedConfig.build?.outDir ?? "dist";
  17. },
  18. buildStart() {
  19. console.log(
  20. bold(
  21. green(
  22. `👏欢迎使用${blue(
  23. "[vue-pure-admin]"
  24. )},如果您感觉不错,记得点击后面链接给个star哦💖 https://github.com/pure-admin/vue-pure-admin`
  25. )
  26. )
  27. );
  28. if (config.command === "build") {
  29. startTime = dayjs(new Date());
  30. }
  31. },
  32. closeBundle() {
  33. if (config.command === "build") {
  34. endTime = dayjs(new Date());
  35. utils.getPackageSize({
  36. folder: outDir,
  37. callback: (size: string) => {
  38. console.log(
  39. bold(
  40. green(
  41. `🎉恭喜打包完成(总用时${dayjs
  42. .duration(endTime.diff(startTime))
  43. .format("mm分ss秒")},打包后的大小为${size})`
  44. )
  45. )
  46. );
  47. }
  48. });
  49. }
  50. }
  51. };
  52. }