Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
172
|
第
16
章
16.3
 创建
React
应用
开始一个
React
应用最好的方式是使用
create-react-app
(
CRA
)这个工具,它会创建所
有的项目样板代码、开发者工具,并提供一个最小的应用让你作为起点。而且,
create-
react-app
会让它的配置保持更新,因此我们可以专注于应用的构建而无须再为框架工具
链而分心。尽管这么说,如果真的需要配置工具链,也可以把应用从工具链中分离出来,
这样虽然不能再跟最新的
CRA
工具链保持一致,但也获得了对应用配置完全的控制。
一直以来,我们应用开发的一切工作成果都是跟
Express
应
用合为一体的,而
SPA
最好是
被看作一个分离的独立应用。如此一来,就有了
两个
应用根目录。清晰起见,当我提及
Express
应用所在的目录时
,会说
服务器根目录
;当提及
React
应用所在的目录时
,会说
客
户端根目录
。而
应用根目录
是这两个目录所在的目录。
既然如此,那就进入你的应用根目录,创建一个名为
server
的目录
,这就是
Express
应用
服务器所在的地方。不用创建客户端应用的目录,
CRA
会为我们创建。
运行
CRA
之前需要先安装
Y
arn
。
Yarn
是一个包管理器,跟
npm
类似。
实际上,
Yarn
基
本上完全替代了
npm
。
虽然
React
开发并未强制使用
Yarn
,但它已经成为事实标准了,不
使用它无异于要“逆流而上”。虽然
Y
arn
和
npm
在用法上有一些微小差异,但是很可能你
只会注意到,你要运行的是
yarn add
而不是
npm install
。要安装
Yarn
,只需遵照
Yarn
官
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9787115565099