Speed up Electron client packaging by filtering prebuilds
Release rolling / release (push) Has been cancelled
Release rolling / release (push) Has been cancelled
Only ship native prebuilds for the target platform/arch (~80MB instead of ~500MB of multi-arch blobs), skip redundant GUI rebundles, cache Electron downloads across hosts, and strip more packaging-only deps so "Finalizing package" no longer crawls multi-hundred-MB asars six times.
This commit is contained in:
+20
-4
@@ -15,7 +15,12 @@
|
||||
|
||||
const path = require('path')
|
||||
const { spawnSync } = require('child_process')
|
||||
const { ALL_64, parseHostList, clientNpmScript } = require('./hosts.cjs')
|
||||
const {
|
||||
ALL_64,
|
||||
parseHostList,
|
||||
clientNpmScript,
|
||||
hostToElectron,
|
||||
} = require('./hosts.cjs')
|
||||
|
||||
const root = path.resolve(__dirname, '..')
|
||||
|
||||
@@ -24,6 +29,7 @@ const CLIENT_HOSTS = parseHostList(process.env.PEARDOCK_CLIENT_HOSTS, ALL_64)
|
||||
|
||||
function run(cmd, args, opts = {}) {
|
||||
console.log(`\n$ ${cmd} ${args.join(' ')}\n`)
|
||||
const t0 = Date.now()
|
||||
const res = spawnSync(cmd, args, {
|
||||
cwd: root,
|
||||
stdio: 'inherit',
|
||||
@@ -33,10 +39,13 @@ function run(cmd, args, opts = {}) {
|
||||
})
|
||||
if (res.error) throw res.error
|
||||
if (res.status !== 0) process.exit(res.status || 1)
|
||||
console.log(`[make] ok in ${((Date.now() - t0) / 1000).toFixed(1)}s`)
|
||||
}
|
||||
|
||||
function npmRun(script) {
|
||||
run(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['run', script])
|
||||
function npmRun(script, env) {
|
||||
run(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['run', script], {
|
||||
env: env ? { ...process.env, ...env } : process.env,
|
||||
})
|
||||
}
|
||||
|
||||
function makeServer(hosts = SERVER_HOSTS) {
|
||||
@@ -54,6 +63,7 @@ function makeServer(hosts = SERVER_HOSTS) {
|
||||
|
||||
function makeClient(hosts = CLIENT_HOSTS) {
|
||||
console.log(`[make] client hosts: ${hosts.join(', ')}`)
|
||||
// Build GUI bundle once; forge prePackage skips rebuild when this is set
|
||||
npmRun('build:client-bundle')
|
||||
for (const host of hosts) {
|
||||
const script = clientNpmScript(host)
|
||||
@@ -61,11 +71,17 @@ function makeClient(hosts = CLIENT_HOSTS) {
|
||||
console.error(`[make] no client script for host ${host}`)
|
||||
process.exit(1)
|
||||
}
|
||||
// Prefer prebuilds; skip native rebuild (cross-arch rebuild is slow/fails)
|
||||
const { platform, arch } = hostToElectron(host)
|
||||
console.log(`[make] client ${host} (filter prebuilds to ${platform}-${arch})`)
|
||||
// Prefer prebuilds; skip native rebuild (cross-arch rebuild is slow/fails).
|
||||
// PEARDOCK_PACKAGE_* tells forge.config to ignore foreign prebuilds (~500MB → ~30MB).
|
||||
const env = {
|
||||
...process.env,
|
||||
npm_config_build_from_source: 'false',
|
||||
PEARDOCK_SKIP_REBUILD: process.env.PEARDOCK_SKIP_REBUILD || '1',
|
||||
PEARDOCK_PACKAGE_PLATFORM: platform,
|
||||
PEARDOCK_PACKAGE_ARCH: arch,
|
||||
PEARDOCK_SKIP_PREPACKAGE_BUNDLE: '1',
|
||||
}
|
||||
run(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['run', script], { env })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user