babel-plugin-react-native
Features
This plugin was created to allow tree-shaking when building for multiple react-native platforms.
Install
npm install --save-dev --save-exact babel-plugin-react-native
Example
Source:
import { Platform } from 'react-native';
if (Platform.OS === 'web') {
console.log('web');
} else {
console.log('not web');
}
Transformed to (with OS: "web"
):
if ('web' === 'web') {
console.log('web');
} else {
console.log('not web');
}
Usage
babel.config.json
Via {
"plugins": [["babel-plugin-react-native", { "OS": "web" }]]
}