ExtJS (5) Sencha 不同环境的构建配置 [英] ExtJS (5) Sencha build configurations for different environments
问题描述
我有一个指向 API 的 ExtJS 5.0 应用程序.在开发上,我想使用http://localhost
,但在生产当然还有其他一些服务器.
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.
有没有办法在 sencha app build
期间从外部设置应用程序的变量?或者在代码中访问一些 ENV 变量?
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.
非常感谢,
塞巴斯蒂安
推荐答案
我找到了一种方法,但我不确定这是最好的方法.在您的 app.json 中,您会找到这样的部分:
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.
然后在构建时,无论我执行sencha app build testing"还是sencha app build production",它都会将环境的相应香蕉值构建到 Ext.manifest 对象中.
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.
我从这个文档中得到了这个想法:当你启动你的应用程序时,你会发现 app.json 的处理内容加载为Ext.manifest"."http://docs.sencha.com/cmd/5.x/microloader.html
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屋!