返回首页
🎨 前端 / Web
Tailwind CSS 4 alpha 抢先看:CSS-first 配置
Tailwind 4 是 5 年来最大重写。本文展示 alpha 版新特性,以及从 v3 到 v4 的迁移。
Tailwind · CSS · Lightning CSS · 前端
📰
今日技术简讯
📰 技术简讯 · 2026-05-14
今日聚合 6 条热门技术内容。
🤖 AI / LLM
1. GPT-5 多模态进入公测
- 链接:https://platform.openai.com/docs/multimodal
- 来源:OpenAI
- 摘要:GPT-5 多模态公测,图像 + 音频 + 视频统一接口。
🎨 前端 / Web
2. Tailwind CSS 4 alpha 抢先看
- 链接:https://tailwindcss.com/blog/v4-alpha
- 来源:Tailwind CSS
- 摘要:Tailwind 4 alpha 推出 CSS-first 配置 + Lightning CSS 引擎。
⚙️ 后端 / 架构
3. CockroachDB 24.2 异地多活
- 链接:https://www.cockroachlabs.com/blog/24-2
- 来源:Cockroach Labs
- 摘要:分布式 SQL 数据库新增异地多活特性,跨区域延迟 < 50ms。
🚀 独立开发 / OPC
4. 《SaaS SEO Playbook》发布
- 链接:https://saas-seo-playbook.com
- 来源:社区
- 摘要:100 页实战手册,覆盖关键词研究、内容策略、外链建设。
5. Outseta 推出 AI 客服
- 链接:https://www.outseta.com/ai-support
- 来源:Outseta
- 摘要:内置 AI 客服机器人,自动回复 80% 常见问题。
6. Dub.co 推出 Payouts 2.0
- 链接:https://dub.co/payouts-2
- 来源:Dub
- 摘要:联盟营销自动结算,支持全球 50+ 国家、20+ 货币。
数据来源:掘金 / InfoQ 中文 / HN / GitHub / Dev.to 采集时间:2026-05-14 09:00 (UTC+8)
📝
今日深度文
Tailwind CSS 4 alpha 抢先看:CSS-first 配置
一句话结论:Tailwind 4 把配置从 JS 移到 CSS,引擎换成 Lightning CSS。构建速度提升 10 倍。
5 个重大变化
1. CSS-first 配置
/* ❌ Tailwind 3:tailwind.config.js */
module.exports = {
theme: {
extend: {
colors: {
brand: '#7c3aed',
},
},
},
};
/* ✅ Tailwind 4:直接在 CSS 里 */
@import "tailwindcss";
@theme {
--color-brand: #7c3aed;
}
优势:
- 不用切换 JS / CSS 上下文
- CSS 变量自动可用
- IDE 高亮更好
2. Lightning CSS 引擎
# 构建时间对比(100 个组件项目)
Tailwind 3 (PostCSS): 12.5s
Tailwind 4 (Lightning CSS): 1.4s
优势:
- 用 Rust 写的 CSS 解析器
- 比 PostCSS 快 10 倍
- 支持现代 CSS 语法(嵌套、color-mix)
3. 自动内容检测
// ❌ Tailwind 3:必须配置 content
module.exports = {
content: [
"./src/**/*.{js,ts,jsx,tsx}",
"./app/**/*.{js,ts,jsx,tsx}",
],
};
// ✅ Tailwind 4:自动检测所有源文件
// 无需配置!
4. CSS 变量主题
@theme {
--color-primary: #7c3aed;
--color-secondary: #ec4899;
--font-display: "Inter", sans-serif;
--spacing-1: 4px;
--spacing-2: 8px;
}
/* 自动生成:bg-primary, text-secondary, font-display */
5. 容器查询内置
<!-- ❌ Tailwind 3:需插件 -->
<!-- @tailwindcss/container-queries -->
<!-- ✅ Tailwind 4:内置 -->
<div class="@md:flex-row flex-col">
...
</div>
安装(alpha)
npm install tailwindcss@next
postcss.config.mjs:
export default {
plugins: {
"@tailwindcss/postcss": {},
},
};
globals.css:
@import "tailwindcss";
@theme {
--color-brand-50: #f5f3ff;
--color-brand-500: #8b5cf6;
--color-brand-900: #4c1d95;
}
@layer base {
h1 {
font-size: var(--text-2xl);
}
}
迁移指南
Step 1:升级依赖
npm install tailwindcss@next @tailwindcss/postcss@next
npm uninstall tailwindcss postcss autoprefixer
Step 2:删除配置
# 删除 tailwind.config.js(v4 不再需要)
Step 3:迁移 globals.css
/* v3 风格(删除) */
@tailwind base;
@tailwind components;
@tailwind utilities;
/* v4 风格(新增) */
@import "tailwindcss";
Step 4:迁移自定义颜色
// ❌ v3: tailwind.config.js
extend: {
colors: {
brand: {
500: '#8b5cf6',
},
},
}
// ✅ v4: globals.css
@theme {
--color-brand-500: #8b5cf6;
}
Step 5:测试
npm run dev
npm run build
5 个常见坑
坑 1:alpha 阶段有 bug
生产环境暂不推荐用 alpha
等 2026 Q3 stable 再升级
坑 2:插件不兼容
# 老插件可能不工作
# 检查:https://tailwindcss.com/docs/installation
坑 3:暗色模式配置变化
/* ❌ v3:darkMode: 'class' 在 config */
/* ✅ v4:用 @custom-variant */
@custom-variant dark (&:where(.dark, .dark *));
坑 4:自定义动画
/* ❌ v3:@layer utilities */
/* ✅ v4:@theme + @keyframes */
@theme {
--animate-fade-in: fadeIn 0.3s ease-in;
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
}
坑 5:JIT 模式默认开启
// 不再需要 purge 配置
// 自动 tree-shake 未使用的类
何时升级
现在升级(alpha)
- 新项目(无历史包袱)
- 喜欢尝试新特性
- 想体验 10x 构建速度
等 stable 再升级
- 现有大型项目
- 依赖大量第三方插件
- 团队不愿冒险
不升级
- 项目已用 Tailwind 3 稳定运行
- 没有性能瓶颈
我的看法
Tailwind 4 是 5 年来最重要的升级:
- CSS-first 配置 → 更符合 CSS 工作流
- Lightning CSS → 构建快 10 倍
- 零配置 → 上手成本更低
- 现代 CSS 特性 → 跟上前沿
但 alpha 阶段不稳定,建议新项目试用,老项目等 stable。
参考
本文基于 Tailwind 4 alpha.2,2026 年 5 月最新。
📚 同主题文章
🎨前端 / Web·
shadcn/ui + 设计系统 2026:现代 Web 产品的 UI 实战
shadcn/ui 是 2026 年最火的前端组件库 + 设计系统方案。本文从 0 到完整设计系统,含 5 个真实项目 + 主题定制 + 组件库扩展 + A11y。
shadcn/ui设计系统Tailwind v4
🎨前端 / Web·
React 19 实战:从 Server Components 到 Server Actions 完整指南
React 19 是前端框架的"分水岭"——Server Components 让前端从"CSR + API"转向"RSC + Actions"。本文从 0 到生产级 RSC 实战,含 4 个真实项目 + 性能对比。
ReactServer ComponentsServer Actions
🎨前端 / Web·
TypeScript 5.6 实战:从入门到生产级类型系统
TypeScript 5.6 引入 infer const / iterator helpers 等重磅特性。本文从基础到生产级类型系统实战,含 4 个真实项目 + 类型设计模式。
TypeScript类型系统前端