本文阅读量 次
1. 前端工程化,开发体验¶
| 场景组合 | 说明 | 备注 |
|---|---|---|
| eslint + ts | typescript-eslint ⧉ | |
| eslint + vue | eslint-plugin-vue | |
| eslint + vite | ||
| stylelint + vue | ||
| stylelint + vite | ||
| stylelint + prettier | ||
| eslint + prettier | ||
| prettier + vue | ||
| prettier + ts | ||
| vscode + vue | IDE支持 | |
| vscode + ts | ||
| vscode + eslint | 插件官网 ⧉ | 3.0.5 支持 Flat Config 插件配置文档 ⧉ |
| vscode + prettier | 插件官网 ⧉ | |
| vite+vue | @vitejs/plugin-vue ⧉ | Vite 支持 Vue |
| vue + ts | vue-tsc ⧉ | vue 对 tsc 的封装 |
1.1 ESLint¶
1.1.1 安装 ESLint¶
npm install eslint --save-dev
1.1.2 初始化 ESLint¶
npx eslint --init
1.1.3 Eslint 9 的重要变更¶
1.1.3.1 默认使用 Flag Config¶
目前 (v9.x.x) 仍然可以通过设置环境变量 ESLINT_USE_FLAT_CONFIG=false 使用旧版 eslintrc 格式的配置文件,但预计在 v10.0.0 完全移除对 eslintrc 方式的支持
1.1.3.2 什么是 Flag Config¶
Flag Config 默认配置文件按照如下顺序查找
eslint.config.js
eslint.config.mjs
eslint.config.cjs
1.1.3.3 迁移说明¶
Flag Config不支持.eslintignore文件,通过Ignoring Files配置 ⧉ 支持,需要将.eslintignore中的规则迁移过去
1.1.4 Eslint + TS 的官方支持¶
主要通过 typescript-eslint ⧉ 的一系列功能进行支持
1.1.5 Eslint + Vue 的官方支持¶
项目地址 eslint-plugin-vue ⧉
配置说明 详见这里 ⧉, 注意 是针对 eslint 9.0.0 之前的版本,还是之后的版本
1.1.5.1 备注¶
"extends": ["plugin:vue/vue3-recommended"]和"extends": ["plugin:vue/base"]至少要在 .eslintrc.json 中配置一个eslint-plugin-vue和eslint-plugin-html不能一起工作
1.1.6 Eslint + Vite 的官方支持¶
1.2 Prettier¶
1.2.1 安装¶
npm install --save-dev prettier
1.2.2 创建相关配置文件¶
touch .prettierrc .prettierignore
1.2.3 基本使用¶
检查当前目录文件的格式
npx prettier . --check
npx prettiere . --write
1.2.4 配置 VS Code 保存时自动进行格式化¶
1.3 StyeLint¶
1.4 CI/CD¶
1.5 IDE 的支持¶
1.5.1 vscode 支持 vue¶
- Vue2 是通过 Vetur ⧉ 插件进行支持的,目前基本上不演进了
- Vue3 是通过 Volar ⧉ 插件支持的,现在此插件已经更名为 Vue - Official ⧉
1.5.2 vscode 支持 eslint¶
1.5.3 vscode 支持 prettier¶
1.6 其它¶
1.6.1 vscode 设置¶
| 设置 | 示例值 | 说明 |
|---|---|---|
"editor.rulers" | [120, 160] | 在第 120, 160 个字符处显示宽度标尺 |
"editor.wordWrapColumn" | 120 | 每行宽度 120 个字符 |
"editor.formatOnSave" |
