npm 、yarn、pnpm 远程下载包并执行,介绍各种包管理工具的多种执行方式, npx、npm init ,yarn create 、 pnpm dlx 、pnpm create 、 pnpx。
npm
# npx (推荐):
# 从远程仓库下载 create-react-app 包, 并运行 create-react-app
# 临时安装用完即删(但是实际上是过一段时间才会删除 create-react-app 包)
npx create-react-app myapp
# npm init
# 从远程仓库下载 create-react-app 包, 并运行 create-react-app
# 注意这种方式会自动在包前面加上create前缀,所以我们这里写的是 react-app
# 临时安装用完即删(但是实际上是过一段时间才会删除 create-react-app 包)
npm init react-app myapp
# 全局永久安装
npm install -g create-react-app
create-react-app myapp
yarn
# 这个和 npm init react-app 差不多(自动在包名前面加上create前缀),
# 从远程仓库下载 create-react-app 并执行,
yarn create react-app myapp
# 完全等价于下面全局安装并运行命令
yarn global add create-react-app
create-react-app my-app
pnpm
# pnpm dlx
# 等价于 npx create-react-app myapp
pnpm dlx create-react-app myapp
# pnpx
# pnpx 完全等价 pnpm dlx
pnpx create-react-app myapp
# pnpm create
# 等价于 npm init react-app myapp
pnpm create react-app myapp
# 全局安装并运行
pnpm add create-react-app -g
create-react-app myapp