gpt4 book ai didi

javascript - debug/local ("grunt serve") 与 dist/build ("grunt") 的不同设置?

转载 作者:行者123 更新时间:2023-12-03 08:42:56 24 4
gpt4 key购买 nike

我想定义一些 application settings ,但我想根据我是否在“调试”模式下运行(例如 gruntserve)或最终编译的应用程序是否正在运行来提供不同的值(例如 grunt 的输出)。也就是说,类似于:

angular.module('myApp').factory('AppSettings', function() {
if (DebugMode()) { // ??
return { apiPort: 12345 };
} else {
return { apiPort: 8008 };
}
});

我怎样才能做到这一点?

最佳答案

我在应用程序中处理它的方式:

  1. 将一个环境的所有配置数据移至一个文件:config.js、config.json...您的应用认为易于阅读的任何内容。
  2. 现在修改您的配置文件,使用 grunt 配置值将其转换为模板,并使用 grunt-template 生成文件。作为构建的一部分 - 例如:app.constant('myAppConfig', {bananaHammocks: <%= banana.hammocks %>});
  3. 最后,添加grunt-stage根据环境切换 grunt 配置值:创建不同的 config/secret/(env).json文件,更新您的模板 ( app.constant('myAppConfig', {bananaHammocks: <%= stg.banana.hammocks %>}); ),然后 grunt stage:local:buildgrunt stage:prod:build

我发现这是复杂性和功能之间的良好平衡(环境之间的分离,运行时代码不关心构建选项,...)

关于javascript - debug/local ("grunt serve") 与 dist/build ("grunt") 的不同设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33003129/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com