How to run and pack external executable using Electron?

前端 未结 2 744
有刺的猬
有刺的猬 2021-01-05 21:14

For example, I have a compiled binary cudaDeviceQuery which returns a list of devices as JSON. Here\'s a piece of code:

export default function          


        
相关标签:
2条回答
  • 2021-01-05 21:49

    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...

    0 讨论(0)
  • 2021-01-05 22:00

    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

    0 讨论(0)
提交回复
热议问题