10

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

2
  • If you use webpack, have a look at this: stackoverflow.com/questions/44310260/… Commented Jul 2, 2018 at 9:37
  • It only able to config 2 different URL and for develop and production. But what I want is to config different URLs for production, which is the package after 'npm run build' Commented Jul 2, 2018 at 9:39

1 Answer 1

5

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/

Sign up to request clarification or add additional context in comments.

2 Comments

This is only able to edit before command 'npm run build'. Is there any possible to add a file to edit it after command 'npm run build'?
IN node need to rebuild compile and compack app js. that why npm run build important for that you can try with node super user. it use for collection of files to watch for changes github.com/petruisfan/node-supervisor

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.