打包命令为:"cross-env MODE=production npm run build --emptyOutDir && electron-builder build --config electron-builder.json --dir --config.asar=false"
使用"start": "concurrently -k 'npm run dev' 'npm run electron'"命令运行一切正常
electron-builder 打包后,单独运行应用程序,一片空白,调试器无报错
electron-builder.json配置内容如下:
{
"productName": "electron-vite-app",
"appId": "AppID",
"asar": true,
"directories": {
"output": "release/${version}"
},
"files": [
"src/main/index.js",
"dist/**/*"
],
"electronDownload": {
"mirror": "https://npmmirror.com/mirrors/electron/"
},
"mac": {
"icon": "build/icons/icon.icns",
"target": [
"dmg"
]
},
"dmg": {
"contents": [
{
"x": 410,
"y": 150,
"type": "link",
"path": "/Applications"
},
{
"x": 130,
"y": 150,
"type": "file"
}
]
},
"win": {
"target": [
{
"target": "nsis",
"arch": [
"x64"
]
}
],
"artifactName": "${productName}_${version}.${ext}"
},
"nsis": {
"oneClick": false,
"perMachine": false,
"allowToChangeInstallationDirectory": true,
"deleteAppDataOnUninstall": false
}
}
入口文件内容:
const { app, BrowserWindow, session } = require('electron')
const path = require('path')
function createWindow () {
const win = new BrowserWindow({
width: 1280,
height: 680,
frame: false,
maximizable: false,
title: 'app test',
webPreferences: {
nodeIntegration: true,
backgroundThrottling: false,
webSecurity: false,
}
})
let url =
process.env.NODE_ENV === "development"
? "http://localhost:3000"
: "app://" + path.join(__dirname, "../dist/index.html");
win.openDevTools({ mode: "detach" });
win.loadURL(url);
}
app.whenReady().then( async () => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
dist/index.html内容:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.17e50649.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>app test</title>
<script type="module" crossorigin src="/index.b3158158.js"></script>
<link rel="stylesheet" href="/index.cb8e0a9c.css">
</head>
<body>
<div id="app"></div>
</body>
</html>
求各位大佬指点一下。甚是感谢!
打包后的调试 推荐使用 debugtron 工具
https://github.com/bytedance/...