bunny-web-template/build/info.ts

57 lines
1.5 KiB
TypeScript
Raw Normal View History

import boxen, { type Options as BoxenOptions } from 'boxen';
2025-02-24 22:45:14 +08:00
import dayjs, { type Dayjs } from 'dayjs';
import duration from 'dayjs/plugin/duration';
import gradientString from 'gradient-string';
import { wrapperEnv } from './utils';
2025-02-24 22:45:14 +08:00
dayjs.extend(duration);
const boxenOptions: BoxenOptions = {
padding: 0.94,
borderColor: 'cyan',
borderStyle: 'round',
textAlignment: 'left',
2025-02-24 22:45:14 +08:00
};
/* 输出日志信息 */
const printLogMessage = (VITE_PORT: number) => {
return gradientString('cyan', 'magenta').multiline(
`保存成功!服务器重新启动...
2025-02-24 22:45:14 +08:00
访
http://localhost:${VITE_PORT}`
);
2025-02-24 22:45:14 +08:00
};
export const viteConsoleLog = (mode) => {
const { VITE_PORT } = wrapperEnv(mode);
2025-02-24 22:45:14 +08:00
let config: { command: string };
let startTime: Dayjs;
let endTime: Dayjs;
return {
name: 'vite:buildInfo',
configResolved(resolvedConfig) {
config = resolvedConfig;
},
buildStart() {
console.log(boxen(printLogMessage(VITE_PORT), boxenOptions));
if (config.command === 'build') {
startTime = dayjs(new Date());
}
},
closeBundle() {
if (config.command === 'build') {
endTime = dayjs(new Date());
const format = dayjs.duration(endTime.diff(startTime)).format('mm分ss秒');
console.log(
boxen(
gradientString('cyan', 'magenta').multiline(`🎉 恭喜打包完成(总用时${format}`),
boxenOptions
)
);
}
},
};
2025-02-24 22:45:14 +08:00
};