Before diving deep into Re.Pack and introducing it into project, it's important to understand when and why to use Re.Pack and how does it compare with alternatives.
React Native environment and Browser environment have differences. React Native needs to run additional JS setup/init code so that it's usable at all. There's a great discrepancy between available APIs. In React Native we also have platform specific files — e.g.: .ios.js
, .android.js
and so on.
Putting all the above together, makes Webpack unable to produce bundle at all due to build errors and then the bundle produced by Webpack is unusable by default.
Therefore, we need to make changes to Webpack configuration and change how and what Webpack puts into the final bundle. All these necessary changes are encapsulated inside Re.Pack in form of Webpack plugins.
So to answer the question:
Re.Pack is what makes Webpack and Webpack-produced bundle usable in React Native application. Additionally, Re.Pack is what allows us to use Code Splitting powered by Webpack inside React Native applications.
The main feature of Re.Pack is Webpack and its ecosystem of loaders, plugins and support for various features like symlinks, aliases etc.
However, because Re.Pack is based on Webpack, it is targeted towards advanced users who already know how to use Webpack and want to leverage Webpack ecosystem.
If you're just starting with React Native, it's better to stick with the default solution — Metro, since you probably won't benefit much from switching to Webpack and Re.Pack.
You can explore examples of React Native applications using Re.Pack here: https://github.com/callstack/repack-examples.
Both Metro and Re.Pack have different approaches for the similar problem — bundling JavaScript code for your React Native application.
The main distinction is that, Metro is custom-built solution and Re.Pack uses Webpack. As a result there few differences that you should consider when deciding the solution to use:
Re.Pack is a direct successor to Haul. Therefore we took the experience we gained with Haul while making rather major changes in the approach:
@callstack/nativepack
Re.Pack is a rebranded version of @callstack/nativepack
, which was a temporary name to avoid infringing on Webpack trademark. They are both the same projects.