如何通过 Atom 在 Node.js 中有条件地设置属性?
How can I set properties conditionally in Node.js via Atom?
我正在通过 Atom 使用 Electron 开发 Node.js 应用程序。
我想有条件地(或自动地)设置一些属性,例如,url
在生产级别上应该是 http://some.url
。
目前我是这样用的
// win.loadURL('http://app.url/webchat'); //uncomment when production
win.loadURL('http://test.app.url/webchat'); // uncomment when development
这让我很恼火,当我错过更改评论时,这可能是个问题。
如何在 production/development 级别有条件地更改我的属性?
if (process.env.DEV === "PROD") {
win.loadURL('http://app.url/webchat');
} else {
win.loadURL('http://test.app.url/webchat');
}
然后在启动您的应用程序时执行
DEV="PROD" node app.js
或者什么
我有一个配置目录,其中包含针对不同环境的不同配置文件:dev、test、prod。然后在我的 package.json 中添加了特定于环境的构建命令。例如对于产品:
"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;
然后我在我的应用程序中需要的任何地方都需要配置并使用这些值。目前这是一件简单的事情,但它确实有效。
我正在通过 Atom 使用 Electron 开发 Node.js 应用程序。
我想有条件地(或自动地)设置一些属性,例如,url
在生产级别上应该是 http://some.url
。
目前我是这样用的
// win.loadURL('http://app.url/webchat'); //uncomment when production
win.loadURL('http://test.app.url/webchat'); // uncomment when development
这让我很恼火,当我错过更改评论时,这可能是个问题。
如何在 production/development 级别有条件地更改我的属性?
if (process.env.DEV === "PROD") {
win.loadURL('http://app.url/webchat');
} else {
win.loadURL('http://test.app.url/webchat');
}
然后在启动您的应用程序时执行
DEV="PROD" node app.js
或者什么
我有一个配置目录,其中包含针对不同环境的不同配置文件:dev、test、prod。然后在我的 package.json 中添加了特定于环境的构建命令。例如对于产品:
"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;
然后我在我的应用程序中需要的任何地方都需要配置并使用这些值。目前这是一件简单的事情,但它确实有效。