简体   繁体   English

NextJs 和 Create React App 有什么区别?

[英]What is the difference between NextJs and Create React App?

I'm trying to figure out the difference between NextJs and Create React App .我试图找出NextJsCreate React App之间的区别。 I know both are there to make our life easier while developing our Front-end Apps using ReactJs .我知道在使用ReactJs开发前端应用程序时,两者都是为了让我们的生活更轻松。

After exploring some articles on Google, I found that the main difference is在 Google 上浏览了一些文章后,我发现主要区别在于

NextJs provides server side rendering (SSR) while Create React App provides client side rendering (CSR) and SSR improves performance of Application Loading. NextJs 提供服务器端渲染(SSR),而 Create React App 提供客户端渲染(CSR),SSR 提高了应用程序加载的性能。

But what about other parameters from development perspective like但是从开发的角度来看其他参数呢?

Maintainability and Scalability of the Web App developed with NextJS or CRA? Web 用NextJS还是CRA开发的App的可维护性和可扩展性?

Typescript and React Hooks/Redux support ? Typescript 和 React Hooks/Redux 支持

Or you can even Guide me if I'm doing a wrong comparison?或者,如果我做错了比较,您甚至可以指导我?

I've used both NextJs and CRA.我使用过 NextJs 和 CRA。 Both these frameworks can be used to get started quickly and provide a good developer experience.这两个框架都可用于快速入门并提供良好的开发人员体验。 However, both of these have use cases where either of them shines better.但是,这两个都有用例,其中任何一个都更好。 I'll try to compare them based on some of these factors.我将尝试根据其中一些因素对它们进行比较。 Feel free to suggest edits with additional points or comments随意提出带有附加点或评论的编辑

Server Side Rendering服务器端渲染

CRA税务局 Next.js Next.js
CRA doesn't support SSR out of the box. CRA 不支持开箱即用的 SSR。
However, you can still configure it.但是,您仍然可以对其进行配置。
It just takes more effort to setup SSR with your preferred server and configuration.使用您喜欢的服务器和配置设置 SSR 需要更多的努力。 The development team doesn't have plans to support this in the near future.开发团队没有计划在不久的将来支持此功能。 They suggest other tools for this use case.他们为此用例建议了其他工具
NextJs has different types for SSR . NextJs 有不同的 SSR 类型 It supports SSR out of the box.它支持开箱即用的 SSR。
* Static generation: fetch data at build time. * Static 生成:在构建时获取数据。 This works best for use cases like blogs or static websites这最适合博客或 static 网站等用例
* Server side rendering: fetch data and render for each requests. * 服务器端渲染:为每个请求获取数据并渲染。 You have to do this when you need to serve different view for different users.当您需要为不同的用户提供不同的视图时,您必须这样做。

Configurability可配置性

I think this is point where these tools are very different and your decision can depend on this factor我认为这是这些工具非常不同的地方,您的决定可能取决于这个因素

CRA税务局 Next.js Next.js
Create React App doesn't leave you a lot of room to configure it. Create React App 不会给您留下太多配置空间。
Configurations like webpack config cannot be changed unless webpack 配置之类的配置不能更改,除非
you stray away from normal CRA way (eject, rescripts, rewired, craco).您偏离了正常的 CRA 方式(弹出、重写、重新布线、craco)。
Basically, you have to use what's configured in基本上,您必须使用中配置的内容
react-scripts which is the core of CRA. react-scripts是 CRA 的核心。
Almost everything is configurable .几乎所有东西都是可配置的。
If you check the example NextJs templates , you can see files like如果您检查示例NextJs 模板,您可以看到类似的文件
babelrc , jest.config , eslintrc etc babelrcjest.configeslintrc
that you can configure.您可以配置。

Maintainability可维护性

CRA税务局 Next.js Next.js
CRA is very opinionated. CRA 非常有主见。
If you keep updated with the releases of CRA, it's not hard to maintain.如果您不断更新 CRA 的版本,维护起来并不难。
NextJs is also well maintained. NextJs 也维护得很好。 They release regular updates.他们发布定期更新。

Typescript Typescript

CRA税务局 Next.js Next.js
Supports out of the box.支持开箱即用。 You can initialize CRA app with typescript with您可以使用 typescript 初始化 CRA 应用程序
npx create-react-app my-app --template typescript
Supports typescript out of the box.开箱即用支持 typescript
Start with configurations for typescript with touch tsconfig.json从 typescript 的配置开始, touch tsconfig.json

Hooks support挂钩支持

Latest version of both CRA and NextJs installs a version of React that supports hooks. CRA 和 NextJs 的最新版本都安装了支持钩子的 React 版本。 You can also upgrade to the latest version easily您还可以轻松升级到最新版本


Redux support Redux 支持

Redux is a library that you can use with both these tools. Redux 是一个可以与这两种工具一起使用的库。

