Skip to content

Idea: Wrap usage of debug in NODE_ENV !== 'production' check #57

Closed

Description

@wesleytodd

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.

Activity

  1. blakeembrey commented on Jun 17, 2017

    @blakeembrey
    Member

    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).

  2. wesleytodd commented on Jun 17, 2017

    @wesleytodd
    MemberAuthor

    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.

  3. dougwilson commented on Jun 19, 2017

    @dougwilson
    Contributor

    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.

  4. wesleytodd commented on Jun 19, 2017

    @wesleytodd
    MemberAuthor

    but not always a blocker if there is a good use

    Agreed, and the solution I posted here does not really do that. If you have a better idea I would love to hear it.

    it would probably make sense to wrap with process.env.DEBUG being blank

    Not sure about this, because usually the DEBUG var is set in runtime, where this is a build time operation. Not sure how to reconcile the difference.

    As an additional note, I have "nooped-out" some sub modules recently using Webpack

    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.

  5. wesleytodd commented on Mar 16, 2024

    @wesleytodd
    MemberAuthor

    Cleaning up old issues.

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions