Prettier enforces a consistent code style (i.e. code formatting that won’t affect the AST) across your entire codebase because it disregards the original styling* by parsing it away and re-printing the parsed AST with its own rules that take the maximum line length into account, wrapping code when necessary.
配置 .prettierrc
使用的是开源项目 vue-router 中的 .prettierrc 配置
安装 Prettier VSCode 插件
调整 VSCode 默认格式化工具为 Prettier
9.3. ESLint
ESLint 是什么?
ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code, with the goal of making code more consistent and avoiding bugs. In many ways, it is similar to JSLint and JSHint with a few exceptions:
ESLint uses Espree for JavaScript parsing.
ESLint uses an AST to evaluate patterns in code.
ESLint is completely pluggable, every single rule is a plugin and you can add more at runtime.
安装 ESLint VSCode 插件
初始化 ESLint 配置
代码语言:javascript
复制
npx eslint --init
按需调整 ESLint 配置
10. 构建工具
目前的主流 Web 构建工具主要包含:webpack、vitejs、rollup、glup、parcel 等。本文选择目前社区中比较火爆的“下一代前端构建工具 ViteJS”作为我们项目的构建工具。
Vitejs 是什么?
Vite 是一个由原生 ESM 驱动的 Web 开发构建工具。在开发环境下基于浏览器原生 ES imports 开发,在生产环境下基于 Rollup 打包。
Vitejs 关键特性?
快速的冷启动
即时的模块热更新
真正的按需编译
默认支持 TypeScript,开箱即用
默认支持 jsx、tsx,开箱即用
支持 HMR
Vitejs 初始配置?
11. 联调
npm link 在测试阶段,可应用于在父子项目之间建立软连接,避免反复往 npm 仓库中发包。
This is handy for installing your own stuff, so that you can work on it and test iteratively without having to continually rebuild.
https://docs.npmjs.com/cli/v7/commands/npm-link