feat: 打包加固调整
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
const fs = require('fs')
|
||||
const { execSync } = require('child_process')
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
|
||||
function cleanDirectory(dirPath) {
|
||||
const resolvedPath = path.resolve(dirPath)
|
||||
function cleanOutRoot() {
|
||||
const outDir = path.resolve(process.cwd(), 'out')
|
||||
|
||||
const parentDir = path.basename(path.dirname(resolvedPath))
|
||||
if (parentDir !== 'out') {
|
||||
console.error(`Error: Directory "${resolvedPath}" is not inside a "out" folder`)
|
||||
if (!fs.pathExistsSync(outDir)) {
|
||||
return
|
||||
}
|
||||
|
||||
const distPath = path.join(resolvedPath, 'dist')
|
||||
|
||||
if (fs.existsSync(distPath)) {
|
||||
fs.rmSync(distPath, { recursive: true, force: true })
|
||||
console.log(`deleted: ${distPath}`)
|
||||
fs.removeSync(outDir)
|
||||
|
||||
if (fs.pathExistsSync(outDir)) {
|
||||
execSync(`cmd /c rd /s /q "${outDir}"`, { stdio: 'ignore' })
|
||||
|
||||
process.exitCode = 1
|
||||
}
|
||||
}
|
||||
|
||||
cleanDirectory(process.cwd())
|
||||
cleanOutRoot()
|
||||
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
if (!fs.existsSync(path.join(process.cwd(), 'dist/main/build.jsc'))) {
|
||||
throw new Error('字节码文件未找到,请先执行编译')
|
||||
const entryPath = path.join(process.cwd(), '.vite/build/main.js')
|
||||
const jscPath = path.join(process.cwd(), '.vite/build/main.jsc')
|
||||
if (!fs.existsSync(entryPath)) {
|
||||
throw new Error('主进程入口未找到,请先构建主进程')
|
||||
}
|
||||
if (!fs.existsSync(jscPath)) {
|
||||
const bytenode = require('bytenode')
|
||||
bytenode.compileFile({ filename: entryPath, output: jscPath })
|
||||
}
|
||||
|
||||
const content = `
|
||||
const {app} = require('electron');
|
||||
require('bytenode');
|
||||
require('./index.jsc);
|
||||
`
|
||||
const content = [
|
||||
"require('bytenode')",
|
||||
"require('./main.jsc')"
|
||||
].join('\n')
|
||||
|
||||
const outputPath = path.join(process.cwd(), 'dist/main/build.js')
|
||||
const outputPath = entryPath
|
||||
|
||||
// 确保目录存在
|
||||
fs.mkdirSync(path.dirname(outputPath), { recursive: true })
|
||||
|
||||
// 写入文件
|
||||
fs.writeFileSync(outputPath, content.trim())
|
||||
console.log(`生产环境入口文件已生成: ${outputPath}`)
|
||||
fs.writeFileSync(outputPath, content)
|
||||
console.log(`生产环境入口文件已生成: ${outputPath}`)
|
||||
|
||||
Reference in New Issue
Block a user