代码规范&&多个server

本文介绍了如何在前端项目中实施代码规范,包括ESLint、EditorConfig和Pre-commit钩子的配置方法,以及如何集成到构建流程中实现自动化检查。

  • 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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值