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.

50 lines
1.4 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. return {
  12. name: "vite:buildInfo",
  13. configResolved(resolvedConfig: { command: string }) {
  14. config = resolvedConfig;
  15. },
  16. buildStart() {
  17. console.log(
  18. bold(
  19. green(
  20. `👏欢迎使用${blue(
  21. "[vue-pure-admin]"
  22. )}star哦💖 https://github.com/xiaoxian521/vue-pure-admin`
  23. )
  24. )
  25. );
  26. if (config.command === "build") {
  27. startTime = dayjs(new Date());
  28. }
  29. },
  30. closeBundle() {
  31. if (config.command === "build") {
  32. endTime = dayjs(new Date());
  33. getPackageSize({
  34. callback: (size: string) => {
  35. console.log(
  36. bold(
  37. green(
  38. `🎉恭喜打包完成(总用时${dayjs
  39. .duration(endTime.diff(startTime))
  40. .format("mm分ss秒")}${size}`
  41. )
  42. )
  43. );
  44. }
  45. });
  46. }
  47. }
  48. };
  49. }