tailwind 在我的 nextjs 项目上无法正常工作,我已经检查了所有配置,但没有检查出来。
我发现当我从导航栏组件中携带似乎不起作用的代码并将其放入我的 page.js 中时,它开始工作,这些类将适用,如果我返回到我的导航栏组件添加更多样式,一切都会看起来不错一段时间然后再次停止,我必须再次将我的导航栏代码携带到 page.js 才能再次开始工作。
我的导航栏组件
import Link from 'next/link'
import React from 'react'
import { BiSolidFoodMenu } from "react-icons/bi";
import { RiEBike2Line } from "react-icons/ri";
import { TbInfoOctagon } from "react-icons/tb";
import { TiContacts } from "react-icons/ti";
const Navbar = () => {
return (
<div className=' flex items-center w-full justify-around space-x-3'>
<div>
<h1 className='style '>
LUIGIE HOUSE
</h1>
</div>
<div className='flex space-x-3'>
<div className='flex flex-row items-center space-x-2'>
<Link href='#'>Home</Link>
<BiSolidFoodMenu />
</div>
<div className='flex flex-row items-center space-x-2'>
<Link href='#'>About</Link>
<RiEBike2Line />
</div>
<div className='flex flex-row items-center'>
<Link href='#'>Delivery</Link>
<TbInfoOctagon />
</div>
<div className='flex flex-row items-center'>
<Link href='#'>Contact</Link>
<TiContacts />
</div>
</div>
<div>
Buy
</div>
</div>
)
}
export default Navbar
我的顺风config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./app/**/*.{js,ts,jsx,tsx,mdx}",
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
],
jit: true,
theme: {
extend: {},
},
plugins: [],
}
我的问题是我的顺风类不适用于我的项目,直到我从导航栏组件中取出代码,并将其放在我的 page.js 上,然后它才能工作。然后我发现我的类现在正在工作,所以我去删除 page.js 上的代码并返回到我的导航栏组件,只是为了我的类在几分钟后再次停止工作。
-检查全局样式中或包含 Tailwind CSS 的任何位置是否具有正确的导入语句:
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
注意*:确保这些导入位于主 CSS 文件的开头。
-如果您仍然面临某些类未应用的问题,您可以尝试将它们明确包含在安全列表属性中。这可确保 Tailwind 在优化过程中不会清除这些类:
module.exports = {
// ...
jit: true,
content: [
// ... (as before)
],
safelist: [
// Add the classes that are not being applied in your Navbar
'your-safelisted-class-1',
'your-safelisted-class-2',
// ...
//Replace 'your-safelisted-class-1', 'your-safelisted-class-2', etc.,
with the actual classes that are not working as expected.
],
// ...
};
进行这些修改后,重新启动开发服务器并检查问题是否仍然存在。