# learn-react **Repository Path**: zhoujunpei/learn-react ## Basic Information - **Project Name**: learn-react - **Description**: 主要用于学习react和demo以及底层原理 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-12-06 - **Last Updated**: 2025-11-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 准备工作 基于 Vite 创建 React + TypeScript 的项目,具体创建项目的步骤,请参考 Vite 官方文档。 在 Vite 项目中配置 @ 路径提示 1.安装 node 的类型声明: ```bash npm i -D @types/node ``` 2.配置 vite.config.ts 文件: ```js // 1. 以 ES6 模块化的方式,从 Node 的 path 模块中,导入 join 函数 import { join } from 'path' // https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], // 2. 在 resolve.alias 对象下,配置 @ 的指向路径 resolve: { alias: { '@': join(__dirname, './src/') } } }) ``` 3.配置 tsconfig.json 文件,在 compilerOptions 节点下,新增 "baseUrl": "." 和 "paths": { "@/*": [ "src/*" ] } 两项: ```js { "compilerOptions": { /* 新增以下两个配置项,分别是 baseUrl 和 paths */ "baseUrl": ".", "paths": { "@/*": [ "src/*" ] }, "target": "ES2020", "useDefineForClassFields": true, "lib": [ "ES2020", "DOM", "DOM.Iterable" ], "module": "ESNext", "skipLibCheck": true, /* Bundler mode */ "moduleResolution": "bundler", "allowImportingTsExtensions": true, "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", /* Linting */ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true }, "include": [ "src" ], "references": [ { "path": "./tsconfig.node.json" } ] } ```