build: strip macOS Electron binaries after pack
This commit is contained in:
parent
84f3282bbd
commit
413ede2487
@ -22,6 +22,7 @@
|
||||
"electronLanguages": [
|
||||
"en"
|
||||
],
|
||||
"afterPack": "./scripts/strip-macos-binaries.js",
|
||||
"files": [
|
||||
"src/**/*",
|
||||
"assets/**/*",
|
||||
|
||||
39
scripts/strip-macos-binaries.js
Normal file
39
scripts/strip-macos-binaries.js
Normal file
@ -0,0 +1,39 @@
|
||||
const { execFileSync } = require('node:child_process');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
function walk(dir, out = []) {
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) walk(full, out);
|
||||
else out.push(full);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function isMachO(file) {
|
||||
try {
|
||||
const out = execFileSync('file', ['-b', file], { encoding: 'utf8' });
|
||||
return out.includes('Mach-O');
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
exports.default = async function afterPack(context) {
|
||||
if (context.electronPlatformName !== 'darwin') return;
|
||||
|
||||
const appOutDir = context.appOutDir;
|
||||
const appName = `${context.packager.appInfo.productFilename}.app`;
|
||||
const appPath = path.join(appOutDir, appName);
|
||||
|
||||
const targets = walk(appPath).filter(isMachO);
|
||||
|
||||
for (const file of targets) {
|
||||
try {
|
||||
execFileSync('strip', ['-x', file], { stdio: 'inherit' });
|
||||
} catch (err) {
|
||||
console.warn(`[strip] skipped ${file}: ${err.message}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user