How check if Vue is in development mode?

前端 未结 9 746
灰色年华
灰色年华 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 18:55

    This is how Vue checks wether it is in development mode:

    if (process.env.NODE_ENV !== 'production' &&
      process.env.NODE_ENV !== 'test' &&
      typeof console !== 'undefined'
    )
    

    Source: GitHub

    Note: I removed the check config.productionTip !== false from the code, because it is used only to turn off the "production tip" even if Vue is running in in development mode.

    Gene Parcellano's answer works great as long as you are using Webpack, but this might be a bit more robust.

    Edit:

    It would be easy to combine both answers like that:

    if (
      window.webpackHotUpdate || (
        process.env.NODE_ENV !== "production" &&
        process.env.NODE_ENV !== "test" &&
        typeof console !== "undefined"
      )
    )
    

提交回复
热议问题