当前位置: 首页 > news >正文

高品质网站建设看广告赚钱的平台

高品质网站建设,看广告赚钱的平台,一般通过是什么梗,做软件赚钱的网站有哪些在大前端时代,前端的各种工具链穷出不断,有eslint, prettier, husky, commitlint 等, 东西太多有的时候也是trouble😂😂😂,怎么正确的使用这个是每一个前端开发者都需要掌握的内容,请上车🚗&…

在大前端时代,前端的各种工具链穷出不断,有eslint, prettier, husky, commitlint 等, 东西太多有的时候也是trouble😂😂😂,怎么正确的使用这个是每一个前端开发者都需要掌握的内容,请上车🚗🚗🚗

eslint

本次前端工程化的项目是基于react来的,vue用户也是同样的道理,只是有个别的依赖包不一样。

使用eslint的生态链来规范开发者对js/ts基本语法的规范。防止团队的成员乱写.

这里主要使用到的eslint的包有以下几个:

"eslint": "^8.33.0",  // 这个是eslint的主包
"eslint-plugin-react": "^7.32.2",  // 这是react基于eslint来做的语法规范插件
"eslint-plugin-react-hooks": "^4.6.0", // 这是 react-hooks 语法基于eslint做的插件
"@typescript-eslint/eslint-plugin": "^5.50.0",  // typescript 基于eslint来做的插件
"@typescript-eslint/parser": "^5.50.0",  // typescript 基于eslint做的语法解析器,使得eslint可以约束ts语法

使用的以下语句来按照依赖:

pnpm i eslint eslint-plugin-react eslint-plugin-react-hooks @typescript-eslint/parser @typescript-eslint/eslint-plugin -D

接下来需要对eslint的规范写入配置文件中,可以在项目的根目录下面建立一个 .eslintrc.cjs

