Pass arguments to packaged electron application

后端 未结 2 978
清酒与你
清酒与你 2021-01-18 21:14

We\'re using electron-packager to bundle up and distribute the front-end of our web application. We need to be able to pass in the host and port of

2条回答
  •  感动是毒
    2021-01-18 22:11

    I recommend you to use a command line arguments management system like "minimist" for example.

    You can use this in your json : "start": "electron . --srv=server.com --prt=112 --arg3=myarg3"

    In your main.js you can use this :

    var args = require('minimist')(process.argv);
    
    console.log(args)
    

    and you can use your args in the main javascript file.

    For the Package, you can do the same thing but in the shortcut, by adding myapp.exe --srv=server.com --prt=112 --arg3=myarg3

提交回复
热议问题