問題描述
我正在創(chuàng)建一個運行從 create-react-app 生成的反應的電子.然后我添加 nedbjs(一個持久性數(shù)據(jù)庫)和 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.
這是我的項目結(jié)構(gòu):
這是我的 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"
}
},
我使用命令 yarn electron-pack 來打包我的應用程序.然后從 dist 文件夾運行解壓后的可執(zhí)行文件然后得到這個錯誤:
I use command yarn electron-pack to package my app. And then running the unpacked executable from dist folder then got this error:
這里是 我的倉庫
推薦答案
要在您的電子構(gòu)建文件夾中添加文件或文件夾,您可以在 package.json 中添加 extraFiles 選項.這是一個復制憑據(jù)"目錄的示例:
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
希望對你有幫助
這篇關于如何使用電子生成器將文件夾和文件添加到電子構(gòu)建的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!