# React + TypeScript + Vite This template provides a minimal setup to get React working in Vite with HMR and some Oxlint rules. ## 路由模式 通过 `VITE_ROUTER_MODE` 选择路由模式: - `.env` 默认设置 `hash`,地址示例为 `/#/about/me`。 - `.env.local` 可设置 `history`,地址示例为 `/about/me`。此文件已被 Git 忽略。 - `.env.local` 同时影响本地开发和本地构建;需要构建 Hash 版本时运行 `VITE_ROUTER_MODE=hash pnpm build`。 修改环境变量后需重启开发服务或重新构建。History 模式需要服务器配置前端路由回退,并确保深层 URL 下的资源路径正确。 ## 资源基础路径 通过环境变量 `VITE_BASE_URL` 配置 Vite 的 `base`,默认值为 `/`。可在 `.env.local` 中覆盖: ```dotenv VITE_BASE_URL=./ ``` `./` 适用于 Hash 路由的相对资源部署;History 路由建议使用 `/` 或明确的部署子目录,例如 `/app/`。部署到子目录时,还需配套设置路由的 `basename`。 Currently, two official plugins are available: - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs) - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) ## React Compiler The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation). ## Expanding the Oxlint configuration If you are developing a production application, we recommend enabling type-aware lint rules by installing `oxlint-tsgolint` and editing `.oxlintrc.json`: ```json { "$schema": "./node_modules/oxlint/configuration_schema.json", "plugins": ["react", "typescript", "oxc"], "options": { "typeAware": true }, "rules": { "react/rules-of-hooks": "error", "react/only-export-components": ["warn", { "allowConstantExport": true }] } } ``` See the [Oxlint rules documentation](https://oxc.rs/docs/guide/usage/linter/rules) for the full list of rules and categories.