How to run and pack external executable using Electron?

喜你入骨 提交于 2019-11-30 21:54:19

There are two things. If you set __dirname: true in your web app config you will get the relative path of the file from your context directory

If you set __dirname: false then __dirname will have the full path.

Development Mode

You have two options

  1. Set __dirname: true and concatenate it with os.cwd()
  2. Set __dirname: false and use __dirname directly

Production Mode

  1. Set __dirname: true and use os.cwd().
  2. Set __dirname: true and use process.resourcePath

I will prefer 2 as the preferred approach in production

YASH GAUTAMI

Add this in package.json:

"scripts": {
    "start": "electron .", "install": "electron-rebuild",
    "package-osx": "electron-packager . Node-RED --platform=darwin --arch=x64 --   out=build --overwrite",
    "package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --prune=true --out=release-builds",
    "package-win": "electron-packager . electron-serialport --overwrite --asar=true --platform=win32 --arch=x64 --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"CryptoApp\"",
    "package-linux": "electron-packager . electron-serialport --overwrite --asar=true --platform=linux --arch=x64 --prune=true --out=release-builds"
},

"dependencies": {
    "electron-packager": "^12.1.0",
    "electron-prebuilt": "^1.4.13",
}

In case of not working for windows use the following:

"package-win": "electron-packager . electron-serialport --overwrite --asar=true --platform=win32 --arch=ia32 --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"CryptoApp\"",

Thanks...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!