1. 入门篇
npm init
npm init -y 或
npm init -f
npm config set init.author.email "[email protected]"
npm config set init.author.name "wangshijun"
npm config set init.author.url "http://github.com/wangshijun"
npm config set init.license "MIT"
npm config set init.version "0.1.0"
npm run command
command是scripts脚本中的key
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
如果不带任何参数执行 npm run,它会列出可执行的所有命令
npm 在执行指定 script 之前会把 node_modules/.bin 加到环境变量 $PATH 的前面,这意味着任何内含可执行文件的 npm 依赖都可以在 npm script 中直接调用,换句话说,你不需要在 npm script 中加上可执行文件的完整路径
eslint代码风格检查工具 1. 用于测试代码
const str = 'some value';
function fn(){
console.log('some log');
}
- 1.添加eslint依赖npm install eslint -D
- 2.初始化 eslint 配置./node_modules/.bin/eslint --init根据提示完成风格配置
- 3.添加 eslint 命令
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"eslint": "eslint *.js"
}
- 1.运行npm run eslint
使用
&&
分割多个指令 一个出错则终止后续命令执行 "scripts": {
"eslint": "eslint *.js",
"serial": "npm run eslint && node index.js && node second.js",
}
使用
&
分割多个指令"parallel": "npm run eslint & node index.js & node second.js",
- 1.安装依赖npm i npm-run-all -D
- 2.指令
npm-run-all
command1
command2
"all": "npm-run-all eslint serial parallel"
- 1.并行执行多条同时运行的指令
npm-run-all
--parallel
command1
command2
"allparallel": "npm-run-all --parallel eslint serial parallel",
npm run command
--
paramContent"eslint":"eslint *.js",
"param": "eslint *.js --fix"
npm run eslint -- --fix
等价于
npm run param
使用 --loglevel silent,或者 --silent,或者更简单的 -s 来控制
npm run test -s
使用 --loglevel verbose,或者 --verbose,或者更简单的 -d 来控制
npm run test -d
Last modified 3yr ago