← Go Back

React + TypeScript with Parcel

Broken Post?Let me know

Photo by Kira auf der Heide on Unsplash

Learned today that it's easy to create React + TypeScript site with Parcel without using CRA (create-react-app).

Parcel Documentation has a whole (short but complete) section on how to use TypeScript file with Parcel.

https://parceljs.org/typeScript.html

Just include TypeScript file (either .ts or .tsx for React components) in an HTML file, and Parcel will know what to do with it.

<html>
<head>
<title>MobX React TypeScript</title>
</head>
<body>
<div id="app"></div>
<script src="../src/index.tsx"></script>
</body>
</html>
view raw index.html hosted with ❤ by GitHub

View this gist on GitHub

including TypeScript file

One caveat is that you need to set a jsx option in tsconfig.json to react for it to work.

{
"compilerOptions": {
...
"jsx": "react"
...
}
view raw tsconfig.js hosted with ❤ by GitHub

View this gist on GitHub

jsx option in tsconfig.json

Resources