Browserify production build is not optimized by default #3503
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey hey,
(formal bug report below, without as much context on my solution)
When using
browserify
to bundle a project that usesreact-router
, the default configuration of browserify transforms causes around 3kb of minified/gzipped warning messages to end up in the production bundles.The source of the problem is that by default browserify transforms do not run on packages in
node_modules
. Configuring those to run on the whole bundle is simple, but I believe this is counter-intuitive to the common "best practices", and people might overlook this.I imagine this hasn't been reported before because React users seem to use Webpack more than Browserify, and Webpack's
DefinePlugin
targets the whole bundle.facebook/react
handles this problem by depending onloose-envify
, and declaring the transform it in itspackage.json
. Since React itself does this I believe that react-router should follow the lead and not rely on users to do the right thing. That said, it's another burden on the package authors for something that can also be handled with appropriate configuration by users. It also needs to be done in https://github.com/mjackson/history, and a big number of other React-related projects I imagine.The other option is to document this issue in this project and others, by specifying the consequences (dev code in production, dead weight in the JS bundles) and fix (
global
flag for a transform that replacesNODE_ENV
and potentially other variables).Version
2.3.0, 2.4.1, and
history@2.1.2
(probably all ofreact-router@2
& other versions ofhistory
as well)Test Case
https://github.com/ThibWeb/react-router-browserify-build
(Warning: big file) L248 of https://github.com/ThibWeb/react-router-browserify-build/blob/master/bundle.js#L248.
Steps to reproduce
Compile a project using
react-router
with browserify, without running an "envify" transform over allnode_modules
(default behavior).Example:
NODE_ENV=production browserify index.js -t [ babelify ] -t [ envify ] > bundle.js
Expected Behavior
Messages intended for developers should be surrounded by
'production' !== 'production'
(or other env values for that matter) checks so that minification removes them.Actual Behavior
±3kb (gzipped) of development aid messages are kept in the bundle and make their way to production.