问题描述
我正在创建一个运行从 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" } },
我使用命令 yarn electron-pack 来打包我的应用程序.然后从 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
希望对你有帮助