使用说明
React+TypeScript+Vite
这个模板提供了一个最小的设置,让React在Vite中使用HMR和一些ESLint规则。
目前,有两个官方插件可用:
- @vitejs/plugin-react 用途 巴别塔 用于快速刷新
- @vitejs/插件反应swc 用途 SWC 用于快速刷新
扩展ESLint配置
如果您正在开发生产应用程序,我们建议更新配置以启用类型感知的lint规则:
- 配置顶级
parserOptions这样的属性:
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
- 替换
tseslint.configs.recommended向tseslint.configs.recommendedTypeChecked或tseslint.configs.strictTypeChecked - 可选择添加
...tseslint.configs.stylisticTypeChecked - 安装 eslint插件反应 并更新配置:
// eslint.config.js
import react from 'eslint-plugin-react'
export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})