相关的包:
npm set-script prepare "husky install"
npm run prepare
// -c指定了lint-staged的配置文件
npx husky add .husky/pre-commit "npx lint-staged -c ./.husky/lintstagedrc.js"
npx husky add .husky/commit-msg "npx commitlint --edit $1"
配置文件lintstagedrc.js
在这里插入代码片module.exports = {
"**/*.{js,jsx}": ["eslint --fix"],
"*.{scss,less,styl,html}": ["stylelint --fix", "prettier --write"],
"*.vue": ["prettier --write", "eslint --fix", "stylelint --fix"]
}
module.exports = {
extends:[...,'eslint-config-prettier','plugin:prettier/recommended'],//这里直接使用了插件eslint-plugin-prettier的配置,plugin:开头,那么就可以不用在plugins字段声明prettier插件了
}
module.exports = {
printWidth: 100, // 打印宽度
tabWidth: 2, // tab 宽度
useTabs: false, // 使用tab
semi: false, // 分号
vueIndentScriptAndStyle: false, // vue indent
singleQuote: false, // 单引号
quoteProps: "as-needed", // 对象key 引号
bracketSpacing: true, // 导入对象和{}之间加空格
trailingComma: "none", // 尾随逗号
// jsxBracketSameLine: true, // 尖括号和结尾同一行 Deprecated
bracketSameLine: true, // 尖括号和结尾同一行
jsxSingleQuote: false, // jsx 中使用单引号
arrowParens: "avoid", // x=>x , (x)=>
insertPragma: false, // insert
requirePragma: false, // 只在@format或者@prettier 文件格式
proseWrap: "never", // prose散文是否根据printWidth 格式换行
htmlWhitespaceSensitivity: "strict", // HTML空白灵敏度
endOfLine: "auto" // 结尾
}
module.exports = {
extends:['stylelint-config-standard','stylelint-config-prettier'],
plugins:['stylelint-order']
}
commitlint.config.js
module.exports = {
extends: ["@commitlint/config-conventional"],
rules: {
"body-leading-blank": [2, "always"],
"footer-leading-blank": [1, "always"],
"header-max-length": [2, "always", 108],
"type-empty": [2, "never"],
"scope-empty": [0],
"subject-empty": [2, "never"],
"subject-full-stop": [0],
"type-case": [0],
"scope-case": [0],
"subject-case": [0],
"type-enum": [
2,
"always",
["feat", "fix", "perf", "style", "docs", "test", "refactor", "build", "ci", "chore", "revert"]
]
}
}
# http://editorconfig.org
root = true
# 说明
## 设置文件编码为 UTF-8;
## 用两个空格代替制表符;
## 在保存时删除尾部的空白字符;
## 在文件结尾添加一个空白行;
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
[Makefile]
indent_style = tab