I need to run React in production mode, which presumably entails defining the following somewhere in the enviornment:
process.env.NODE_ENV = \'production\';
Unfortunately none of the above answers work, because setting process.env.NODE_ENV
has no effect in Browserify. The resulting bundle still has process.env.NODE_ENV
references in it and hence
require()
the React production version modules,This is unfortunately not the only place where this approach is offered as the correct answer :-(
The correct approach can be found in e.g.
You need to switch the envify transform to be a global one, e.g.
# note the "-g" instead of the usual "-t"
$ browserify ... -g [ envify --NODE_ENV production ] ....
or in gulpfile.js
browserify(...)
...
.transform('envify', {
global: true, // also apply to node_modules
NODE_ENV: debug ? 'development' : 'production',
})
...
.bundle()
...
.pipe(gulpif(!debug, babelMinify())) // my example uses gulp-babel-minify
...