Vue & Webpack: Global development and production variables

Viewed 833

I'm using vue-cli to build my web app. My app uses an api in a number of places like so:

axios.post(API + '/sign-up', data).then(res => {
  // do stuff
});

The API variable is a constant containing the beginning of the address, e.g., https://example.com.

How would I detect whether this is a dev or prod build and set that variable accordingly? For now, I have a script tag in my index.html document and I am manually changing it for dev and prod:

<script>var API = 'https://example.com'</script>

Is there a better way to handle this?

1 Answers
Related