Closed andrezsanchez closed 9 years ago
I have the exact same issue.
This means that production builds that require('react')
still have React console.warn()
in the console ...
You need to use a global transform for envify
to alter a package's code – by default, local transforms are only applied to your application and not to anything in node_modules
.
# Note the use of -g in place of -t
browserify -g [ envify --NODE_ENV production ] file.js
That being said, I believe envify
is applied to React automatically when it's bundled, in which case the problem you have here is that you're using command-line arguments instead of environment variables. They don't propagate their way downwards to react's transform if they're passed the same way as in your example.
I think the best approach would actually just be:
NODE_ENV=production browserify file.js
Ah okay, I thought I was missing something obvious, but I couldn't find the answer to this anywhere. I'm actually using this as part of a gulp pipeline, so I'm avoiding setting environment variables like this in favor of just having a --production
flag.
I am using gulp browserify. What is the equivalent of the "global" flag there? Anybody knows?
@Levino: excerpt from my 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
...
Meanwhile I switched to webpack. Thanks for finally answering my question though @stefanb2
I'm trying to use this transform on a project, but the transform doesn't seem to be replacing the environment variables within a library (specifically React, but I don't know if that makes a difference here).
To reproduce: