How check if Vue is in development mode?

前端 未结 9 700
灰色年华
灰色年华 2021-01-03 18:14

When I run my Vue app, the console shows:

You are running Vue in development mode.
Make sure to turn on production mode when deploying for production.
See mo         


        
相关标签:
9条回答
  • 2021-01-03 19:03

    Webpack is used for almost all of my Vue projects, so I check to see if webpackHotUpdate is present.

     if (webpackHotUpdate) {
          console.log('In Dev Mode');
     }
    

    It's present in the window object if the webpack dev server is running.

    0 讨论(0)
  • 2021-01-03 19:13

    I know this is an old question but it may be helpful to new VueJS users to know this solution that I found in the current version of Vue (3.11):

    When running in dev mode the property Vue.config.devtools is true, in production mode it is false!

    0 讨论(0)
  • 2021-01-03 19:13

    Try using .env files.

    You can specify env variables by placing the following files in your project root:

    .env # loaded in all cases .env.local # loaded in all cases, ignored by git .env.[mode] # only loaded in specified mode .env.[mode].local # only loaded in specified mode, ignored by git

    plus

    Env Loading Priorities

    An env file for a specific mode (e.g. .env.production) will take higher priority than a generic one (e.g. .env).

    Docs: https://cli.vuejs.org/guide/mode-and-env.html#environment-variables

    0 讨论(0)
提交回复
热议问题