Comments (4)
shameless plug I've written a babel plugin that solves this. It's based on the transform @zebulonj mentioned, but re-written for babel v6 and v7. Plus a few customization options
https://github.com/husscode/babel-plugin-strip-invariant
from invariant.
I am trying to use this in a react-native project. I've added babel-plugin-dev-expression and in .babelrc -> plugins added babel-plugin-dev-expression. But get the error below when running the app.
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3099): SyntaxError: TransformError: /Users/aaa/dev/bbb-app/node_modules/react-native/packager/src/Resolver/polyfills/prelude_dev.js: /Users/aaa/dev/bbb-app/node_modules/react-native/packager/src/Resolver/polyfiBundling
index.ios.js``
Anyone know why?
react-native: v0.42.3
from invariant.
Came here looking for the same thing (what's the recommended approach for removing the messages in production builds). Only thing that immediately comes to mind:
function broadcast( message ) {
invariant( typeof message === 'string', process.env.NODE_ENV !== 'production' ? "Message must be defined." : undefined );
// Do some stuff here...
}
Is there not a better way?
from invariant.
Found this babel transform: https://github.com/bloodyowl/strip-invariant
Suspect Facebook is doing something similar (stripping message arguments in build), but don't have time to investigate at the moment.
from invariant.
Related Issues (20)
- No LICENSE file HOT 2
- Make message optional HOT 1
- 2.2.2 is somewhat broken... HOT 1
- Zero, the number should not throw HOT 1
- No PATENTS file ! HOT 3
- flow type definition more permissive than the actual code HOT 2
- Support ES Modules
- Question: is `process.env` possibly undefined? HOT 1
- Update license to MIT HOT 2
- Invariant can't be imported in TypeScript under jest vs metro-bundler/packager (in react-native) HOT 6
- The invariant message will be stripped in production? HOT 1
- not ok TypeError: "file" argument must be a non-empty string
- es module version?
- The `framesToPop` is puzzling me HOT 2
- Is there a specific reason to not allow `invariant(cond, message, ...args)` ? HOT 1
- Invariant Violation: Module is not a registered callable module (calling onShouldStartLoadWithRequest)
- The original intention of developing this library HOT 2
- Why?
- Audit vulnerabilities detected in the invariant project on Tag: v2.2.4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from invariant.