Open rico345100 opened 7 years ago
FWIW I'm seeing the same thing with almost identical code. But I've noticed something else:
gulp mytask
Does not work, even when I have b.transform(envify({ NODE_ENV: 'production' }))
in my pipeline
NODE_ENV=production gulp mytask
does work. It seems that envify
is ignoring the NODE_ENV
value specified.
@Kryten0807 I solved this problem without using this, could be useful in your current situation. This is the code what am I did: https://github.com/rico345100/gulp-react-boilerplate/blob/master/gulpfile.js
Important thing is that when you bundling React with bundler, it checks process.NODE_ENV is production or not. So it's super easy with just add this simple line anywhere before bundle:
process.env.NODE_ENV = 'production';
It's now 100% working, without adding NODE_ENV=production in command line :)
@rico345100
This works only because react contains envify
(or loose-envify
in recent versions) transform in package.json
itself. Therefore browserify executes it and inlines env
contents.
However it would not work for modules which are not configured that way.
The issue in the original post is caused by the fact that browserify does not run the transforms on node_modules
contents.
100% solution to that would be to provide global
flag with transform options to force the execution on all files.
b.transform(envify({
NODE_ENV: 'production'
}), {
global: true
});
@InvictusMB That's a really good information, Thanks! I'm gonna try that.
Correction to @InvictusMB, the config must come first:
browserify()
.require(requirements)
.transform({ global: true }, envify({NODE_ENV: 'production'}))
.bundle()
.pipe(output);
But ☝️ tripped me up because one must import envify/custom
(not envify
).
This also works:
const options = {
transform: [
['envify', { NODE_ENV: 'production', global: true}]
],
};
browserify(options)
.require(requirements)
.bundle()
.pipe(output);
I'm using Browserify, and when I minified JS code with using React and Redux, it saids:
So I added envify and used like this:
You can see that when it's production mode, it calls envify, also I printed "envify" on the console when it runs.
After run the browserify(with gulp), it saids 'envify':
But still same errors on the webbrowser's console:
I'm running multiple node services on single server, so I can't set NODE_ENV to production, because some of them are still in development mode. Is there a something that I missed? Why it won't worked at all?
I'm using