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.

53 lines
1.5 KiB

  1. import type { Plugin } from "vite";
  2. import dayjs, { Dayjs } from "dayjs";
  3. import duration from "dayjs/plugin/duration";
  4. import { green, blue, bold } from "picocolors";
  5. import { getPackageSize } from "@pureadmin/utils";
  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/xiaoxian521/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. 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. }