- eslint||
- editorconfig||
- precommit
安装:
npm i eslint eslint-config-standard eslint-plugin-standard eslint-plugin-promise
eslint-plugin-import eslint-plugin-node -D复制代码.eslintrc
npm i eslint-plugin-html 在vue文件中写js,也是也在script标签里面的
{
"extends": "standard",
"plugins": [
"html"
],
"parser": "babel-eslint", //使用基于babel的eslint
"rules": {
"no-new": "off",
"indent": "off",
"space-before-function-paren": "off",
"no-dupe-keys": "off",
"semi": "off",
"no-multiple-empty-lines": "off",
"comma-dangle": "off",
"eol-last": "off",
"no-unused-vars": "off",
"no-multi-spaces": "off",
"space-in-parens": "off",
"spaced-comment": "off",
"quotes": "off",
"no-undef": "off",
"key-spacing": 'off',
"space-before-blocks": "off",
"comma-spacing": "off"
}
}复制代码package.json
"scripts":{
"lint":"eslint --ext .js --ext .jsx --ext .vue client/"
"lint-fix":"eslint --ext .js --ext .jsx --ext .vue client/"
}复制代码npm i eslint-loader babel-eslint -D
再到webpack.config.base.js里面配置
---------------------------------------我是来势汹汹的分割线------------------------------
.editorconfig
root = true //配置文件读到这个文件就可以了
[*]
charset = utf-8
end_of_line = lf
indent_size = 2 //tab长度是2个空格
indent_style = space //制表符,用space
insert_final_newline = true // 保存自动后面加一个空行
trim_trailing_whitespace = true //去出尾部空格复制代码precommit--package.json
注意先git init ,后npm i husky -D
"scripts":{
"lint":"eslint --ext .js --ext .jsx --ext .vue client/"
"lint-fix":"eslint --ext .js --ext .jsx --ext .vue client/"
"precommit":"npm run lint-fix"
}复制代码-------------nodemon自动重启--------------
nodemon.json
{
"restartable": "rs",
"ignore": [
".git",
"node_modules/**/node_modules",
".eslintrc",
"client",
"build/webpack.config.client.js",
"public"
],
"verbose": true,
"env": {
"NODE_ENV": "development"
},
"ext": "js json ejs"
}复制代码package.json
script{
......
"dev:server": "nodemon server/server.js",
}复制代码npm run dev:server
npm i concurrently -D
script{
......
"dev": "concurrently \"npm run dev:client\" \"npm run dev:server\"",
}复制代码npm run dev
本文介绍了如何在前端项目中实施代码规范,包括ESLint、EditorConfig和Pre-commit钩子的配置方法,以及如何集成到构建流程中实现自动化检查。

被折叠的 条评论
为什么被折叠?



