不使用Webpack进行反应 [英] React without Webpack

查看:82
本文介绍了不使用Webpack进行反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始研究ReactJS.看来Facebook刚刚发布了15.0.1版本.去年,我在使用JSXTransformer的0.12.x版本中研究了这个框架,现在看来它已不复存在.

I started to look into ReactJS. It seems that Facebook just released version 15.0.1. I looked into this framework last year, during 0.12.x version, when it was using JSXTransformer, and now it seems it went away from it.

现在看来,几乎每个教程都建议将最新的React与Webpack结合使用.有没有办法完全不使用webpack?我正在尝试为React 15.x.x寻找一个很好的有效示例,并附带一个艰苦的任务.

Now it seems that almost every tutorial suggests using latest React with Webpack. Is there a way not use webpack at all? I'm trying to find a good valid example with a grunt task for React 15.x.x.

任何帮助将不胜感激.

推荐答案

似乎不赞成使用Jsx转换器.

Jsx transformer is deprecated it seems.

更新2019年4月8日:使用 https://github.com/developit/htm 进行简约的反应设置.

Update 04/08/2019 : use https://github.com/developit/htm for a minimalist react setup.

如果您不想使用Webpack,则必须考虑可以使用哪些功能.

If you don't want to use webpack, you have to think about which features you can live without.

随着浏览器对ES6功能的支持的发展,您现在可以拥有ES6语法,并且还可以使用模块(在激活实验性标志时),而无需使用Webpack.

With the advancement of browsers' support for ES6 features, you can now have ES6 syntax and also use modules (when activating experimental flags) without using Webpack.

如果要使用JSX,则始终需要将其转换为JS,因为地平线上的浏览器没有对它的本机支持.最简单的方法是将具有"React"预设的Babel中间件添加到开发服务器.

If you want to use JSX, you will always need to transpile it to JS because there is no native support for it in browsers on the horizon. The most simple way of doing that is to add a Babel middleware with the "React" preset, to your development server.

依赖性管理也将变得复杂,因为npm在CommonJS中提供了程序包,这些程序包无法在浏览器中正常运行...

Dependency management is also going to be complicated, because npm provides packages in CommonJS, which can't run as is in the browser...

如果您想尝试一下,可以查看我放在GitHub 没有Webpack的反应,尝试使用本机浏览器功能和http2复制大多数Webpack功能.

If you want to experiment with that, you can check out an experimental React starter-kit that I've put on GitHub React Without Webpack that attempts to replicate most of webpack features using native browser features and http2.

这篇关于不使用Webpack进行反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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