node.js - 如何在 Yeoman Ember 应用程序中设置/获取环境特定变量

标签 node.js ember.js yeoman

考虑使用 Yeoman Ember 应用程序。

我看过不同的工具,例如:

但我不太明白如何根据某些 grunt/node 环境在 router.js 中设置/获取不同的适配器 url。

最佳答案

一种方法是拥有两个文件:development.properties 和 production.properties,并使用 grunt 将它们复制到 current.properties 文件,然后您可以始终读取 current.properties 文件,例如使用 nconf从您的应用程序的任何位置。

您只需在 grunt 文件中使用 grunt-contrib-copy 任务即可。

总结:创建一个 gruntfile,从命令行读取环境并将相应的文件属性复制到 current.properties,然后在你的 Route.js 中包含 nconf 并使用它。

另外,nconf 还可以在运行 Node 时从命令行读取参数,这样您就可以避免 grunt 文件并像 Node app.js --property=value 一样运行它并获取属性的值使用 Route.js 中的 nconf

关于node.js - 如何在 Yeoman Ember 应用程序中设置/获取环境特定变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20742882/

相关文章:

django - 使用主干/ Ember 使 Django 成为一个简单的 REST API?

javascript - Yeoman.io 在安装 generator-angular 时出现问题

node.js - MEAN 堆栈中缺少哈希前缀错误

javascript - Gulp 4 watch 未检测到更改

node.js - MongoDB 中的用户特定数据库

javascript - Ember JS : Pass data between routes

javascript - 使用 ember-data 的非 CRUD 操作

javascript - 将单页 Angular 应用程序模板集成到 Sails.js 中

gruntjs - 如何让Yeoman持续运行测试

node.js - Nodejs Dynamodb批量写入项目,如果项目存在则不覆盖