我正在尝试构建一个带有react的电子应用程序,但是我的Windows选项没有被读取。
我首先运行react-scripts build创建build文件夹。然后,我运行npm run dist来运行构建配置。但是,它会建立错误的目标(默认nsis而不是msi)。
{
"name": "myApp",
"version": "0.1.0",
"main": "public/electron.js",
"private": true,
"dependencies": {
"@types/styled-components": "^4.1.16",
"bootstrap": "^4.3.1",
"electron-is-dev": "^1.1.0",
"jquery": "^3.4.1",
"moment": "^2.20.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-icons": "^3.7.0",
"react-picker": "^1.2.14",
"react-scripts": "^3.0.1",
"react-spinners": "^0.5.4",
"reactstrap": "^8.0.0",
"styled-components": "^4.3.1",
"tslint": "^5.17.0",
"typescript": "^3.5.2"
},
"scripts": {
"start": "react-scripts start",
"build": {
"appId": "myApp",
"extends": null,
"win": {
"title": "My App",
"version": "1.0",
"target": "msi",
"icon": "src/CITIcon.ico"
}
},
"test": "react-scripts test",
"eject": "react-scripts eject",
"electron-start": "electron .",
"pack": "build --dir",
"dist": "build"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"electron": "^5.0.3",
"electron-builder": "^20.43.0",
"tslint-config-prettier": "^1.18.0",
"tslint-eslint-rules": "^5.4.0",
"tslint-react": "^4.0.0"
}
}
当我运行npm run dist时,我得到以下输出
> windowsandon@0.1.0 dist
> build
• electron-builder version=20.43.0
• loaded parent configuration preset=react-cra
• description is missed in the package.json appPackageFile={myPath}\package.json
• author is missed in the package.json appPackageFile={myPath}\package.json
• writing effective config file=dist\builder-effective-config.yaml
• no native production dependencies
• packaging platform=win32 arch=x64 electron=5.0.3 appOutDir=dist\win-unpacked
• default Electron icon is used reason=application icon is not set
• building target=nsis file=dist\myApp Setup 0.1.0.exe archs=x64 oneClick=true perMachine=false
• building block map blockMapFile=dist\myApp Setup 0.1.0.exe.blockmap
目标应为msi,扩展名null应否定了“已加载的父配置”部分。
答案 0 :(得分:0)
我明白了。我必须从脚本对象中删除构建部分,并指定图标路径。
"scripts": {
"start": "react-scripts start",
"test": "react-scripts test",
"eject": "react-scripts eject",
"electron-start": "electron .",
"pack": "build --dir",
"dist": "build"
},
"build": {
"appId": "MyApp",
"extends": null,
"win": {
"icon": "./img/icon.ico",
"target": "msi"
}
},