如何使用电子生成器将文件夹和文件添加到电子生成 [英] How to add folders and files to electron build using electron-builder
问题描述
我正在创建一个电子,该电子会运行由create-react-app生成的反应。然后我添加nedbjs(一个持久性数据库)和camojs(nedb的ODM)作为依赖项。要连接与nedb的反应,我使用电子ipc。
I am creating an electron which running react generated from create-react-app. Then i add nedbjs(a persistence database) and camojs(ODM for nedb) as dependency. To connect react with nedb i use electron ipc.
这是我的项目结构:
这是我的package.json:
And here is my package.json:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"electron-dev": "concurrently \"cross-env BROWSER=none yarn start\" \"wait-on http://localhost:3000 && electron .\"",
"electron-pack": "build --em.main=build/electron.js",
"electron-release": "build --em.main=build/electron.js --publish=always",
"preelectron-pack": "yarn build",
"preelectron-release": "yarn build"
},
"build": {
"appId": "com.example.cra-electron-boilerplate",
"files": [
"build/**/*",
"node_modules/**/*",
"package.json"
],
"directories": {
"buildResources": "assets"
},
"publish": {
"provider": "github"
}
},
我使用命令毛线电子包装来打包我的应用程序。然后从dist文件夹运行解压缩的可执行文件,然后出现以下错误:
I use command yarn electron-pack to package my app. And then running the unpacked executable from dist folder then got this error:
这里是我的仓库
推荐答案
要在电子构建文件夹中添加文件或文件夹,可以在package.json上添加extraFiles选项。
下面是复制凭据目录的示例:
To add a file or folder on your electron build folder, you can add the extraFiles options on package.json. Here is an example to copy a "credential" directory:
"build": {
"appId": "com.example.electron-boilerplate",
"files": [
"app/**/*",
"node_modules/**/*",
"package.json"
],
"directories": {
"buildResources": "resources"
},
"extraFiles": [
"credentials"
],
"publish": null
},
然后
$ npm run release // as usual
希望这会有所帮助
这篇关于如何使用电子生成器将文件夹和文件添加到电子生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!