- node 20.11.0
- pnpm 8.15.1
使用vite初始化项目
pnpm create vite one-day --template react-ts
使用shadcn-ui初始化ui组件库
(1) 安装Tailwind
并初始化
pnpm add -D tailwindcss postcss autoprefixer
pnpm dlx tailwindcss init -p
(2) 修改tsconfig.json
tsconfig.json
文件中添加以下配置:
{
"compilerOptions": {
// ...
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
// ...
}
}
(3) 更新vite.config.ts
配置别名
pnpm install @types/node -D
// 引入path
import path from "path";
export default defineConfig({
// ...
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
// ...
});
(4) 使用shadcn-ui
脚手架生成配置
pnpm dlx shadcn-ui@latest init
✔ Would you like to use TypeScript (recommended)? … yes
✔ Which style would you like to use? › New York
✔ Which color would you like to use as base color? › Zinc
✔ Where is your global CSS file? … src/styles/global.css
✔ Would you like to use CSS variables for colors? … yes
✔ Are you using a custom tailwind prefix eg. tw-? (Leave blank if not) … tw-
✔ Where is your tailwind.config.js located? … tailwind.config.js
✔ Configure the import alias for components: … @/components
✔ Configure the import alias for utils: … @/lib/utils
✔ Are you using React Server Components? … no
✔ Write configuration to components.json. Proceed? … yes
# 初始化stylelint
pnpm create stylelint
会自动安装stylelint
和stylelint-config-standard
, 并且生成.stylelintrc.json
配置文件
rules
配置参考stylelint
官网
rules
中新增配置
export default {
// ...
rules: {
// ...
// tailwindcss
"at-rule-no-unknown": [
true,
{
ignoreAtRules: [
"tailwind",
"apply",
"variants",
"responsive",
"screen",
],
},
],
// ...
},
};
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Currently, two official plugins are available:
- @vitejs/plugin-react uses Babel for Fast Refresh
- @vitejs/plugin-react-swc uses SWC for Fast Refresh
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
- Configure the top-level
parserOptions
property like this:
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
- Replace
plugin:@typescript-eslint/recommended
toplugin:@typescript-eslint/recommended-type-checked
orplugin:@typescript-eslint/strict-type-checked
- Optionally add
plugin:@typescript-eslint/stylistic-type-checked
- Install eslint-plugin-react and add
plugin:react/recommended
&plugin:react/jsx-runtime
to theextends
list