代码规范&&多个server

171 阅读1分钟

  • 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