Open markrian opened 7 years ago
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
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?
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.
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 :wink:
https://github.com/husscode/babel-plugin-strip-invariant :rocket:
It'd be useful if the README referred to babel-plugin-dev-expression, or similar, as the way to actually strip out the messages passed to
invariant
whenNODE_ENV=production
.As it is, the source simply states:
but doesn't explain how that actually happens.
The README doesn't clear it up either; it says how to install
invariant
, but that alone won't result in the intended benefit of this module, that is, fewer bytes in production builds.Unless I'm missing something?