Electron Forge 卡在松鼠上
我一直在尝试打包一个电子应用程序,但它从未超越这个阶段:
我尝试了 3 次,每次都要花几个小时,但还是没有完成 squirrel 的打包。
package.json:
{
"name": "NAME",
"version": "0.1.0",
"private": false,
"author": "AUTHOR",
"description": "DESCRIPTION.",
"dependencies": {
"@emotion/react": "^11.10.0",
"@emotion/styled": "^11.10.0",
"@fortawesome/fontawesome-svg-core": "^6.1.2",
"@fortawesome/free-brands-svg-icons": "^6.1.2",
"@fortawesome/free-solid-svg-icons": "^6.1.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"@material-ui/core": "^4.12.4",
"@mui/material": "^5.9.2",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"bootstrap": "^5.2.0",
"cross-env": "^7.0.3",
"electron": "^19.0.10",
"electron-compile": "^6.4.4",
"electron-forge": "^5.2.4",
"electron-is-dev": "^2.0.0",
"react": "^18.2.0",
"react-bootstrap": "^2.4.0",
"react-dom": "^18.2.0",
"react-dropdown": "^1.10.0",
"react-modal": "^3.15.1",
"react-scripts": "5.0.1",
"reactjs-popup": "^2.0.5",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"dev": "concurrently -k \"cross-env BROWSER=none npm start\" \"npm:electron\"",
"electron": "wait-on tcp:3000 && electron .",
"package": "react-scripts build && electron-forge package",
"make-mac": "react-scripts build && electron-forge make --platform darwin",
"make-linux": "react-scripts build && electron-forge make --platform linux",
"make": "react-scripts build && electron-forge make"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"concurrently": "^7.3.0",
"electron-prebuilt-compile": "8.2.0",
"wait-on": "^6.0.1"
},
"main": "public/electron.js",
"homepage": "./",
"config": {
"forge": {
"packagerConfig": {},
"makers": [
{
"name": "@electron-forge/maker-squirrel",
"config": {
"name": "stock_trading_app"
}
},
{
"name": "@electron-forge/maker-zip",
"platforms": [
"darwin",
"linux",
"win32"
]
},
{
"name": "@electron-forge/maker-deb",
"config": {}
},
{
"name": "@electron-forge/maker-rpm",
"config": {}
}
]
}
}
}
我的
out > win32-x64
文件夹中出现了一个
application
文件,但它不是
.exe
文件。
我还有一个随机的
out > make > squirrel.windows > x64
文件夹,里面没有任何内容。
这个过程需要很长时间,因为您要打包整个应用程序,包括
node_modules
。
一个快速的解决方案是将参数
"asar": true
添加到
packagerConfig
1
。但除非您想打包未编译的文件,否则您可能只想保留
build
文件夹。
您已将脚本配置为在
make
之前运行
build
。现在,由于 Electron Forge 没有提供覆盖
dir
2
的选项,您将必须使用
ignore
选项来排除您不想在打包应用中拥有的文件和文件夹
3
。
packagerConfig: {
ignore: [
"^\\/public$",
"^\\/src$",
"^\\/node_modules$",
"^\\/[.].+",
// [...]
]
},
1.顺便说一下,我在
这里
、
这里
和
这里
找到了关于此内容的提及。
2. 如
文档
中所述 → “您无法覆盖
dir
、
arch
、
platform
、
out
或
electronVersion
选项,因为它们是由 Electron Forge 内部设置的。”
3. 请参阅
此答案
的另一个示例。