/** * 将 static/icons 下的 tab 相关 SVG 转为 81x81 PNG,供 tabBar 使用 * 运行: node scripts/svg-to-png.js */ const fs = require('fs'); const path = require('path'); const dir = path.join(__dirname, '..', 'static', 'icons'); const names = [ 'tab-message', 'tab-message-active', 'tab-contacts', 'tab-contacts-active', 'tab-app', 'tab-app-active' ]; async function run() { let sharp; try { sharp = require('sharp'); } catch (e) { console.error('请先安装 sharp: npm install sharp'); process.exit(1); } const size = 81; for (const name of names) { const svgPath = path.join(dir, name + '.svg'); const pngPath = path.join(dir, name + '.png'); if (!fs.existsSync(svgPath)) { console.warn('跳过(不存在):', svgPath); continue; } const svg = fs.readFileSync(svgPath); await sharp(svg) .resize(size, size) .png() .toFile(pngPath); console.log('生成:', pngPath); } // 同步到构建输出目录,避免 tab 图标不更新 const distDir = path.join(__dirname, '..', 'unpackage', 'dist', 'dev', 'app-plus', 'static', 'icons'); if (fs.existsSync(distDir)) { for (const name of names) { const src = path.join(dir, name + '.png'); const dest = path.join(distDir, name + '.png'); if (fs.existsSync(src)) fs.copyFileSync(src, dest); } console.log('已同步到 unpackage/dist/dev/app-plus/static/icons/'); } console.log('完成。'); } run().catch((err) => { console.error(err); process.exit(1); });