npm package.json配置整理
通过npm init 创建 package.json文件
参数:
name:项目名字
version: 版本号
description: 项目介绍
main: 项目的入口文件
scripts: npm提供给我们运行shell命令的入口
author:作者
license:标注我们项目的许可证权限,如果不想开源({"license":"UNLICENSED"}或{"private":true})
dependencies:项目运行时必要依赖,
peerDependencies: 针对特定版本开发
devDependencies:项目开发时所需依赖
homepage:项目主页的网址
files:将软件包作为依赖项安装时要包含的条目
npm script使用
npm 脚本的原理非常简单。每当执行npm run,就会自动新建一个 Shell,在这个 Shell 里面执行指定的脚本命令。因此,只要是 Shell(一般是 Bash)可以运行的命令,就可以写在 npm 脚本里面。
1.目录
npm run新建的这个 Shell,会将当前目录的node_modules/.bin子目录加入PATH变量,执行结束后,再将PATH变量恢复原样。node_modules/.bin子目录里面的所有脚本,都可以直接用脚本名调用,而不必加上路径。比如,当前项目的依赖里面有 Mocha,只要直接写mocha test就可以了。

2.通配符
*表示任意文件名,**表示任意一层子目录
3.传参
向 npm 脚本传入参数,要使用--标明

4.执行顺序
&代表并行执行, &&代表继发执行(即只有前一个任务成功,才执行下一个任务)

5.npm 钩子
npm 脚本有pre和post两个钩子,例:build脚本命令的钩子就是prebuild和postbuild
提供的默认钩子:
prepublish,postpublish
preinstall,postinstall
preuninstall,postuninstall
preversion,postversion
pretest,posttest
prestop,poststop
prestart,poststart
prerestart,postrestart
6.变量
可以通过npm_package_拿到package.json的配置


7.常用的脚本
