style: 统一代码格式和类型定义,测试eslint --fix, 还是有报错
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
// src/plugins/updatePackageJson.ts
|
||||
import { Plugin } from 'vite'
|
||||
import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
import type { Plugin } from 'vite'
|
||||
import fs from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
|
||||
const updatePackageJson = (): Plugin => {
|
||||
function updatePackageJson(): Plugin {
|
||||
return {
|
||||
name: 'update-package-json',
|
||||
async buildStart() {
|
||||
// 只在生产环境构建时执行
|
||||
if (process.env.NODE_ENV !== 'production') return
|
||||
if (process.env.NODE_ENV !== 'production')
|
||||
return
|
||||
|
||||
const packageJsonPath = path.resolve(process.cwd(), 'package.json')
|
||||
|
||||
@@ -21,10 +22,11 @@ const updatePackageJson = (): Plugin => {
|
||||
packageJson['update-time'] = new Date().toISOString().split('T')[0] // YYYY-MM-DD
|
||||
|
||||
// 写回文件(保持 2 空格缩进)
|
||||
await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n', 'utf-8')
|
||||
await fs.writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`, 'utf-8')
|
||||
|
||||
console.log(`[update-package-json] 更新时间戳: ${packageJson['update-time']}`)
|
||||
} catch (error) {
|
||||
}
|
||||
catch (error) {
|
||||
console.error('[update-package-json] 插件执行失败:', error)
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user