如何使用电子生成器将文件夹和文件添加到电子

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"
    }
  },

我使用命令 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

希望对你有帮助

这篇关于如何使用电子生成器将文件夹和文件添加到电子构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)