2025-02-26 11:23:04 +08:00
|
|
|
|
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';
|
2025-02-26 11:23:04 +08:00
|
|
|
|
import gradientString from 'gradient-string';
|
|
|
|
|
|
|
|
|
|
import { wrapperEnv } from './utils';
|
2025-02-24 22:45:14 +08:00
|
|
|
|
|
|
|
|
|
dayjs.extend(duration);
|
|
|
|
|
|
|
|
|
|
const boxenOptions: BoxenOptions = {
|
2025-02-26 11:23:04 +08:00
|
|
|
|
padding: 0.94,
|
|
|
|
|
borderColor: 'cyan',
|
|
|
|
|
borderStyle: 'round',
|
|
|
|
|
textAlignment: 'left',
|
2025-02-24 22:45:14 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* 输出日志信息 */
|
|
|
|
|
const printLogMessage = (VITE_PORT: number) => {
|
2025-02-26 11:23:04 +08:00
|
|
|
|
return gradientString('cyan', 'magenta').multiline(
|
|
|
|
|
`保存成功!服务器重新启动...
|
2025-02-24 22:45:14 +08:00
|
|
|
|
项目访问地址如下:
|
2025-02-26 11:23:04 +08:00
|
|
|
|
http://localhost:${VITE_PORT}`
|
|
|
|
|
);
|
2025-02-24 22:45:14 +08:00
|
|
|
|
};
|
|
|
|
|
|
2025-02-26 11:23:04 +08:00
|
|
|
|
export const viteConsoleLog = (mode) => {
|
|
|
|
|
const { VITE_PORT } = wrapperEnv(mode);
|
2025-02-24 22:45:14 +08:00
|
|
|
|
|
2025-02-26 11:23:04 +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
|
|
|
|
};
|