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:
use
definepluginof webpack:new webpack.defineplugin({ 'process.env.node_env': json.stringify(process.env.node_env || 'development') }),in javascript file, use variable detect if in development mode or production mode.
const isdevelopment = process.env.node_env !== 'production';then if
isdevelopmenttrue, use stats dom.if (isdevelopment) { const stats = require('stats.js'); stats = new stats(); document.body.appendchild(stats.dom); }pack client side in production mode:
webpack -p --progressrun 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
Post a Comment