新しいバージョンの HeroUI ( + tailwindcss@4 )をノリで適当にインストールすると、cssがきなかい。ということが起きるのでしっかりと設定方法を確認しましょう。
npm install @heroui/react framer-motion
hero.tsが必要になります。hero.ts - HeroUIプラグインの定義です。
重要なのは:
hero.ts
import { heroui } from "@heroui/react";
export default heroui();
globals.css
@import "tailwindcss";
@plugin "./hero.ts";
/* このファイルからの相対パス */
@source "../../node_modules/@heroui/theme/dist/**/*.{js,ts,jsx,tsx}";
@custom-variant dark (&:is(.dark *));
postcss.config.mjs
const config = {
plugins: {
"@tailwindcss/postcss": {
content: [
// ● 実は以下の行は不要です。削除してしまってもok
// "./src/**/*.{js,ts,jsx,tsx}",
// "./node_modules/@heroui/**/*.{js,ts,jsx,tsx}"
]
}
}
};
export default config;
tailwind.config.ts → 不要です。
以上です。簡単ですね。
1 . src/app/providers.tsx
'use client'
import { FC, ReactNode } from "react"
import {HeroUIProvider} from "@heroui/react";
type Props = {
children: ReactNode;
}
export const Providers: FC<Props> = ({children}) => {
return (
<HeroUIProvider>
{children}
</HeroUIProvider>
);
};
2 . src/app/layout.tsx
+ <Providers>
{children}
+ </Providers>
3 . src/app/page.tsx
'use client'
import {Button} from "@heroui/react";
export default function Home() {
return (
<Button color="secondary">Button</Button>
);
}