package.json 命令和配置 package.json

package.json 中的 scripts 字段定义了项目的常用命令,可以通过 npm run <script-name> 来运行

常见的项目配置脚本如下:

  • start: 启动项目,通常是启动开发服务器。比如, npm start 可能会执行 node index.js

  • test: 常常用于启动测试脚本。

  • build: 打包或构建项目的命令。比如: 使用 webpack 打包项目。

  • lint: 运行代码规范检查工具。比如 eslint

  • dev: 启动开发者模式

你也可以选择自己写一个脚本,比如在你的项目 package.json 中的 scripts 对象中写入键为 ‘start’,脚本的值为 ‘hexo clean && hexo server’

1
2
3
4
5
6

"script":{
"start": "hexo clean && hexo server"
"... 其他脚本"
}

请注意,在 json 文件中写的命令联合使用 & 符号,而在控制台中键入命令,只需要 ; 分割联合的命令

之后可以使用 npm run start 执行你写的 start 命令