babel和jsx类型有什么区别 [英] Whats the difference between type babel and jsx

查看:67
本文介绍了babel和jsx类型有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用React JS ...很抱歉,但是我对type ="text/babel"和type ="text/jsx"有什么区别感到困惑

I just started using React JS ... I'm sorry but I am confused on what is the difference between type="text/babel" and type="text/jsx"

以及何时使用它们..请帮助我理解.

and when do I use them.. please help me understand.

推荐答案

Babel是一个编译器,它将输入代码转换为纯" JavaScript.

Babel is a transpiler that turns input code into "pure" JavaScript.

JSX是JavaScript上的语法糖.您编写.jsx并使用编译器(通常是Babel)将其转换为.js.

JSX is a syntax sugar over JavaScript. You write .jsx and transpile it to .js using a transpiler (typically, Babel).

编写 text/babel 时,您是在向Babel库说要将该脚本转换为纯JavaScript.

When you write text/babel you are saying to the Babel library that you want to transpile that script into pure JavaScript.

如果您编写 text/jsx ,则表示您的脚本位于.jsx中,并且需要一个编译器来解析您的代码.

In case you write text/jsx you are saying your script is in .jsx and you need a transpiler to parse your code.

如果要编写.jsx和/或ES6而不配置webpack或browserify之类的捆绑程序,请通过CDN加载Babel并使用 text/babel 为简单起见.

If you want to write .jsx and/or ES6 without configuring a bundler like webpack or browserify, load Babel through a CDN and use text/babel for simplicity.

这篇关于babel和jsx类型有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