Vue.js build with different environment variables

Viewed 16020

I've used official Webpack template for Vue.js. It uses separate configuration for different environments. They offer test, development and production. However, I need another one as we have two production servers (one production and one staging).

What is the best practice to have different configurations for different production environments? I would think of something like npm run build --URL:http://some-url.com --PORT:80 ....

Any advice is welcome!

4 Answers

The variable process.env.NODE_ENV always has two values: development - production.

With this variable you can determine which url to use.

for example:

const API_URL = {
  development: "http://localhost/api/",
  productrion: "https://api.example.com/api/",
};
const baseURL = API_URL[process.env.NODE_ENV];
Related