node.js - How to change environment variable such as 'process.env.NODE_ENV' in client side using webpack? -


i have javascript client side built webpack. using stats.js monitor frame rate. don't want show stats window in production mode. have tried of following:

  1. use defineplugin of webpack:

    new webpack.defineplugin({       'process.env.node_env': json.stringify(process.env.node_env || 'development') }), 
  2. in javascript file, use variable detect if in development mode or production mode.

    const isdevelopment = process.env.node_env !== 'production'; 

    then if isdevelopment true, use stats dom.

    if (isdevelopment) {     const stats = require('stats.js');     stats = new stats();     document.body.appendchild(stats.dom); } 
  3. pack client side in production mode:

    webpack -p --progress 
  4. run app in production mode (this server side):

    node_env=production port=8899 node server.js 

but these settings, supposedly run app in production mode, not stop client side displaying stats window on browser. clue wrong?

never mind. fixed putting node_env=production in front of webpack -p --progress. seems webpack doesn't change environment variable default when using -p argument. see issue.

so run webpack bundler following:

node_env=production webpack -p --progress 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -