import pkg from './package/package.json'; import pkg2 from './package.json' import fs from 'fs-extra'; import chalk from 'chalk'; function buildNewVersion() { const beginYear = 2024; const currDate = new Date(); const currYear = currDate.getFullYear(); const year = currYear - beginYear; const month = currDate.getMonth() + 1; const day = currDate.getDate(); const version = `${year}.${month}.${day}`; pkg.version = version; pkg2.version = version; console.log('写入新版本号:' + pkg.version); fs.writeFileSync('package.json', JSON.stringify(pkg2, null, 2)); fs.writeFileSync('package/package.json', JSON.stringify(pkg, null, 2)); } export const runBeforeBuild = async () => { try { //设置新版本号 buildNewVersion(); } catch (error) { console.log(chalk.red('vite build error:\n' + error)); process.exit(1); } }; runBeforeBuild();