- Jest doesn’t compile code under
node_modulesby default, so it’s extra work for users to configure Jest when testing.
- It’s common to exclude
node_moduleswhen compiling for bundlers such as webpack. If your library is cross-platform and supports web, it should have first-class support for other bundlers.
- If your library supports web, you should pre-compile it so that the user can import it in Node for SSR.
The main reason many people don’t compile the code when publishing is because it’s not straightforward. We need to take care of many things, for example, different entry points and babel configuration for different targets. If we use a static type checker such as Flow or TypeScript, we also need to take care of generating and publishing the type definitions.
We built Bob to simplify this and take care of it automatically. All the scripts and Babel config are abstracted away. It can also automatically configure your project to use it just by running
yarn bob init.
Currently, it handles the following targets,
- Generic CommonJS build
- ES modules build for bundlers such as
- Flow definitions (copies
- TypeScript definitions (uses
tscto generate declaration files)
Bob’s goal is to standardize these build scripts across the React Native libraries in the community. We plan to implement more things in the future, including a watch mode.