参照你们的回复, 自己弄了个方法, 去除 node-pty 生成的 node_gyp_bins 文件夹
electron-builder 配置项里的 afterPack:
afterPack: async (pack) => {
const dir = join(pack.appOutDir, '
PhpWebStudy.app/Contents/Resources')
const optdefault = { env: process.env, cwd: dir }
if (!optdefault.env['PATH']) {
optdefault.env['PATH'] =
'/opt:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin'
} else {
optdefault.env[
'PATH'
] = `/opt:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:${optdefault.env['PATH']}`
}
execSync('asar e app.asar app', optdefault)
execSync('rm -rf app/node_modules/node-pty/build/node_gyp_bins', optdefault)
execSync('rm -rf app.asar', optdefault)
execSync('asar pack app app.asar', optdefault)
execSync('rm -rf app', optdefault)
console.log('afterPack handle end !!!!!!')
return true
}
里面的 PhpWebStudy 换成自己的 app 名字