Ganzo
Ganzo

Reputation: 250

Adding babel/typescript to an existing react project

I have a few questions regarding the subject:

  1. Is it possible to add babel to an existing react project, or is it better to restart the development and add babel at the beginning to avoid any setup issues?

  2. Is webpack mandatory to be added along with babel for react projects, or can you just add babel without webpack?

  3. Same question goes for typescript: Is it possible to add it in an existing project or is it better to restart everything?

  4. And last but not least. If I have a backend made in node and a frontend in react, do I have to add babel in both?

Thanks everybody for all of your anwsers.

Upvotes: 1

Views: 499

Answers (1)

lilla
lilla

Reputation: 31

I just started to work with React a little bit less than a month ago, so I had to do some research to answer your question. What I found that you don't have to restart your whole project, you can just install Babel and Typescript with npm. It is not necessary to use Webpack with Babel.

npm i @babel/core babel-loader @babel/preset-env @babel/preset-react --save-dev
npm install --save-dev typescript awesome-typescript-loader

About implementing TS I recommend reading this article.

If you created your application with create-react-app it already comes with Babel and Webpack and in that case you have to use the following command to implement Typescipt:

npm install --save typescript @types/node @types/react @types/react-dom @types/jest

I'm not really sure how to interpret your last question, so I'm going to leave that for more experienced fellows. I hope I could help you!

Upvotes: 3

Related Questions