考虑使用 Yeoman Ember 应用程序。
我看过不同的工具,例如:
- https://github.com/logankoester/grunt-environment
- https://github.com/jsoverson/grunt-env
- https://github.com/outaTiME/grunt-config
但我不太明白如何根据某些 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/