通过这篇文章你可以学到
node
:v18.13.0npm -vvite
:^4.4.5React
:^18.2.0typescript
:^5.0.2Redux
:^4.2.1React-router
:^6.15.0"Ant-design
:^5.8.3eslint
:^8.47.0prettier
:^3.0.1normalize.css
:^8.0.1npm
:9.8.1
npm init vite@latest xxxx(项目名) --template react-ts
//示例:
npm init vite@latest vite-React-ts-Redux --template react-ts
注意:我们这里要把命令中的项目名改成自己将要创建的项目名
? Select a framework: » - Use arrow-keys. Return to submit.
Vanilla
Vue
> React
Preact
Lit
Svelte
Solid
Qwik
Others
? Select a variant: » - Use arrow-keys. Return to submit.
> TypeScript
TypeScript + SWC
JavaScript
JavaScript + SWC
vite-React-ts-Redux && pnpm install && pnpm run dev
# pnpm
pnpm init vite@latest project-name --template react-ts
# npm
npm init vite@latest project-name --template react-ts
vite.config.js
文件添加路径别名配置import {
defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path' //导入Path模块
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
// 路径别名
resolve: {
alias: {
'@': path.resolve(__dirname, 'src') // 配置 @ 别名指向 src 文件夹
}
}
})
tsconfig.json
文件添加路径别名声明,以便ts识别路径别名{
"compilerOptions": {
"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",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
// 路径别名
"baseUrl": "./src",
"paths": {
"@/*": ["*"]
}
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
安装 normalize.css
文件
npm install normalize.css
安装之后 引入到我们的项目中.在我们的main.tsx
文件中进行引入
@import 'normalize.css';
这里我们使用prettier 和 eslint 实现我们的格式化和校验
首先我们要在项目中安装 prettier
npm install prettier -D
.prettierrc
文件,并且配置一些我们项目所需要的格式