feat: 打包加固调整

This commit is contained in:
duanshuwen
2025-11-23 18:21:28 +08:00
parent 0b1e7a6679
commit 7eb2a13efe
7 changed files with 99 additions and 129 deletions

View File

@@ -14,19 +14,6 @@ export default function electronBytecode(options?: ElectronBytecodeOptions): Plu
apply: 'build',
async closeBundle() {
if (process.env.NODE_ENV !== 'production') return
const electronVersion = require('electron/package.json').version
const nodeVersion = process.version
const versionData = {
node: nodeVersion,
electron: electronVersion,
platform: process.platform,
arch: process.arch,
buildTime: new Date().toISOString()
}
const versionPath = path.resolve(process.cwd(), 'dist', 'version.json')
fs.ensureDirSync(path.dirname(versionPath))
fs.writeJsonSync(versionPath, versionData, { spaces: 2 })
const entryPath = path.resolve(process.cwd(), options?.entry || '.vite/build/main.js')
@@ -34,14 +21,13 @@ export default function electronBytecode(options?: ElectronBytecodeOptions): Plu
const outputPath = entryPath.replace(/\.js$/, '.jsc')
const backupPath = `${entryPath}.bak`
fs.copyFileSync(entryPath, backupPath)
await bytenode.compileFile({ filename: entryPath, output: outputPath })
if (!options?.keepSource) {
fs.removeSync(entryPath)
}
const stub = [
"require('bytenode')",
`require('./${path.basename(outputPath)}')`
].join("\n")
fs.writeFileSync(entryPath, stub)
}
}
}