H I*_*H I 9 next.js tailwind-css
Shadcn UI ( https://ui.shadcn.com/ ) 工作正常,直到我只工作了几周,直到昨天,当我在本地主机中运行我的 NextJS 应用程序时,所有顺风车都不起作用。为了调试这个问题,我在一个全新的文件位置创建了一个空白的 NextJS 13 应用程序,一切正常;tailwind 正在默认的 nextJS 13 页面上工作。然后我跑了
npx shadcn-ui init
Run Code Online (Sandbox Code Playgroud)
无需安装任何组件。它没有吐出任何错误,但随后顺风样式不再起作用。
注入后我的tailwind.config.js:
/** @type {import('tailwindcss').Config} */
module.exports = {
darkMode: ["class"],
content: [
'./pages/**/*.{ts,tsx}',
'./components/**/*.{ts,tsx}',
'./app/**/*.{ts,tsx}',
],
theme: {
container: {
center: true,
padding: "2rem",
screens: {
"2xl": "1400px",
},
},
extend: {
colors: {
border: "hsl(var(--border))",
input: "hsl(var(--input))",
ring: "hsl(var(--ring))",
background: "hsl(var(--background))",
foreground: "hsl(var(--foreground))",
primary: {
DEFAULT: "hsl(var(--primary))",
foreground: "hsl(var(--primary-foreground))",
},
secondary: {
DEFAULT: "hsl(var(--secondary))",
foreground: "hsl(var(--secondary-foreground))",
},
destructive: {
DEFAULT: "hsl(var(--destructive))",
foreground: "hsl(var(--destructive-foreground))",
},
muted: {
DEFAULT: "hsl(var(--muted))",
foreground: "hsl(var(--muted-foreground))",
},
accent: {
DEFAULT: "hsl(var(--accent))",
foreground: "hsl(var(--accent-foreground))",
},
popover: {
DEFAULT: "hsl(var(--popover))",
foreground: "hsl(var(--popover-foreground))",
},
card: {
DEFAULT: "hsl(var(--card))",
foreground: "hsl(var(--card-foreground))",
},
},
borderRadius: {
lg: "var(--radius)",
md: "calc(var(--radius) - 2px)",
sm: "calc(var(--radius) - 4px)",
},
keyframes: {
"accordion-down": {
from: { height: 0 },
to: { height: "var(--radix-accordion-content-height)" },
},
"accordion-up": {
from: { height: "var(--radix-accordion-content-height)" },
to: { height: 0 },
},
},
animation: {
"accordion-down": "accordion-down 0.2s ease-out",
"accordion-up": "accordion-up 0.2s ease-out",
},
},
},
plugins: [require("tailwindcss-animate")],
}
Run Code Online (Sandbox Code Playgroud)
滴注后我的utils.ts
import { ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
Run Code Online (Sandbox Code Playgroud)
编辑:经过一些测试,问题似乎来自 globals.css 和 tailwind.config.js,但仍然不确定它们是什么。
小智 10
就我而言,Shadcn 组件没有找到 tailwind 导出的样式。正如@moyindavid 所回答的,问题出在 tailwind.config 中。
解决方案:将“@”文件夹添加到tailwind属性的导出中。
module.exports = {
darkMode: ["class"],
content: [
'./pages/**/*.{ts,tsx}',
'./components/**/*.{ts,tsx}',
'./app/**/*.{ts,tsx}',
'./@/**/*.{ts,tsx}', // <- HERE
],
Run Code Online (Sandbox Code Playgroud)
如果您的情况与我的类似,并且您使用 src 文件夹来包装 app 文件夹,则问题来自 tailwind 配置文件。
/** @type {import('tailwindcss').Config} */
module.exports = {
darkMode: ["class"],
content: [
'./pages/**/*.{ts,tsx}',
'./components/**/*.{ts,tsx}',
'./app/**/*.{ts,tsx}',
],
Run Code Online (Sandbox Code Playgroud)
这就是你所拥有的。但是,内容映射到错误的目录。使用此更新内容数组中的字符串。
content: [
'./src/app/**/*.{ts,tsx}', './src/components/**/*.{ts,tsx}',
],
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9048 次 |
最近记录: |