How to check if Angular application running in Production or Development mode

前端 未结 6 618
挽巷
挽巷 2020-12-07 17:27

This seems an easy one, but I couldn\'t find any solution.

So, how do I check if my app is running in production mode or dev mode?

6条回答
  •  情话喂你
    2020-12-07 17:53

    it depends on what you are asking...

    If you want to know the mode of Angular, as @yurzui said, you need to call { isDevMode } from @angular/core but it can return false only if you call enableProdMode before it.

    If you want to know the build environment, in other words, if your app is running minified or not, you need to set a build variable in your build system... Using Webpack, for example, you should have a look at definePlugin.

    https://webpack.github.io/docs/list-of-plugins.html#defineplugin

    new webpack.DefinePlugin({
      ENV_PRODUCTION: !!process.env.NODE_ENV
    });
    

提交回复
热议问题