kit chan kit chan - 6 months ago 50
Node.js Question

envify in react.js doesn't work

I am new to node.js and react.js.
I recently learn react.js and follow the instruction on react.js offical page and try to use production mode.
So i start with the code in main.js

var React = require('react');
var ReactDOM = require('react-dom');

ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('example')
);


and browserify it

$ browserify -t [ babelify --presets [ react ] ] -t [ envify --NODE_ENV production ] main.js -o bundle.js


But envify seems not work. The result bundle code still contain

process.env.NODE_ENV


Is something wrong? I 've tried to set
process.env.NODE_ENV='production'
in the main.js. But it doesnt work. can anyone help me? thanks.

Answer

Set the NODE_ENV variable in the shell instead.

NODE_ENV=production browserify -t [ babelify --presets [ react ] ] -t envify main.js -o bundle.js