File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # npm create 命令
2+
3+ npm create 是 npm init 命令的一个别名。
4+
5+ 不过,如果执行` npm create xyz ` ,实际上执行的是` npx create-xyz ` 。它会暂时性安装` create-xyz ` ,然后执行它的` package.json ` 里面定义的脚本命令。
6+
7+ 下面是一些例子。
8+
9+ - ` npm create svelte@latest `
10+ - ` npm create vue@latest `
11+ - ` npm init react-app my-app `
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ npm 从5.2版开始,增加了 npx 命令,它有很多用处。
44
55![ ] ( https://www.wangbase.com/blogimg/asset/201902/bg2019020901.jpg )
66
7- Node 自带 npm 模块,所以可以直接使用 npx 命令。万一不能用,就要手动安装一下。
7+ Node 自带 npx 模块,所以可以直接使用 npx 命令。万一不能用,就要手动安装一下。
88
99``` bash
1010$ npm install -g npx
@@ -49,7 +49,7 @@ $ npx ls
4949$ npx create-react-app my-react-app
5050```
5151
52- 上面代码运行时,npx 将` create-react-app ` 下载到一个临时目录,使用以后再删除 。所以,以后再次执行上面的命令,会重新下载` create-react-app ` 。
52+ 上面代码运行时,npx 将` create-react-app ` 下载到一个临时目录,然后自动执行 ` package.json ` 文件的 ` bin ` 字段指定的命令,执行以后再删除整个模块 。所以,以后再次执行上面的命令,会重新下载` create-react-app ` 。
5353
5454下载全局模块时,npx 允许指定版本。
5555
@@ -65,6 +65,8 @@ $ npx uglify-js@3.1.0 main.js -o ./dist/main.js
6565$ npx http-server
6666```
6767
68+ npx 也可以执行` package.json ` 文件的` scripts ` 字段的命令,比如` npx foo dev ` 会执行` foo ` 模块的` scripts ` 字段的` dev ` 命令。
69+
6870## ` --no-install ` 参数和` --ignore-existing ` 参数
6971
7072如果想让 npx 强制使用本地模块,不下载远程模块,可以使用` --no-install ` 参数。如果本地不存在该模块,就会报错。
You can’t perform that action at this time.
0 commit comments