chore: 移除未使用的插件和更新 package.json 的字段

This commit is contained in:
feige996
2025-07-12 11:37:32 +08:00
parent ffe4d25003
commit bd1490b1ee
4 changed files with 0 additions and 81 deletions

View File

@@ -1,41 +0,0 @@
import path from 'node:path'
import process from 'node:process'
import fs from 'fs-extra'
export function copyNativeRes() {
const waitPath = path.resolve(__dirname, '../src/nativeResources')
const buildPath = path.resolve(
__dirname,
'../dist',
process.env.NODE_ENV === 'production' ? 'build' : 'dev',
process.env.UNI_PLATFORM!,
'nativeResources',
)
return {
enforce: 'post',
async writeBundle() {
try {
// 检查源目录是否存在
const sourceExists = await fs.pathExists(waitPath)
if (!sourceExists) {
console.warn(`[copyNativeRes] 警告:源目录 "${waitPath}" 不存在,跳过复制操作。`)
return
}
// 确保目标目录及中间目录存在
await fs.ensureDir(buildPath)
console.log(`[copyNativeRes] 确保目标目录存在:${buildPath}`)
// 执行文件夹复制
await fs.copy(waitPath, buildPath)
console.log(
`[copyNativeRes] 成功将 nativeResources 目录中的资源移动到构建目录:${buildPath}`,
)
}
catch (error) {
console.error(`[copyNativeRes] 复制资源失败:`, error)
}
},
}
}

View File

@@ -1,37 +0,0 @@
// src/plugins/updatePackageJson.ts
import type { Plugin } from 'vite'
import fs from 'node:fs/promises'
import path from 'node:path'
import process from 'node:process'
function updatePackageJson(): Plugin {
return {
name: 'update-package-json',
async buildStart() {
// 只在生产环境构建时执行
if (process.env.NODE_ENV !== 'production')
return
const packageJsonPath = path.resolve(process.cwd(), 'package.json')
try {
// 读取并解析 package.json
const content = await fs.readFile(packageJsonPath, 'utf-8')
const packageJson = JSON.parse(content)
// 更新时间戳(使用 ISO 格式或自定义格式)
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')
console.log(`[update-package-json] 更新时间戳: ${packageJson['update-time']}`)
}
catch (error) {
console.error('[update-package-json] 插件执行失败:', error)
}
},
}
}
export default updatePackageJson