Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a url config file for Vue project

Tags:

vue.js

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

like image 434
Super Guo Avatar asked Jul 02 '18 09:07

Super Guo


People also ask

Where do I put Vue config?

It's simple just create file vue. config. js in ROOT folder of project.

How do I run a Vue project on localhost?

Open in browser To view the project, open a tab and type http://localhost:3000 into the URL bar. That's the address that the Node server is listening to. You should now see this page, which is the basic structure of our project.


1 Answers

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/

like image 197
channasmcs Avatar answered Oct 24 '22 15:10

channasmcs