Super Guo
Super Guo

Reputation: 133

How to add a url config file for Vue project

Is there any possible to add a config file for Vue project to config API URL?

Now I have a Vue web project, and a .Net Web API project.

I have to build the web project every time that I have to publish to different environment.

Is there any possible to add a config file like web.config for .Net Web API that I can edit it any time I want?

What I expected is, I can have a file to edit anytime I want after run command 'npm run build'. Is this possible

Upvotes: 10

Views: 12202

Answers (1)

channasmcs
channasmcs

Reputation: 1156

yes you can add config file if you use webpack

/config/prod.env.js

module.exports = {
NODE_ENV: '"production"', // or development
BASE_URL: '"https://BASEURL/"',
API_URL: '"https://APIURL/"',
}

Assig in build file and use

process.env.API_URL  

reference : https://alligator.io/vuejs/working-with-environment-variables/

Upvotes: 5

Related Questions