我在查看 vue.js 的 wiki 页面时看到了这个:
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 链接放进去就可以了?
最佳答案
不,Babel 和 Webpack 对于 React 堆栈来说不是必需的。您仍然可以找到其他替代方案来构建您最喜欢的堆栈,例如 Browserify 和 Gulp。
但是,如果您想让事情变得更简单,我建议您将 Babel 和 Webpack 与 React 一起学习和使用,因为:
- 您可以使用模块。
- 您可以将 JSX 与 ES6 结合使用。
- 它支持很多浏览器
- 您可以使用更高级的功能(异步/等待)等
使用 webpack
- 您可以为 sass、less、postcss 等使用不同的加载器
- 您可以使用不同的插件来优化您的构建,例如 Uglify、HotModuleReplacement、Chunks 等
使用 webpack 还有很多优点,您可以在 here 找到
关于reactjs - 为什么 React 需要 Babel 和 Webpack 才能工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43175140/