简体   繁体   English

在现有的 React 项目中实现 babel/typescript

[英]Implement babel/typescript in a existing react project

i have some questions it is possible to implement babel in a existing react project or it's better to restart the project and add babel at the start to avoid any implement issues.我有一些问题可以在现有的 react 项目中实现 babel,或者最好重新启动项目并在开始时添加 babel 以避免任何实现问题。

Is webpack is mandatory with babel for react project or you can implement babel without webpack. webpack 对于反应项目是 babel 是强制性的,或者您可以在没有 webpack 的情况下实现 babel。

Same question for typescript possible to implement it in a existing project or better to restart all? typescript 的相同问题可以在现有项目中实施还是更好地重新启动?

and a last question if i have back in node and a front in react to i have to implement babel in the both?最后一个问题,如果我回到节点并且前面对我做出反应,我必须在两者中都实现 babel?

Thank you for all your anwser.谢谢你的所有回答。

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.不到一个月前,我刚开始使用 React,所以我不得不做一些研究来回答你的问题。 What I found that you don't have to restart your whole project, you can just install Babel and Typescript with npm.我发现您不必重新启动整个项目,您可以使用 npm 安装 Babel 和 Typescript。 It is not necessary to use Webpack with Babel.没有必要将 Webpack 与 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.关于实现 TS 我推荐阅读这篇文章。

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:如果您使用 create-react-app 创建应用程序,它已经带有 Babel 和 Webpack,在这种情况下,您必须使用以下命令来实现 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!我希望我能帮助你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM