Babel plugin for React Native for Web


0.9.2-rc.03 years ago3 years agoMinified + gzip package size for @hushicai/babel-plugin-react-native-web in KB



npm version PRs Welcome

A Babel plugin that will alias react-native to react-native-web and exclude any modules not required by your app (keeping bundle size down).


yarn add --dev babel-plugin-react-native-web



  "plugins": [
    ["react-native-web", { commonjs: true }]

You should configure the plugin to match the module format used by your bundler. Most modern bundlers will use a package's ES modules by default (i.e., if package.json has a module field). But if you need the plugin to rewrite import paths to point to CommonJS modules, you must set the commonjs option to true.


NOTE: react-native-web internal paths are not stable and you must not rely on them. Always use the Babel plugin to optimize your build. What follows is an example of the rewrite performed by the plugin.


import { StyleSheet, View } from 'react-native';


import StyleSheet from 'react-native-web/dist/exports/StyleSheet';
import View from 'react-native-web/dist/exports/View';

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.