三分钟在你的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官网教程

相关推荐
子兮曰4 天前
jev-ultrafast 深度解析:7 秒订机票的浏览器 Agent 是如何炼成的
前端·后端·agent
子兮曰4 天前
Jev 爆发一周:7 秒 Agent 背后的 System One 生态与三场争议
前端·后端·ai编程
前端小万4 天前
写公众号赚了 3000 块后,我做了一款叫 "一键成稿" 的软件
前端·微信小程序
爱勇宝4 天前
ZCode 开源 24 小时:一份没有历史的账本,回答不了"有没有偷代码"
前端·后端·chatglm (智谱)
三十而立洋4 天前
Cookie 详解:从产生到安全,一次讲透
前端·javascript
卡布鲁4 天前
把一个 Vite + Vue3 应用塞进 qiankun (React + Umi3) 主站:十个坑的复盘
前端·javascript·react.js
汉堡大王95275 天前
Jev:不是聊天机器人, 而是一个智能 if 语句
前端·人工智能·后端
梦想很大很大5 天前
从运行事实到回归证据:Workrun 的 Telemetry 与 Evaluation 实践
前端·人工智能·后端
计算机魔术师5 天前
Meta Muse agent 接入 Shopify 的 Shop Pay 实现代理式购物
前端
沙蒿同学5 天前
我用 Go 搭了一条 AI Agent 流水线:从 1 张商品图到一整套淘宝详情页
前端·javascript·后端