Flowbite 시작하기 — Laravel
이 문서는 Laravel 프로젝트에 Flowbite를 설치하고 Tailwind CSS와 함께 통합하는 방법을 안내해요. Laravel은 기본적으로 Vite + Tailwind CSS(또는 Blade)를 지원하므로 Flowbite를 쉽게 붙일 수 있어요.
출처: 문서
본문
먼저 Composer로 Laravel 프로젝트를 만들고 npm으로 Tailwind CSS와 Flowbite를 설치해요.
composer create-project laravel/laravel example-app
cd example-app
npm install
npm install flowbite
Tailwind 설정
Laravel 10 이상에서 tailwind.config.js의 콘텐츠 경로에 Flowbite의 자바스크립트 파일을 추가하고, 플러그인을 등록해요.
import flowbite from "flowbite/plugin";
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./resources/**/*.blade.php",
"./resources/**/*.js",
"./resources/**/*.vue",
"./node_modules/flowbite/**/*.js",
],
theme: {
extend: {},
},
plugins: [flowbite],
};
컴포넌트 사용
이제 Blade 템플릿에서 Flowbite의 클래스 기반 컴포넌트를 그대로 사용할 수 있어요. 상호작용이 필요한 컴포넌트(드롭다운, 모달 등)는 Flowbite의 자바스크립트를 함께 로드해야 해요.
<!-- resources/views/welcome.blade.php -->
<!DOCTYPE html>
<html lang="en">
<head>
@vite(['resources/css/app.css', 'resources/js/app.js'])
<title>Flowbite + Laravel</title>
</head>
<body>
<button type="button" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800">
Flowbite Button
</button>
<script src="https://cdn.jsdelivr.net/npm/flowbite@latest/dist/flowbite.min.js"></script>
</body>
</html>
이렇게 하면 Laravel 애플리케이션에서 Flowbite 컴포넌트를 바로 활용할 수 있어요.