2019-01-22
React + TypeScript with Parcel
programming, quicktip, react, selfnote
programming, quicktip, react, selfnote
_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> |
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" | |
... | |
} |
jsx option in tsconfig.json