基础路径
配置tsconfig.json里的baseUrl, 这样模块的引用的路径不需要写../../../..了, 可以直接写src/xxx
{
"compilerOptions": {
"importHelpers": true,
"baseUrl": "src",
"allowJs": true,
"allowSyntheticDefaultImports": true,
"target": "es5",
"outDir": "dist",
"experimentalDecorators": true,
"lib": ["es5", "dom", "es2015.promise", "esnext"],
"types": ["node"],
"declaration": false,
"sourceMap": true
},
"include": ["./src/**/*.ts"],
"exclude": ["node_modules"]
}
配置prettier
安装
$ yarn add --dev --exact prettier
新建配置文件
$ echo {}> .prettierrc.json
在precommit-hook自动格式化, 参考prettier.io/docs/en/pre…
$ npm install -g mrm mrm-task-lint-staged
$ npx mrm lint-staged
执行上述命令后, package.json里的npm scripts会新增
"prepare": "husky install"
而且package.json会新增字段
"lint-staged": {
"*.{js,css,md}": "prettier --write"
}
可加入自己想要自动格式化的文件类型如ts, tsx
避免prettier与eslint的冲突, 参考prettier.io/docs/en/int…
$ yarn add eslint-config-prettier -D
配置eslint
"eslintConfig": {
"extends": [
"prettier"
]
},
规范commit msg
$ yarn add @commitlint/config-conventional @commitlint/cli -D
$ echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
$ npx husky add .husky/commit-msg "yarn commitlint --edit $1"
package.json里添加husky配置
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},