feat: 打包加固调整
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user