Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow removal of debug code in production builds #349

Merged
merged 1 commit into from
Feb 23, 2015
Merged

Conversation

tschaub
Copy link
Contributor

@tschaub tschaub commented Feb 18, 2015

By wrapping debug code in conditions with process.NODE_ENV !== 'production', people using compressors that do dead code removal can generate production builds without the debug code.

This is possible using Browserify with the envify transform before running code through Uglify (with --compress dead_code=true). React itself uses this same pattern.

@hai-cea
Copy link
Member

hai-cea commented Feb 21, 2015

Thanks @tschaub - It may be a good idea to create a utility function to do this? Something like:

Log.warn(...);
Log.error(...);
Log.debug(...);

That way we can keep the NODE_ENV check inside a single function.

@tschaub
Copy link
Contributor Author

tschaub commented Feb 22, 2015

@hai-cea I understand the desire to move the repeated code to utility functions, however I think that might defeat the purpose. The idea here is to keep the warning strings out of production builds. If the implementation of Log.warn has the process.NODE_ENV !== 'production' check, the body of the implementation will be removed, but the call sites (and warning strings) will remain.

Defining a const would be an alternative (e.g. const DEBUG = process.NODE_ENV !== 'production';). But I'm pretty sure this would need to appear in each module where it is used. A build flag is another alternative, but this isn't as widespread a convention as using NODE_ENV.

I understand if these checks seems like a hassle to maintain. And removing the warning strings from production builds is a pretty minor optimization. There would still be some benefit of a utility function that was a no-op in production.

hai-cea pushed a commit that referenced this pull request Feb 23, 2015
Allow removal of debug code in production builds
@hai-cea hai-cea merged commit 77247b5 into mui:master Feb 23, 2015
@hai-cea
Copy link
Member

hai-cea commented Feb 23, 2015

Thanks @tschaub - Makes sense to me.

@oliviertassinari
Copy link
Member

Why are we using process.NODE_ENV when react is using process.env.NODE_ENV ?

@tschaub
Copy link
Contributor Author

tschaub commented Apr 23, 2015

@oliviertassinari very bad typo. Needs to be fixed.

@oliviertassinari
Copy link
Member

@hai-cea @tschaub I have done a new PR to fix it #573

@mmrtnz
Copy link
Contributor

mmrtnz commented Apr 24, 2015

@oliviertassinari's PR has been merged

@zannager zannager added the component: button This is the name of the generic UI component, not the React module! label Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: button This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants