057285ed89
配置 electron-builder files 仅打 out 产物,移除未用依赖并将 Vue 生态移至 devDependencies;koffi 仅解包 win32_x64 并在 afterPack 裁剪;打包前清理旧 zip。
32 lines
939 B
JavaScript
32 lines
939 B
JavaScript
/** 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 })
|
|
}
|
|
}
|
|
}
|