You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Idea: Wrap usage of debug in NODE_ENV !== 'production' check #57
This would enable users to optimize their builds using a tool like envify. I have talked a little before about how I think the debug module is not a great overall solution because it loads and runs even when it is turned off. In this case, my production browser builds get an extra ~4.5kb that they will never use.
I know there are downsides to this, but I just wanted to bring it up in case anyone was interested in this.
I think it's tricky to make something happen over the entire module world like this (e.g. Make every module adopt this pattern to be useful). Instead, I'd suggest the alternative of replacing all instances with a proxy module in production or proposing something directly to the debug module. Maybe we could build better code mod tooling also to remove debug calls in production (this is something I've been interested in, happy to take a look next week since I hadn't considered this as the use case).
I agree on all points. I think getting something into the debug module itself is the best idea because adoption is clearly the hard part here. I will go take a look to see if there is something simple we could do there to resolve this issue.
Yea, I can definitely see cutting out unnecessary dependencies from packed builds (especially for front-ends), though if there was a generic way to do this across all debug-using packages that would be best, but not always a blocker if there is a good use.
If any wrapper, it would probably make sense to wrap with process.env.DEBUG being blank, rather than based off process.env.NODE_ENV, since it is likely (and in my experience, must likely) to use debugging in production (since in dev you can easily run under a debugger / modify things at will).
As an additional note, I have "nooped-out" some sub modules recently using Webpack, by storing a noop version of it locally and aliasing to that local stub when packing. That works, but not the best since now we have to keep the stub in sync ourselves, but helps us slim the builds on our terms.
Just to add a note here. The debug module is a bad pattern. It always was and I will die on that hill (as in I have a personal goal to replace it with pino or something which is a real logger which is passed into each package in the ecosystem. That is a tangent for here though, so I am just closing.
Activity
blakeembrey commentedon Jun 17, 2017
I think it's tricky to make something happen over the entire module world like this (e.g. Make every module adopt this pattern to be useful). Instead, I'd suggest the alternative of replacing all instances with a proxy module in production or proposing something directly to the debug module. Maybe we could build better code mod tooling also to remove debug calls in production (this is something I've been interested in, happy to take a look next week since I hadn't considered this as the use case).
wesleytodd commentedon Jun 17, 2017
I agree on all points. I think getting something into the debug module itself is the best idea because adoption is clearly the hard part here. I will go take a look to see if there is something simple we could do there to resolve this issue.
dougwilson commentedon Jun 19, 2017
Yea, I can definitely see cutting out unnecessary dependencies from packed builds (especially for front-ends), though if there was a generic way to do this across all debug-using packages that would be best, but not always a blocker if there is a good use.
If any wrapper, it would probably make sense to wrap with process.env.DEBUG being blank, rather than based off process.env.NODE_ENV, since it is likely (and in my experience, must likely) to use debugging in production (since in dev you can easily run under a debugger / modify things at will).
As an additional note, I have "nooped-out" some sub modules recently using Webpack, by storing a noop version of it locally and aliasing to that local stub when packing. That works, but not the best since now we have to keep the stub in sync ourselves, but helps us slim the builds on our terms.
wesleytodd commentedon Jun 19, 2017
Agreed, and the solution I posted here does not really do that. If you have a better idea I would love to hear it.
Not sure about this, because usually the
DEBUGvar is set in runtime, where this is a build time operation. Not sure how to reconcile the difference.This is what I have done in our prod builds, but it has not been fun to maintain. I am really looking for a better solution, thus this post.
wesleytodd commentedon Mar 16, 2024
Cleaning up old issues.
Just to add a note here. The
debugmodule is a bad pattern. It always was and I will die on that hill (as in I have a personal goal to replace it withpinoor something which is a real logger which is passed into each package in the ecosystem. That is a tangent for here though, so I am just closing.