Create React App is just a React project creation engine to help you setup your React project quickly. Create React App只是一个 React 项目创建引擎,可帮助您快速设置您的 React 项目。 After running the CRA script npx create-react-app <appname> you will get a nice and clean single-page application that you can run.运行 CRA 脚本npx create-react-app <appname>后,您将获得一个可以运行的漂亮且干净的单页应用程序。 Under the hood you also get things like babel, eslint, jest, webpack already setup so it's a really convenient way to start doing React development.在引擎盖下,您还可以获得诸如 babel、eslint、jest、webpack 之类的东西已经设置好了,所以这是开始进行 React 开发的一种非常方便的方式。 And in case you'd need more control over the configuration of those tools, you can still use npm run eject .如果您需要对这些工具的配置进行更多控制,您仍然可以使用npm run eject

Next.js on the other hand is a framework based on React to build Node.js server-side apps.另一方面, Next.js是基于 React 构建 Node.js 服务器端应用程序的框架。 This means you will use the same component-oriented logic to build pages and leverage the Next.js routing engine for page to page navigation.这意味着您将使用相同的面向组件的逻辑来构建页面并利用 Next.js 路由引擎进行页面导航。 Server-side rendering will allow loading time to be more spread over time, so perceived performance will be probably better.服务器端渲染将允许加载时间随着时间的推移更加分散,因此感知性能可能会更好。 Redux can be used as well but there will be some additional steps to make it work properly (see https://github.com/kirill-konshin/next-redux-wrapper ) Redux 也可以使用,但需要一些额外的步骤才能使其正常工作(参见https://github.com/kirill-konshin/next-redux-wrapper

Whatever you choose, in the end, it will be React coding .无论你选择什么,最终都会是 React 编码 Components , JSX , TypeScript support , React hooks , and all other core aspects of React will be supported either way.组件JSXTypeScript 支持React 钩子和 React 的所有其他核心方面都将得到支持。 Therefore, you can expect similar degree of maintainability.因此,您可以期待类似程度的可维护性。 On the other hand, scalability depends on your choice: if you choose Next.js you will host the app on a server infrastructure which should be sized according to your audience whereas React bundle created with CRA just need to be statically hosted somewhere.另一方面,可扩展性取决于您的选择:如果您选择 Next.js,您将在服务器基础架构上托管应用程序,该基础架构应根据您的受众调整大小,而使用 CRA 创建的 React 包只需要静态托管在某个地方。

React is just a JavaScript library, and on the other hand, Nextjs is a React framework. React 只是一个 JavaScript 库,另一方面,Nextjs 是一个 React 框架。 SSR is one of the benefits of Nextjs, But there are many other benefits. SSR 是 Nextjs 的好处之一,但还有很多其他好处。 Nextjs can do everything react does, and on top of that, it has features that react alone doesn't have. Nextjs 可以做所有 react 做的事情,除此之外,它还具有单独做 react 所没有的功能。 Checkout the documentation for nextjs here: https://nextjs.org/docs/getting-started在此处查看 nextjs 的文档: https://nextjs.org/docs/getting-started

TLDR TLDR

biggest difference is purpose of both projects.最大的区别是两个项目的目的。 NextJS: JAM Stack or Static Site Generator Create React App: is an officially supported way to create single-page React applications. NextJS: JAM StackStatic 站点生成器Create React App:是官方支持的创建单页 React 应用程序的方式。

Explanation:解释:

This conundrum is true for many opensource projects.对于许多开源项目来说,这个难题都是正确的。 Seem alternative of other but they have key differences.似乎是其他的替代品,但它们有关键的区别。 For Example in this case Although both projects use ReactJS as front end and produce webapps.例如在这种情况下,虽然两个项目都使用 ReactJS 作为前端并生成 webapps。 the problem they solve are very distinct.他们解决的问题非常不同。 there are some overlapping features themes/templates in js. js中有一些重叠的功能主题/模板。 but development and future work will be to enhance project such that it helps solve there problem statement in better way.但开发和未来的工作将是增强项目,以便它有助于以更好的方式解决问题陈述。

ie NextJS will try to include if there are any new Markdown features developed.即 NextJS 将尝试包含是否开发了任何新的 Markdown 功能。 which won't be the case in CreateReactApps.在 CreateReactApps 中不会出现这种情况。

Suggestion.建议。

from your question it seems you are looking these projects for developing React Native Apps.从您的问题来看,您似乎正在寻找这些项目来开发 React Native Apps。 So I will suggest go with Create React App.所以我会建议 go 使用 Create React App。

your comparison should primarily be whether this project align with Problem I am solving.您的比较应该主要是这个项目是否与我正在解决的问题一致。 then compare.然后比较。 Maintainability, Scalability, Typescript and React Hooks/Redux support.可维护性、可扩展性、Typescript 和 React Hooks/Redux 支持。

In case needed more info do comment.如果需要更多信息,请发表评论。

ReactJs is a library and NextJs is framework that uses react components. ReactJs是一个库, NextJs是使用反应组件的框架。

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

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