Managing application settings in an Electron application

给你一囗甜甜゛ 提交于 2019-12-06 04:06:01

I am not using an npm package but my approach is similar to what you have mentioned. I have a config directory with different config files for different environments: dev, test, prod. Then in my package.json I have added environment specific build commands. e.g. For prod:

"build-prod-config": "config/buildProdConfig.sh",
"build-renderer-prod": "webpack --config=webpack.config.renderer.prod.js",
"build-main-prod": "webpack --config=webpack.config.main.prod.js",
"build-prod": "npm run build-prod-config && npm run build-main-prod & npm run build-renderer-prod",

buildProdConfig.sh
#!/usr/bin/env bash

cp config/app.config.prod.js config/app.config.js
echo "Copied ProdConfig to Config"

//This is what a config file looks like
const Config = {
  suppDataDirectoryPath: '/suppData/',
  builtFor: 'prod',
}

module.exports = Config;

I then require Config whereever I need in my application and use the values. This is a simple thing for now, and perhaps doesn't have the flexibility of the config package you linked to, but it works.

Also, another important thing is that I am not packing my application into an ASAR archive, but I think my approach would still work because I am packing everything into a bundle using webpack.

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