Friday, 18 September 2020

How can we pass parameters to an already built Vue JS app?

We have a Vue app that connects to a Web Service and get's some data. The web service URL is different, depending on the location we install the app on.

I first thought of using .env files, but later I realized these files get injected into the minified .js files.

Having this in my main.js was very convenient in the case of .env files:

Vue.prototype.ApiBaseUrl = process.env.VUE_APP_APIBASEURL
Vue.prototype.PrintDocsFolder = process.env.VUE_APP_PRINTDOCSFOLDER
Vue.prototype.TicketPrintWSocket = process.env.VUE_APP_TICKETPRINTWSOCKET   

The app is already built. I don't want to build the app for each of the hundred locations we have to deploy to. I'm not sure about the "official" approach for this.

Is there any out of the box solution in Vue that can allow this configuration? Basically we need to have a file in the root folder of the built app, and read values for our Vue.prototype.VARIABLES.

We are using vue-cli 3.



from How can we pass parameters to an already built Vue JS app?

No comments:

Post a Comment