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
ExtJS stands for Extended JavaScript. It is a JavaScript framework and a product of Sencha, based on YUI (Yahoo User Interface). It is basically a desktop application development platform with modern UI.
Ext JS 7.0 Version 7.0 of Ext JS framework was released on August 29, 2019.
Run Ext JS Web Application: Open command prompt in windows and navigate to the directory where you have your Ext JS application as shown below. Now, enter Sencha web –port xxxx start command as shown below. Use any unused port number.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With