/** electron-builder afterPack:仅保留 Windows x64 的 koffi 原生模块 */ const fs = require('fs') const path = require('path') const KOFFI_KEEP = new Set(['build', 'index.js', 'indirect.js', 'package.json', 'LICENSE.txt']) const NATIVE_PLATFORM = 'win32_x64' exports.default = async function afterPack(context) { const koffiRoot = path.join( context.appOutDir, 'resources', 'app.asar.unpacked', 'node_modules', 'koffi' ) if (!fs.existsSync(koffiRoot)) return for (const name of fs.readdirSync(koffiRoot)) { if (!KOFFI_KEEP.has(name)) { fs.rmSync(path.join(koffiRoot, name), { recursive: true, force: true }) } } const buildDir = path.join(koffiRoot, 'build', 'koffi') if (!fs.existsSync(buildDir)) return for (const plat of fs.readdirSync(buildDir)) { if (plat !== NATIVE_PLATFORM) { fs.rmSync(path.join(buildDir, plat), { recursive: true, force: true }) } } }