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

How do i remove assert function calls #8657

Closed
trish123 opened this issue Mar 15, 2020 · 4 comments
Closed

How do i remove assert function calls #8657

trish123 opened this issue Mar 15, 2020 · 4 comments

Comments

@trish123
Copy link

trish123 commented Mar 15, 2020

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?

@sqal
Copy link

sqal commented Mar 15, 2020

You should use the first one. In production mode, this check will become false && assert(condition()) which will allow the miniifier to remove unused assert function from your code completely.

Here is a great article for you How Does the Development Mode Work?

@trish123
Copy link
Author

trish123 commented Mar 17, 2020

I am using the check - process.env.development - inside assert() function and evaluate the condtion only when process.env.development is true.

If i have to use that while calling assert, then everyone needs to remember to prepend assert() call with process.env.development .
It would be nice if all the assert had been removed like C#/JAVA (without ejecting)

@stale
Copy link

stale bot commented Apr 17, 2020

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Apr 17, 2020
@stale
Copy link

stale bot commented Apr 22, 2020

This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.

@stale stale bot closed this as completed Apr 22, 2020
@lock lock bot locked and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants