Search code examples
reactjstypescriptbabeljstsc

Creating React component libraries using TypeScript vs. Babel compiler


I am currently using the babel compiler to compile my React component libraries. I made this decision based on the fact that Create React App also uses the babel compiler. However, I am now finding that using babel to create libraries is more complicated. You need to introduce the TypeScript compiler anyway to generate type definitions. Thus I need to maintain two sets of configurations, babel and tsconfig. This complexity gets further amplified by the fact that I have multiple such libraries in a monorepo.

So my question is:

  1. Is there any good reason to use the Babel TypeScript compiler to compile React libraries (vs tsc)?
  2. Am I going to loose any features if I get rid of Babel completely and rely only on tsc?

Solution

  • After a lot of research, it was clear to me that when creating a TypeScript library from scratch, it does not make sense to use the Babel compiler. Babel does not do any type checking of TS files. For that I have to run the TypeScript compiler anyway. Hence it is better to use the TypeScript compiler from the get go. For create-react-app, Babel was a better choice because they were. already using it for ES6 builds.

    Furthermore, I picked up a CLI/template for creating my library. It's called TXDX. It really makes the job of creating a TS library very easy.