Skip to content

How do i remove assert function calls #8657

Closed
@trish123

Description

@trish123

I have written an assert function which checks the "development mode" and then check the condtion and throws if the condtion is false. In the production mode, webpack removes the function body.

I would like to remove the call - assert(condition()) - scattered inside my code base in production. I am ok with an empty assert function call but the assert argument - condition() - can be an expensive function call. That's what i want to avoid.

  1. One way is to check process.env.development && assert(condition()) everywhere.
  2. Another way is that i can pass a predicate function to assert and let the assert evaluate it after the development mode check.
  3. Another way is to use some webpack loader to strip function calls. Not sure, how safe it is and I think it is not possible to do that without ejecting.

what is the correct way to do this?

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