ExtJS(5)Sencha构建不同环境的配置 [英] ExtJS (5) Sencha build configurations for different environments

查看:138
本文介绍了ExtJS(5)Sencha构建不同环境的配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个指向一个API的ExtJS 5.0应用程序。在开发中,我想使用 http:// localhost ,但在生产当然还有一些其他服务器。



sencha app build 中有没有办法从外面设置应用的变量?或者在代码中访问一些ENV变量?



如果有人可以帮助我会很棒。



谢谢非常多,



Sebastian

解决方案

这个,但我不知道这是最好的方法。在你的app.json中,你会发现这样一个部分:

  / ** 
*环境特定
*设置。
* /
production:{
banana:'no'
},
testing:{
banana:'yes'
},
开发:{

},



<显然,我已经添加了香蕉字段。我们不允许在生产中部署香蕉,所以我根据环境设置值是否。



然后在构建时,我是否做sencha应用程序构建测试或sencha应用程序构建生产,它将在相应的香蕉环境中构建环境的Ext.manifest对象。



所以在应用程序中,我可以通过以下方式访问该值:

  if(Ext.manifest.banana ===yes)

我假设你可以使用相同的技术来定义其他水果的领域,或者甚至与水果相关的数据。



我从本文中获得了想法:
当您启动您的应用程序,您会发现app.json的处理内容加载为Ext.manifest。
http://docs.sencha.com/cmd/5.x /microloader.html



像我说的,我不知道这是否是最好的方式,但我怀疑可能是。 >

I have an ExtJS 5.0 app that points to an API. On development, I'd like to use http://localhost but on production of course some other server.

Is there a way to set an app's variable from the outside during sencha app build ? Or access some ENV variable in the code?

Would be great if anybody could help me.

Thank you very much,

Sebastian

解决方案

I found a way of doing this but I am not sure it is the best way. In your app.json you will find a section like this:

/**
 * override objects for setting build environment specific 
 * settings.
 */
"production": {
    banana : 'no'
},
"testing": {
    banana : 'yes'
},
"development": {

},

Obviously I have added the banana field myself. We are not allowed to deploy a banana in production so I set the value yes or no based on the environment.

Then at build whether I do 'sencha app build testing' or 'sencha app build production' it will build in the respective banana value for the environment into the Ext.manifest object.

So in the application I can access the value through:

if (Ext.manifest.banana === "yes")

I presume you can use the same technique to define fields for other fruit, or perhaps even non-fruit related data.

I got the idea from this document: "When you launch your application, you will find the processed content of app.json loaded as "Ext.manifest"." http://docs.sencha.com/cmd/5.x/microloader.html

Like I said I don't know if this is the best way to do it but I suspect it might be.

这篇关于ExtJS(5)Sencha构建不同环境的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