babel-plugin-strip-invariant
Babel plugin to remove invariant arguments not needed during production builds.
Why is this necessary?
When using invariant, the actual detailed messages do not get minified away by default as they should. That happens because the minifier doesn't know you won't use the messages anymore.
This plugin solves that by removing all non-essential arguments from invariant calls.
Installation and Setup
Install the latest version of babel-plugin-strip-invariant:
npm install babel-plugin-strip-invariant --save-dev
Inside your .babelrc, configure this plugin to run only when building for production:
That's it! No more invariant messages cluttering production code.
Customization
Since invariant implementation is pretty small, maybe you wish to implement it yourself instead of relying on one more dependency. For that use case, you can customize how this plugin works:
Pragma
You can use a function name other than invariant
.
Than, when babel runs:
// source; // after transpilation;
ArgCount
You can specify the number of arguments to keep.
Than, when babel runs:
// source; // after transpilation;
You can mix both options too!
That's it! If you've liked this, consider giving it a star ⭐️!
Copyright & License
Copyright (c) 2018 Marcel de Oliveira Coelho under the MIT License. Go Crazy. 🚀