Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How check if Vue is in development mode?

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 more tips at https://vuejs.org/guide/deployment.html 

So now I want to check if Vue is in development from inside my templates by using:

console.log("mode is " + process.env.NODE_ENV) 

But that only logs undefined Is there a different way to find the NODE_ENV in Vue?

My webpack config has this part:

if (process.env.NODE_ENV === 'production') {   module.exports.devtool = '#source-map'   // http://vue-loader.vuejs.org/en/workflow/production.html   module.exports.plugins = (module.exports.plugins || []).concat([     new webpack.DefinePlugin({       'process.env': {         NODE_ENV: '"production"'       }     }),     new webpack.optimize.UglifyJsPlugin({       sourceMap: true,       compress: {         warnings: false       }     }),     new webpack.LoaderOptionsPlugin({       minimize: true     })   ]) } 

Perhaps relevant: I use typescript, so I included this type declaration:

declare var process: {     env: {         NODE_ENV: string     } } 
like image 939
Kokodoko Avatar asked Mar 13 '18 13:03

Kokodoko


People also ask

Is Vue js a development framework?

VueJS is an open source progressive JavaScript framework used to develop interactive web interfaces. It is one of the famous frameworks used to simplify web development. VueJS focusses on the view layer. It can be easily integrated into big projects for front-end development without any issues.

Is Vue JS MVC or MVVM?

js is an open-source model-view-view model (MVVM) JavaScript framework.

Can I use Vue JS 3 in production?

Can I use Vue 3 or should I still use Vue 2 for a new project? You can start your new production projects with Vue 3 - the core and subprojects are ready to use. Keep in mind that the ecosystem is still evolving, so some open-source components may not yet available in Vue 3 versions.


1 Answers

If you started with vue-cli (default webpack) then this should work:

  connection: process.env.NODE_ENV === 'development'     ? 'ws://localhost:5000'     : 'wss://myawsomeproject.org' 
like image 200
Thomas Avatar answered Oct 05 '22 06:10

Thomas