3
头图

TL;DR:

👉 npx xxx

👉 yarn create

👉 npm init

Taking create-react-app as an example, the documentation provides three options for creating applications:

  • npx create-react-app my-app
  • npm init react-app my-app
  • yarn create react-app my-app

It's all good, why?

npx

NPM (Node Package Manager) and NPX (Node Package Executor)

NPX is the package executor. try it~

// npx cowsay 亖混子
npx: 41 安装成功,用时 6.739 秒
 _______________
< 亖混子 >
 ---------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Purpose 1. Execute the command of the local package in a short way

If you execute the executable file of the project dependency package, you need to type the following: $ ./node_modules/.bin/jest ; if you use npx will be very concise $ npx jest

Purpose 2. One-time execution of global module commands

Some global packages such as create-react-app are used npx can be used when needed. Compared with global installation, the latest version is guaranteed

$ npx create-react-app my-react-app

yarn create

Quickly create projects with the create-*

How to use yarn create <starter-kit-package> [<args>]

The underlying command does two things:

  1. Install the starter-kit-package package globally, if it already exists locally, try to update to the latest version
  2. Executable to run the package

yarn create react-app my-app equivalent to the script below

$ yarn global add create-react-app
$ create-react-app my-app

npm init

Quickly create projects with the create-* The function and operation are exactly the same as yarn create

npm init react-app my-app equivalent to yarn create react-app my-app

Compared

npm init and yarn create both use the package name rule create-*, first download globally, and then execute

npx xxx There is no package name constraint, temporarily download and delete after execution

The effect of the three is the same, all use the latest package to execute the command


亖混子
4.7k 声望2.4k 粉丝

自信、自洽、自在