vue项目搭建

Wenn 于 2022-11-01 发布

CMS项目搭建规范

一、代码规范

  1. editorconfig配置 ->保证各个操作系统上IDE保持风格一致

    不同编辑器保持相同的格式

    .editorconfig文件

# http://editorconfig.rog

root = true

[*] # 表示所有文件适用
charset = utf-8 # 设置文件字符集为 utf-8
indent_style = space # 缩进风格 (tab | space)
indent_size = 2 # 缩进大小
end_of_line = lf # 控制换行类型(lf | cr | crlf)
trime_tailing_whitespace = true # 去除行首的任意空白字符
insert_final_newline = true # 始终在文件末尾插入一个新行

[*.md] # 表示仅 md 文件适用以下规则
max_line_length = off
trim_trailing_whitespace = false

1.2 prettier配置

yarn add prettier -D

.prettier文件

{
  "useTabs": false,
  "tabWidth": 2,
  "printWidth": 80,
  "singleQuote": true,
  "trailingComma": "none",
  "semi": false
}

.prettierignore忽略格式化文件配置,需要安装prettier插件才可以

/dist/*
.local
.output.js
/node_modules/**

**/*.svg
**/*.sh

/public/*

所有文件统一格式化package.json脚本,一次对所有文件进行修复

    "prettier": "prettier --write ."

1.3使用ESLint检测

    'plugin:prettier/recommended'

1.4git husky和eslint

提交时进行检测

npx husky-init && npm install

1.5提交信息规范

 yarn add commitizen -D
yarn commitizen init cz-conventional-changelog --save-dev --save-exact

需要先将文件添加到暂缓区,之后使用cz进行格式化提交,但是依然无法阻止错误的commit提交信息,配置强制不符合不提交

1.5.1安装插件
yarn add @commitlint/config-conventional @commitlint/cli -D
1.5.2.添加配置文件commitlint.config.js
module.exports = {
  extends: ['@commitlint/config-conventional']
}
生成msg检测文件
yarn husky add .husky/commit-msg "npx --no-install commitlint --edit $1"
yarn husky add .husky/commit-msg "yarn commitlint --edit $1"
1.5.3.配置package.json,使用yarn commit来运行cz
"commit": "git add . && cz"  //直接使用yarn commit即可,后不使用git commit -m msg

二、第三方库集成

2.1