wireguard-dashboard-admin/build/info.ts

54 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-02-27 13:31:19 +08:00
import type { Plugin } from "vite";
import dayjs, { Dayjs } from "dayjs";
import duration from "dayjs/plugin/duration";
import { green, blue, bold } from "picocolors";
2022-08-22 21:34:55 +08:00
import { getPackageSize } from "@pureadmin/utils";
2022-02-27 13:31:19 +08:00
dayjs.extend(duration);
export function viteBuildInfo(): Plugin {
let config: { command: string };
let startTime: Dayjs;
let endTime: Dayjs;
2022-12-03 15:20:30 +08:00
let outDir: string;
2022-02-27 13:31:19 +08:00
return {
name: "vite:buildInfo",
2022-12-03 15:20:30 +08:00
configResolved(resolvedConfig) {
2022-02-27 13:31:19 +08:00
config = resolvedConfig;
2022-12-03 15:20:30 +08:00
outDir = resolvedConfig.build?.outDir ?? "dist";
2022-02-27 13:31:19 +08:00
},
buildStart() {
2022-08-22 21:34:55 +08:00
console.log(
bold(
green(
`👏欢迎使用${blue(
"[vue-pure-admin]"
)}star哦💖 https://github.com/xiaoxian521/vue-pure-admin`
)
)
);
2022-02-27 13:31:19 +08:00
if (config.command === "build") {
startTime = dayjs(new Date());
}
},
closeBundle() {
if (config.command === "build") {
endTime = dayjs(new Date());
2022-08-22 21:34:55 +08:00
getPackageSize({
2022-12-03 15:20:30 +08:00
folder: outDir,
2022-08-22 21:34:55 +08:00
callback: (size: string) => {
console.log(
bold(
green(
`🎉恭喜打包完成(总用时${dayjs
.duration(endTime.diff(startTime))
.format("mm分ss秒")}${size}`
)
2022-02-27 13:31:19 +08:00
)
2022-08-22 21:34:55 +08:00
);
}
2022-02-27 13:31:19 +08:00
});
}
}
};
}