2

How can I know the Vue.js environment is development or production ?

In my AxiosConfig's config.js:

AxiosConfig:{
    baseURL:dev.NODE_ENV.BASE_API,
    responseType: "json",
    withCredentials: true,
    ...

You see the BASE_API in there:

there is the definition of dev.NODE_ENV:

  dev.NODE_ENV = {
    BASE_API: 'http://localhost:8000',
    APP_ORIGIN: 'http://103.20.32.16:8000/'
  }

How can I check the environment is development or production?

then in the AxiosConfig config.js I can use the judgement, when npm run build I will not need to change thebaseURL` then.

1

3 Answers 3

4

Take a look at process.env.NODE_ENV and test for development or production. You might want to replace your dev.NODE_ENV.BASE_API with something like process.env.NODE_ENV.BASE_API.

Further to this, if you're using the vue-cli-service to bootstrap and build your app, you can use .env files and switch the baseURL using those, depending upon your environment. You can find out about it in more detail here: https://cli.vuejs.org/guide/mode-and-env.html

2
0

Just in case you're in a browser, like me (using vue.esm-browser[.prod].js), you can also use this:

if (window.__VUE_DEVTOOLS_GLOBAL_HOOK__.enabled) {
    ... // do stuff
}

This is only true in development mode. I use this in my console logging .

-1

as normally when you run the command npm run dev then it will be a webpack development server and if you run npm run build then it will be for production use and it will make a minified version of it in the dist folder

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.