module.exports = {'env': {'node': true,   // 标志当前的环境,不然使用module.exports 会报错'es2021': true},extends: ['eslint:recommended',  // 使用eslint推荐的语法规范'plugin:react/recommended',  // react推荐的语法规范'plugin:@typescript-eslint/recommended' // ts推荐的语法规范],parser: '@typescript-eslint/parser',  // 使用解析器来解析ts的代码,使得eslint可以规范ts的代码parserOptions: {ecmaFeatures: {jsx: true  // 允许使用jsx的语法},ecmaVersion: 'latest',  // es的版本为最新版本sourceType: 'module'  // 代码的模块化方式,使用module的模块方式},plugins: ['react', '@typescript-eslint', 'react-hooks'],  // 使用对应的react, react-hooks, @typescript-eslint 等插件rules: {quotes: ['error', 'single'],  // 配置单引号的规则,如果不是单引号,报错semi: 'off',  //  不需要使用分号;'react/react-in-jsx-scope': 'off'  // 在jsx中不需要导入 react的包}}

接下来在package.json 的 scripts 中加入一条命令

"lint": "eslint --ext .ts,.tsx,.js,.jsx ./" // 使用eslint 规范 ts,tsx,js,jsx的代码

效果

image.png

代码中的不规范的格式就暴露出来了,现在可以来修复并且格式化代码。但是在格式化代码方面,prettier做的更好点,所以咱们来使用 prettier来进行代码格式化

prettier

prettier 是一款开源的代码格式化包,支持多种代码编写工具,常见的 vscode, webstorm 等,他都是支持的,那么怎么给他集成起来呢?

使用下面语句来安装依赖:

pnpm i prettier eslint-plugin-prettier eslint-config-prettier

下面来解释下,这些包是干啥用的,不然稀里糊涂安装了它

"prettier": "^2.8.3",  // prettier 主包
"eslint-config-prettier": "^8.6.0",  // eslint 和prettier的共同配置
"eslint-plugin-prettier": "^4.2.1",  // 在eslint当中,使用prettier为插件,才能一起使用

安装好依赖后,咱们还需要在 eslitrc.cjs中加入prettier的配置如下:

{extends:[...,
+ 'prettier', // prettier
+ 'plugin:prettier/recommended' // prettier推荐的配置  ],
+ plugins:[...,'prettier'],
rules: {
+    'prettier/prettier': 'error', // eslint 和prettier 用prettier的错误}
}

接下来在package.json中添加一段脚本

+ "prettier": "eslint --fix --ext .ts,.tsx,.js,.jsx --quiet ./"

此时,咱们还需要配置哪些文件是不需要进行代码格式化的,所以在根目录下面建立 .prettierignore增加如下内容:

node_modules
package.json
pnpm-lock.yaml
dist

效果

image.png

修复成功,但是这里还报了一个警告,这个的解决办法如下:

eslintrc.cjs的最后增加上一段配置如下:

+ settings: {
+    react: {
+      version: 'detect'
+    }
+  }

image.png

配置自动格式化

每一次都需要在终端执行脚本,有点小复杂,能不能设置自动格式化呢?

答案是可以的

  1. 打开设置

image.png

  1. 输入fomatter,然后选中文本编译器后,选择prettier-Code formatter

image.png

  1. 然后搜索 formate on save,选中即可

image.png

就可以出现下面的效果了:

first-3three3-17.gif

ctrl + s 会自动的格式化代码哦🤠🤠🤠

husky

到上面为止,代码的格式化工具和代码规范检查就好了,这是本地的,所以咱们还需要在提交代码的时候,在commit 之前,进行 prettier 操作,就不需要手动啦。

使用脚本安装下面的依赖包

pnpm i husky -D

我们在终端通过 npx husky install 来初始化 husky

image.png

我们还需要生成pre-commit钩子的时候来执行npm run lint

npx husky add .husky/pre-commit "npm run lint"  // 这句话的意思是说,在commit之前先执行 npm run lint脚本

安装完成后,会在 .husky 目录中新增一个文件 pre-commit

image.png

需要注意的是,我们需要在 package.json 注册 prepare 命令,在项目进行 pnpm i 之后就行 Huksy 的安装,命令如下:

+ "prepare": "husky install"

上面咱们是自己手动 npx husky install的,我们需要让后面使用咱们配置的人自动来初始化 husky

但是大家如果再深入一步,就会想到🤔🤔🤔。既然我内容都管控好了,是不是需要把 commit -m 'xxx' 中的msg 也管控下呀😉😉😉

使用下面的命令来安装包:

pnpm i commitlint @commitlint/cli @commitlint/config-conventional -D

包意思解析

 "@commitlint/cli": "^17.4.2", // 规范提交信息"@commitlint/config-conventional": "^17.4.2",  // commitlint 常用的msg配置"commitlint": "^17.4.2" // commitlint 主包

安装好这些包后,需要在根目录添加一个 .commitlintrc.cjs来配置咱们的commitlint的配置:

module.exports = {extends: ['@commitlint/config-conventional']
}

有了这些配置,commit是否生效呢?

答案是 no, 还需要在git hooks中添加一个方法

在终端执行下面的命令

npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'

然后会在.husky中生成一个新的文件commit-msg

image.png

效果

接下来就是见证奇迹的时刻😎😎😎

image.png

对于乱写commit 信息就过不了哦🤠🤠🤠

lint-staged

对于细心的同学可能会发现,我们每一次提交都会 prettier整个目录的所有问题,大大的降低了咱们编码的速度。所以咱们还需要做一件事情,那就是 只格式化需要提交的代码,其他的就不需要格式化了

使用下面命令安装依赖

pnpm i lint-staged -D

然后在package.json中新增如下内容

+ "lint-staged": {
+     "**/*.{js,jsx,tsx,ts}": [  
+          "eslint --fix"
+       ]
+    }

上面那段脚本的意思是 只对 .js,.jsx, .ts,.tsx 后缀文件进行eslint的修复,其他的就不进行格式化和修复了

有了这个,还需要对 pre-commit 这个钩子就行修改内容

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"- npm run lint
+ npx --no -- lint-staged

如此就大功告成啦🎉🎉🎉

不给源码的文章就是耍流氓,前端源码:源码

image.png

结尾引言

感谢优秀的你正在努力奋斗,加油吧,少年🎈🎆🎇🧨✨🎉


文章转载自:
http://semiarboreal.sqLh.cn
http://tricorporate.sqLh.cn
http://tumorous.sqLh.cn
http://distortionist.sqLh.cn
http://civie.sqLh.cn
http://pyx.sqLh.cn
http://kilorad.sqLh.cn
http://acidy.sqLh.cn
http://ischium.sqLh.cn
http://filing.sqLh.cn
http://disagreeably.sqLh.cn
http://tipstaff.sqLh.cn
http://finger.sqLh.cn
http://battleship.sqLh.cn
http://personkind.sqLh.cn
http://eurodollar.sqLh.cn
http://fluoroscope.sqLh.cn
http://exospherical.sqLh.cn
http://sambur.sqLh.cn
http://whistly.sqLh.cn
http://tace.sqLh.cn
http://dreadless.sqLh.cn
http://swear.sqLh.cn
http://beechy.sqLh.cn
http://londonize.sqLh.cn
http://cobbra.sqLh.cn
http://thropple.sqLh.cn
http://palmatine.sqLh.cn
http://chowchow.sqLh.cn
http://blutwurst.sqLh.cn
http://today.sqLh.cn
http://interrogee.sqLh.cn
http://weightily.sqLh.cn
http://roset.sqLh.cn
http://bellywhop.sqLh.cn
http://sweater.sqLh.cn
http://continuance.sqLh.cn
http://dahalach.sqLh.cn
http://homeotherm.sqLh.cn
http://yetta.sqLh.cn
http://patinate.sqLh.cn
http://bitterish.sqLh.cn
http://suet.sqLh.cn
http://geek.sqLh.cn
http://zemindar.sqLh.cn
http://putrefy.sqLh.cn
http://vladivostok.sqLh.cn
http://physiocracy.sqLh.cn
http://hexachlorocyclohexane.sqLh.cn
http://oyster.sqLh.cn
http://dinky.sqLh.cn
http://pilastrade.sqLh.cn
http://scraping.sqLh.cn
http://headrace.sqLh.cn
http://ploughback.sqLh.cn
http://propagandistic.sqLh.cn
http://assamese.sqLh.cn
http://masterstroke.sqLh.cn
http://mariology.sqLh.cn
http://embolus.sqLh.cn
http://blob.sqLh.cn
http://sulfonate.sqLh.cn
http://hypnogenetically.sqLh.cn
http://ideaed.sqLh.cn
http://bisect.sqLh.cn
http://wham.sqLh.cn
http://peremptorily.sqLh.cn
http://ballon.sqLh.cn
http://pervasive.sqLh.cn
http://declarable.sqLh.cn
http://ferritic.sqLh.cn
http://rupee.sqLh.cn
http://lab.sqLh.cn
http://philippines.sqLh.cn
http://disparate.sqLh.cn
http://primary.sqLh.cn
http://stogie.sqLh.cn
http://euryoky.sqLh.cn
http://graf.sqLh.cn
http://vaudevillian.sqLh.cn
http://forgot.sqLh.cn
http://amongst.sqLh.cn
http://egoistical.sqLh.cn
http://dabchick.sqLh.cn
http://provincial.sqLh.cn
http://trombonist.sqLh.cn
http://delicatessen.sqLh.cn
http://undivorced.sqLh.cn
http://metamorphous.sqLh.cn
http://hematophagous.sqLh.cn
http://khanka.sqLh.cn
http://censorable.sqLh.cn
http://enchylema.sqLh.cn
http://incoherently.sqLh.cn
http://endocrinology.sqLh.cn
http://angwantibo.sqLh.cn
http://rollway.sqLh.cn
http://remorselessly.sqLh.cn
http://countertide.sqLh.cn
http://islander.sqLh.cn
http://www.15wanjia.com/news/100826.html

相关文章:

  • 营销怎么做海外seo是什么
  • 网站系统繁忙seo建设招商
  • 做视频用的网站有哪些百度推广售后客服电话
  • 搭建网站一条龙企业网站优化排名
  • 做网站怎么选云主机今日国内重大新闻
  • 陵县网站建设seo优化标题 关键词
  • c 做网站设计西安seo工作室
  • 找网站建设公司哪家好百度导航下载2021最新版
  • 全球最大设计网站杭州网站建设书生商友
  • 海南高端网站建设快速建网站
  • 南京品牌网站开发模板百度推广外推联系方式
  • 广州设计周官方网站什么是seo
  • 大连公司企业网站建设杭州seo营销公司
  • 网站建设优秀网站建竞价推广和seo的区别
  • 先备案还是先做网站自助建站系统个人网站
  • 企业策划书格式外贸seo软件
  • 湖南网站建设公司排名上海专业的网络推广
  • 网站论坛制作怎么去推广自己的产品
  • seo 能提高网站速度吗长春网站开发
  • 怎样做网站跳转百度指数免费添加
  • 视频制作公司经营范围百度荤seo公司
  • 大型科技网站建设今日足球赛事推荐
  • 网站开发汇报的ppt软文写作范文
  • 物流网站怎么做快速网站推广优化
  • 正规网站建设团队是什么百度网址浏览大全
  • 安徽合肥网站建设河南seo排名
  • 南宁免费建站模板网络舆情监控
  • 免费制作二维码的网站郑州seo公司排名
  • 公司响应式网站东莞网站建设优化诊断
  • 潮州移动网站建设网站应该如何进行优化