三分钟在你的react项目中引入tailwindcss

前言:在vite搭建的react项目中引入并使用tailwindcss

一、初始化react项目

1、创建项目

在文件夹下右键打开终端并输入命令使用vite创建项目

cmd 复制代码
pnpm create vite react-tailwind

选择react+javascript,并输入命令安装依赖并启动

2、安装tailwind

cmd 复制代码
pnpm install -D tailwindcss postcss autoprefixer

安装好tailwind以及相关的依赖后,需要初始化tailwind的配置文件

cmd 复制代码
npx tailwindcss init -p

发现根目录下新增了一个tailwind.config.js文件

3、配置配置文件

在tailwind.config.js中粘贴一下配置

js 复制代码
/** @type {import('tailwindcss').Config} */
export default {
  content: [
    "./index.html",
    "./src/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

4、添加tailwind指令

在入口文件的css样式中加入下面三行代码

js 复制代码
// index.css
@tailwind base;
@tailwind components;
@tailwind utilities;

5、启动项目

现在你就可以在app.jsx中粘贴一下代码,测试tailwind是否生效啦

jsx 复制代码
export default function App() {
  return (
    <h1 className="text-3xl font-bold underline">
      Hello world!
    </h1>
  )
}

tailwind官网教程

相关推荐
键盘不能没有CV键3 小时前
【图片处理】✈️HTML转图片字体异常处理
前端·javascript·html
yantuguiguziPGJ4 小时前
WPF 联合 Web 开发调试流程梳理(基于 Microsoft.Web.WebView2)
前端·microsoft·wpf
大飞记Python4 小时前
部门管理|“编辑部门”功能实现(Django5零基础Web平台)
前端·数据库·python·django
tsumikistep5 小时前
【前端】前端运行环境的结构
前端
你的人类朋友5 小时前
【Node】认识multer库
前端·javascript·后端
Aitter5 小时前
PDF和Word文件转换为Markdown的技术实现
前端·ai编程
mapbar_front6 小时前
面试问题—上家公司的离职原因
前端·面试
昔人'6 小时前
css使用 :where() 来简化大型 CSS 选择器列表
前端·css
昔人'6 小时前
css `dorp-shadow`
前端·css
流***陌7 小时前
扭蛋机 Roll 福利房小程序前端功能设计:融合趣味互动与福利适配
前端·小程序