为什么React需要Babel和Webpack起作用? [英] Why does React require Babel and Webpack to work?

查看:325
本文介绍了为什么React需要Babel和Webpack起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看vue.js的Wiki页面,并看到了以下内容:

I was looking at the wiki page of vue.js and saw this:

与React开发相比,Vue可以集成到 现有的Web应用程序要容易得多.通常,一个Web应用程序 只需包含Vue.js就可以立即开始使用Vue JavaScript库.与Webpack或Browserify配合使用不是严格的 一定.这与React开发形成鲜明对比 Webpack和Babel的使用不可避免,因此 转换现有的Web应用程序要困难得多.

When compared to React development, Vue can be integrated to an existing web application much more easily. Normally, a web application can start using Vue immediately by simply including the Vue.js JavaScript library. Usage with Webpack or Browserify, are not strictly necessarily. This is in stark contrast to React development where Usage with Webpack and Babel is unavoidable, therefore making converting existing web application much more difficult.

有人可以解释为什么React需要webpack和babel吗?我以为您可以直接添加到React CDN的链接,就可以了吗?

Can someone explain why React needs webpack and babel? I thought you can just drop in the link to the CDN of React and it will work?

推荐答案

否,React堆栈不需要Babel和Webpack.您仍然可以找到其他替代方法来构建自己喜欢的堆栈,例如Br​​owserify和Gulp.

No, Babel and Webpack is not necessary for React stack. You can still find other alternatives to build your favourite stack such as Browserify and Gulp.

但是,如果您想使事情变得简单,我建议您将Babel和Webpack与React结合使用,因为:

However, if you want to make things easier, I do recommend you learn and use Babel and Webpack together with React because:

  • 您可以使用模块.
  • 您可以将JSX与ES6一起使用.
  • 它支持许多浏览器
  • 您可以使用更多高级功能(异步/等待)等

使用webpack

  • 您可以为sass,less,postcss等使用不同的加载器
  • 您可以使用不同的插件来优化构建,例如Uglify,HotModuleReplacement,Chunk等

使用Webpack还有许多其他优点,您可以在此处找到

There are many more advantages to use webpack which you can find here

这篇关于为什么React需要Babel和Webpack起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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