Giter Club home page Giter Club logo

front-end-config's Introduction

这是一个前端工程化的配置项目

使用前先禁用vscode中的eslint等相关插件

问题npm run lint会有一些奇怪的错误

TypeScript

npm i typescript -D
npx tsc --init

Eslint

npm i eslint -D
npx eslint --init
npm i eslint-config-standard-with-typescript -D

Prettier

注意版本兼容问题

npm i prettier -D
echo {}> .prettierrc.json
npm i eslint-config-prettier^8.8.0 eslint-plugin-prettier^5.0.0-alpha.1 -D

Husky

在git提交前后自动执行一些脚本,例如代码检查

npm i husky -D
npx husky install
// 添加钩子 类unix
npx husky add .husky/pre-commit "npm run lint" 
// windows系统
node node_modules/husky/lib/bin add .husky/pre-commit "npm run lint"

Commitlint

便于在changelog文件中提取commit信息,因此需要commit规范

// 安装命令行工具和基于Angular的约定规定
npm i @commitlint/config-conventional @commitlint/cli -D
// 将commitlint添加到钩子
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
// windows注意使用双引号
node node_modules/husky/lib/bin add .husky/commit-msg "npx --no-install commitlint --edit \"$1\""

Angular 规范说明:

  • feat:新功能
  • fix:修补 BUG
  • docs:修改文档,比如 README, CHANGELOG, CONTRIBUTE 等等
  • style:不改变代码逻辑 (仅仅修改了空格、格式缩进、逗号等等)
  • refactor:重构(既不修复错误也不添加功能)
  • perf:优化相关,比如提升性能、体验
  • test:增加测试,包括单元测试、集成测试等
  • build:构建系统或外部依赖项的更改
  • ci:自动化流程配置或脚本修改
  • chore:非 src 和 test 的修改,发布版本等
  • revert:恢复先前的提交

Jest

测试模块

// 安装jest、类型声明文件、以及相关依赖
npm i jest @types/jest [email protected] ts-jest -D
// 初始化配置文件
npx jest --init

修改jest.config.ts文件

 preset: 'ts-jest'

__tests__目录也加上lint校验

"lint": "eslint src __tests__ --ext .js,.ts --cache --fix",

新建一个tsconfig.eslint.json文件,写入以下内容:

{
  "extends": "./tsconfig.json",
  "include": ["**/*.ts", "**/*.js"]
}

Github Actions(后面补充)

通过github actions 实现代码合并或推送到主分支,会自动触发测试和发布版本等一系列流程

参考文章

front-end-config's People

Contributors

nightwatch1998 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.