Electron在包上添加资源文件

时间:2017-11-30 16:02:00

标签: electron packaging enoent

我正在构建我的第一个电子应用程序,但我无法打包它。

当我使用npm start进行测试时,一切正常,但是当我尝试打包它并完成时,我会运行它,但我得到类似ENOENT: no such file or directory, lstat的内容。

我有这样的来源。

fs.copy(path.resolve('src/app/resource/'), dir + '/resource/', e => {
                if (e) {
                    reject(e);
                    return;
                }
                resolve(true);
            });

这会将文件复制到指定的目录,看起来这是错误的原因。

修改

我启用了devtools并为windows创建了安装程序,但只是得到了这个。 enter image description here 看来我的文件不包含在构建中。

这是我的package.json

{
  "name": "exporter",
  "productName": "Exporter",
  "version": "0.0.1",
  "description": "",
  "license": "MIT",
  "repository": "",
  "author": {
    "name": "",
    "email": "",
    "url": "none"
  },
  "scripts": {
    "start": "electron .",
    "build": "electron-packager . --out=/mnt/Busy\\ Drive/dist/exporter --asar --overwrite --all",
    "pack": "build --dir",
    "dist": "build -wl"
  },
  "dependencies": {
    "bootstrap": "^4.0.0-beta",
    "config": "^1.28.1",
    "electron-debug": "^1.0.0",
    "fs-extra": "^4.0.2",
    "is-electron-renderer": "^2.0.1",
    "jquery": "^3.2.1",
    "mysql": "^2.15.0",
    "popper.js": "^1.13.0",
    "winston": "^2.4.0"
  },
  "devDependencies": {
    "devtron": "^1.1.0",
    "electron": "^1.8.1",
    "electron-builder": "^19.47.1",
    "electron-builder-squirrel-windows": "^19.47.0",
    "electron-packager": "^8.0.0",
    "eslint": "^4.11.0",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-node": "^5.2.1",
    "eslint-plugin-promise": "^3.6.0",
    "eslint-plugin-standard": "^3.0.1"
  },
  "build": {
    "appId": "no-id",
    "linux": {
      "target": [
        "dir"
      ]
    },
    "win": {
      "target": "nsis"
    }
  }
}

我已经尝试了不同的打包器,但仍然没有成功。 我的package.json上有错吗?

1 个答案:

答案 0 :(得分:2)

罪魁祸首是使用path.resolve,你应该使用path.join(__dirname, 'your/path/here'),因此它可以访问asar文件。