总体概括
因为搭建的是node项目, 所以比前端项目搭建要简单很多。
从以下因素考虑
- 装包问题
- yarn
- 配置项:
.yarnrc 、.npmrc
.gitignore
- 代码规范
- eslint
- prettier
- commititlint
- 每次提交自动检测eslint\commitLint
- 测试
- jest、ts-jest
- 代码构建
- tsconfig
- typeings
装包问题
这个问题比较简单没有什么好说的, 推荐 yarn , 如果是非常复杂的项目, 推荐使用 yarn/workSpace + lerna 组合拳, 爽歪歪。
.yarnrc
:
registry "https://registry.npm.taobao.org"
npmrc
:
registry = https://registry.npm.taobao.org
.gitignore
:
# See https://help.github.com/ignore-files/ for more about ignoring files.
# dependencies
node_modules/
# testing
coverage/
/doc/
/mock2easy/
# production
/build
/coverage
worker/
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
.idea
.idea/
/packages/**/*.js
/packages/**/*.js.map
!jest.config.js
tempDownload/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
yarn.lock
package-lock.json
代码规范
集成eslint、prettier、recommended
.eslintrc.js
:
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
project: './tsconfig.json',
},
plugins: ['@typescript-eslint'],
extends: [
'prettier',
'prettier/@typescript-eslint',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:prettier/recommended',
],
env: {
node: true,
browser: false,
},
rules: {
'@typescript-eslint/no-var-requires': 1,
'@typescript-eslint/explicit-function-return-type': 2,
'@typescript-eslint/explicit-member-accessibility': 2,
'no-unused-vars': 2,
semi: [2, 'always', {
omitLastInOneLineBlock: true }],
},
};
.prettierrc
:
{
"singleQuote": true,
"trailingComma"