简体   繁体   English

何时使用反应框架,如Next或Gatsby vs Create React App

[英]When to use a react framework such as Next or Gatsby vs Create React App

I'm in the sort of rapid prototyping phase of my React/javascript learning experience. 我正处于我的React / javascript学习体验的快速原型阶段。 I was wondering when folks would reach for a framework such as Next.js or Gatsby.js vs the standard Create React App. 我想知道什么时候人们会找到像Next.js或Gatsby.js这样的框架与标准的Create React App。

I really dig the page based structuring and prospect for preloading links of Next.js. 我真的挖掘基于页面的结构和前景预加载Next.js的链接。 However, I'm not sure when you would reach for Next as apposed to CRA or even ejected CRA. 但是,我不确定你什么时候可以达到CRA,甚至是CRA。

Thanks! 谢谢!

I am in the same boat. 我在同一条船上。 I started with CRA to create a SPA which was great to start with and get over the learning curve. 我从CRA开始创建一个SPA,这个开始很棒并且可以克服学习曲线。 But I soon realized two important issues : 但我很快意识到两个重要问题:

  1. Sharing on social networks : I was unable to change the OGP tags per route. 在社交网络上分享:我无法更改每条路线的OGP标签。 The effect of that is, only your base route (setup correctly with OGP tags) when shared on a social network can produce the card (twitter term), any other route you share will basically show as blank. 这样做的结果是,只有你的基本路线(正确设置OGP标签)在社交网络上共享时才会产生卡片(推特术语),你共享的任何其他路线基本上都会显示为空白。 This is true for Facebook and LinkedIn as well. Facebook和LinkedIn也是如此。 See here . 看到这里
  2. Search Engine Optimization : Though there have been few articles about search engines able to crawl your SPA correctly for indexing, in my experience it hasn't been satisfactory. 搜索引擎优化:虽然很少有关于搜索引擎能够正确抓取您的SPA以进行索引的文章,但根据我的经验,它并不令人满意。 For eg in Google I noticed that only the home page is indexed and it's not parsed correctly. 例如在Google中,我注意到只有主页被编入索引,并且没有正确解析。 Separate titles from separate elements are concatenated together. 将单独的标题与单独的元素连接在一起。 Bing, doesn't seem to have indexed it. Bing,似乎没有索引它。 May be Google indexed it because I have indexed the home page using Google's Search Console. 可能是Google将其编入索引,因为我已使用Google的搜索控制台索引了主页。 It's not a feasible solution if I have to re-index manually for every new page or after an update to a page. 如果我必须为每个新页面手动重新索引或者在更新页面之后,这不是一个可行的解决方案。

Create-React-App : A really good bootstrapper tool to get started with to create a SPA. Create-React-App:一个非常好的bootstrapper工具,可以开始创建SPA。

Gatsby/React-Static : Similar to Create-React-App but produces HTML build output instead thus "pre-rendering". Gatsby / React-Static:与Create-React-App类似,但产生HTML构建输出,因此“预渲染”。 I am yet to experiment with this. 我还没有尝试过这个。 I am hopeful that this would resolve (1) and (2) since I can now have different OGP tags already in the HTML being served from a static site server (S3/Azure Blobs/Github Pages) instead of them being changed locally after the fetch. 我希望这将解决(1)和(2),因为我现在可以在从静态站点服务器(S3 / Azure Blobs / Github页面)提供的HTML中具有不同的OGP标签,而不是在本地之后更改它们。取。 I am not sure if this will work yet. 我不确定这是否会奏效。 The added advantage here is, since Gatsby already pre-renders during build time, the user experiences better performance. 这里的附加优势是,由于Gatsby在构建期间已经预呈现,因此用户体验到更好的性能。 (May be someone experienced with Gatsby can clarify, or I will edit this answer after I am done.) Update (2/19/2018) : I can confirm that (1) is solved by Gatsby.js while still hosted as a static website. (可能是Gatsby有经验的人可以澄清,或者我会在完成后编辑这个答案。)更新(2/19/2018):我可以确认(1)由Gatsby.js解决,同时仍作为静态托管网站。

Next.js : If Gatsby doesn't solve (1) and (2), Next.js will be my fall back to create a full blown SSR app. Next.js:如果Gatsby没有解决(1)和(2),Next.js将是我的后退,以创建一个完整的SSR应用程序。 The issue here is, now I am going to have to use PaaS to host the site (eg Azure Web Apps or AWS ElasticBeanStalk or Heroku) instead of a static site hosting service (Azure Blob, AWS S3, Github Pages). 这里的问题是,现在我将不得不使用PaaS来托管网站(例如Azure Web Apps或AWS ElasticBeanStalk或Heroku),而不是静态网站托管服务(Azure Blob,AWS S3,Github Pages)。 This will be slightly costlier and bit more work to setup CI/CD pipelines. 这将稍微昂贵一点,并且设置CI / CD管道需要更多工作。

Also see these alternatives listed on CRA's docs. 另请参阅CRA文档中列出的这些替代方案

I recently did a lot of research myself about this topic especially create-react-app vs Gatsby.js and I found out that Both tools let you write react code right away without worrying too much about the setup. 我最近自己做了很多关于这个主题的研究,尤其是create-react-app vs Gatsby.js,我发现这两个工具让你可以立即编写反应代码,而不必过多担心设置。 However, Gatsby, for example, offers on top of that, server-side rendering at build time which is crucial for SEO. 但是,Gatsby提供了最重要的服务器端渲染,这对于SEO至关重要。 You don't need any server to render your views which is the case for Next.js because they are already done at build time. 您不需要任何服务器来呈现您的视图,这是Next.js的情况,因为它们已在构建时完成。 when a user visits your website the HTML version will be loaded first and once the javascript is loaded your website will become a fully functional react web app. 当用户访问您的网站时,将首先加载HTML版本,一旦加载了javascript,您的网站将成为一个功能齐全的反应网络应用程序。

The good thing is they all share the same view layer so you can move from one tool to another. 好处是它们共享相同的视图层,因此您可以从一个工具移动到另一个工具。 you can check moving from create-react-app to Gatsby.js which goes into details. 您可以查看从create-react-app移动到Gatsby.js的详细信息。

I'm doing this research myself. 我自己做这个研究。 My understanding is that Next.js provides Server-Side Rendering out of the box. 我的理解是Next.js提供开箱即用的服务器端渲染。 Create React App does not do this so you need to provide your own solution for SSR (for things like faster page loads and SEO). 创建React App不会这样做,因此您需要为SSR提供自己的解决方案(例如更快的页面加载和SEO)。

create-react-app is best for both building website and mobile apps(react native apps) because lots of learning curves available. create-react-app最适合构建网站和移动应用程序(反应原生应用程序),因为有很多学习曲线可用。 other two are the react frameworks(we can say). 另外两个是反应框架(我们可以说)。

use Gatsby for single page website faster and easy to deploy. 使用Gatsby可以更快速,更轻松地部署单页网站。 use Next.js while working with REST APIs (i guess...) 在使用REST API时使用Next.js(我猜......)

it's up to you. 由你决定。 a good developer always find his/her way for easy and fast work. 一个优秀的开发人员总能找到他/她的方式,方便快捷的工作。

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

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