npm-script1

npm script 相比 grunt、gulp、webpack更为简单。

1.初始化npm init

{
"name": "test-npm-script",
"version": "1.0.0",
"description": "test npm-script",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"npm-script"
],
"author": "Felix",
"license": "ISC"
}
  1. npm init 包名称 版本 描述 关键词 许可协议等,也可以快速初始化npm init -f(force) 或者npm init -y(yes)
  2. 初始化的npm init 是可以配置的。例如默认version是1.0.0,我们可以手动配置
  3. 执行npm run 会将所有可执行的命令打印出来

 

npm config set init.version '0.1.0'
npm config set init.name 'Felix'
npm install module_name -S  ===npm install module_name --save   
npm install module_name -D  ===pm install module_name --save-dev 

 

2.安装eslint 

npm install eslint -D

3. 初始化 eslint 输入shell 脚本  ./node_modules/.bin/eslint --init

PS E:\aa> ./node_modules/.bin/eslint --init
? How would you like to configure ESLint? Answer questions about your style
? Which version of ECMAScript do you use? ES2016
? Are you using ES6 modules? Yes
? Where will your code run? (Press <space> to select, <a> to toggle all, <i> to invert selection)Browser
? Do you use CommonJS? No
? Do you use JSX? No
? What style of indentation do you use? Tabs
? What quotes do you use for strings? Single
? What line endings do you use? Windows
? Do you require semicolons? Yes
? What format do you want your config file to be in? JavaScript

 

结果生成的 .eslintrc.js 配置文件

module.exports = {
"env": {
"browser": true,
"es6": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2016,
"sourceType": "module"
},
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"windows"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
};
在package.json加入script命令
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"eslint": "eslint *.js",
}

添加一个文件,index.js

const str="Felix";
function fn(){
console.log('test');
}

  

执行后
E:\aa\index.js

1:7 error 'str' is assigned a value but never used no-unused-vars
2:10 error 'fn' is defined but never used no-unused-vars
3:2 error Unexpected console statement no-console

✖ 3 problems (3 errors, 0 warnings)

  

posted @ 2018-12-20 21:26  一路向北87110  阅读(217)  评论(0编辑  收藏  举报