μ κ° λ§λ Svelte Web μ μ μ΄λ κ² λͺ»μκ²Όλμ? DaisyUI μΈκ³΅νΈν‘κΈ°λ₯Ό λΆμ¬λ΄μ! #4
ν΄λΉ κ²μκΈμ
(1) DaisyUI κ°μ
(2) DaisyUI μ μ© λ°©λ²
μ λν λ΄μ©μ λ΄κ³ μμ΅λλ€.
SvelteKit μ μμ¦ μ μΌ μΈκΈ°λ§λ€λ TailwindCSS λ₯Ό μ μ©ν΄λ³ΌκΉμ? #3
ν΄λΉ κ²μκΈμ (1) TailwindCSS κ°μ (2) TailwindCSS μ μ© λ°©λ² μ λν λ΄μ©μ λ΄κ³ μμ΅λλ€. μ΄μ κ²μκΈ - μ μ μΆμλ SvelteKit μΌλ‘ κ°λ° νκ²½μ ꡬμ±ν΄λ³΄κ² μ΅λλ€! #2 μ μ μΆμλ SvelteKit μΌλ‘ κ°λ°
gngb-tech.tistory.com
ch1 - DaisyUI λ?
DaisyUI κ° λμμ? κΌ μ¬μ©ν΄μΌ νλμ?
TailwindCSS Component Library
DaisyUI λ μ΄μ κ²μκΈμμ λ€λ£¬ TailwindCSS Framework μ μ’ μλ Library μ λλ€. DaisyUI λ μ¬μ μ μλ¦λ΅κ² λμμΈλμ΄ μλ μ¬λ¬κ°μ§ UI Component λ₯Ό κ°λ°μκ° μνλλλ‘ μ¬μ©ν μ μλ Utility Tool μ΄λ©°, (Bootstrap μ μ¬μ© λ°©μκ³Ό μ μ¬ν©λλ€.) TailwindCSS μ κΈ°λ°νκΈ° λμνκΈ° λλ¬Έμ TailwindCSS κ° μ€μΉλμ§ μμ νκ²½μμλ μ μμ μΌλ‘ μλνμ§ μμ΅λλ€. μ΄λ¬ν μΈ‘λ©΄μμ, DaisyUI λ₯Ό TailwindCSS Component Library λ‘ λΆλ₯ν©λλ€.
μ¬μ©νλ μ΄μ
(TailwindCSS λ₯Ό ν¬ν¨νμ¬) μΈλΆμ μΈ CSS λ₯Ό λͺ¨λ μ‘°μνλ©°, Web κ°λ°μ νμν λ€μν UI Component μ λμμΈμ μ§μ ꡬννμ¬ νμ©νλ κ²μ νμ€μ μΌλ‘ μ΄λ ΅μ΅λλ€. λμμΈ μμλ₯Ό ꡬννλ μκ°μ΄ κΈΈμ΄μ§κΈ° λλ¬Έμ λ μ€μν λΆλΆμ κ°λ°νλ κ³Όμ μ μ§μ€νμ§ λͺ»νκ² λ κ°λ₯μ±μ΄ λμμ§λ©°, λμμΈ μΈ‘λ©΄μμλ μ¬λ¬κ°μ§ UI Component μμ 컨μ μ μΈ μΌκ΄μ±μ μ μ§νμ§ λͺ»νμ¬ λμ‘ν (보기μ μ’μ§ μμ) Web μ΄ λ κ°λ₯μ±μ΄ λμμ§λλ€. 무μλ³΄λ€ μΈλΆμ μΈ CSS λ₯Ό λͺ¨λ μ§μ ꡬννλ κ³Όμ μ μΌλΆ Frontend κ°λ°μλ₯Ό μ μΈνκ³ , λλΆλΆμ κ°λ°μλ€μκ²λ κ³ ν΅κ³Ό μΈλ΄μ μκ°μΌλ‘ λ€κ°μ΅λλ€.
μ λͺ©μ²λΌ, (μΈλ΄μ¬μ΄ λ§κ³ λμμΈ κ°κ°μ΄ μ’μ μΌλΆ κ°λ°μλ€μ μ μΈνκ³ ) κ·Όλ³Έμ μΌλ‘ λͺ»μκΈ΄ Web μ λ§λ€μ§ μλ κ°μ₯ μ¬μ΄ λ°©λ²μ μ¬μ μ μ μλ νλ₯ν λμμΈμ νμ©νλ κ² μ λλ€. μ΄λ¬ν μΈ‘λ©΄μμ, TailwindCSS κΈ°λ°μ λμμΈ ν νλ¦Ώμ νμ©ν μ μλ λ¬΄λ£ Plugin μ΄ μ‘΄μ¬νλ€λ©΄ μ¬μ©νμ§ μμ μ΄μ λ₯Ό μμ΅λλ€. ν΄λΉ κ²μκΈμμλ DaisyUI λ₯Ό κΈ°μ‘΄ SvelteKit (w/ TailwinCSS) νκ²½μ μ€μΉνκ³ λμμΈμ μ μ©νλ λͺ κ°μ§ μμλ₯Ό λ€λ£¨λλ‘ νκ² μ΅λλ€.
ch2 - SvelteKit (w/ TailwindCSS) νκ²½μ μ μ©νλ λ°©λ²
DaisyUI λ₯Ό μ€μΉνκ³ , μ μ©ν μμλ₯Ό 보μ¬μ£ΌμΈμ!
μ€μΉ
μ΄μ κ²μκΈμμ μ€μ ν κ°λ° νκ²½μ΄ μ μ λμ΄μΌ ν©λλ€. μ¦, SvelteKit κ°λ° νκ²½μ TailwinCSS κ° μ€μΉλκ³ μ μμ μΌλ‘ μ μ©λ μν©μ μ μ λ‘ ν©λλ€. DaisyUI μ μ€μΉ λ°©λ²μ λΉκ΅μ λ¨μν©λλ€. μλμ μ΄λ―Έμ§μ κ°μ΄, npm μ ν΅ν΄ Daisyui λ₯Ό μ€μΉνκ³ tailwind.config.cjs μ plugins λΆλΆμ require("daisyui") ꡬ문μ μΆκ°νλ©΄ νκ²½ μ€μ μ΄ μλ£λ©λλ€.
λμμΈ μ μ©
DaisyUI 곡μ ννμ΄μ§ μ΅μλ¨ νμ΄μ§μμ μ¬λ¬κ°μ§ UI Component λ₯Ό Preview ννλ‘ λ³΄μ¬μ£Όλλ°, λΉμ₯ μ μ©ν΄λ³΄κ³ μΆμ λ§€λ ₯μ μΈ Component μμλ€μ΄ λμ λλλ€.
μ‘°κΈ λ λ€μν Component μ’ λ₯μ ꡬ체μ μΈ λμμΈ μ μ© λ°©λ²μ DaisyUI Component νμ΄μ§μμ νμΈν μ μμ΅λλ€. ν΄λΉ κ²μκΈμμλ NavBar (μ΅μλ¨ λ€λΉκ²μ΄μ λ°) λμμΈμ μ μ©ν΄ λ³΄κ² μ΅λλ€.
NavBar Component νμ΄μ§μλ λ€μν NavBar λμμΈ μμκ° μ‘΄μ¬νλλ°, μλ μ΄λ―Έμ§μ νΉμ λμμΈ μμλ₯Ό SvelteKit μ μ μ©ν΄λ³΄κ² μ΅λλ€. νΉμ λμμΈ ν νλ¦Ώμ Preview νμ UI Component λ₯Ό Web μ μ μ©νμ λμ ννλ₯Ό 미리 보μ¬μ€λλ€.
HTML νμμλ Preview νμμ λ³Έ λμμΈμ΄ HTML (w/ CSS) ννλ‘ μ 리λμ΄ μλ κ²μ νμΈν μ μμ΅λλ€. (HTML Tag (<div> λ±) μ class ꡬ문μ 보면, TailwindCSS λ¬Έλ² ννκ° μ μ©λμ΄ μλ κ²μ΄ 보μ λλ€.)
ν΄λΉ μ½λλ₯Ό 볡μ¬νμ¬ ./src/routes/+layout.svelte νμΌμ λΆμ¬ λ£μ΅λλ€.
<script>
import '../app.css';
</script>
<div class="navbar bg-base-100">
<div class="flex-none">
<button class="btn btn-square btn-ghost">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
class="inline-block w-5 h-5 stroke-current"
><path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M4 6h16M4 12h16M4 18h16"
/></svg
>
</button>
</div>
<div class="flex-1">
<!-- svelte-ignore a11y-missing-attribute -->
<a class="btn btn-ghost normal-case text-xl">daisyUI</a>
</div>
<div class="flex-none">
<button class="btn btn-square btn-ghost">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
class="inline-block w-5 h-5 stroke-current"
><path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M5 12h.01M12 12h.01M19 12h.01M6 12a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0z"
/></svg
>
</button>
</div>
</div>
<slot />
+layout.svelte νμΌμ μμ±λ μ½λλ μ 체 Web νλ©΄ ꡬ쑰μ μν₯μ λ―ΈμΉλ―λ‘ κΈ°μ‘΄μ μμ±νλ ννμ΄μ§ 컨ν μΈ μλ¨μ λ€λΉκ²μ΄μ λ°κ° μκΈ°λ κ²μ νμΈν μ μμ΅λλ€.
λμμΈ μ»€μ€ν°λ§μ΄μ§
DaisyUI Component λ₯Ό μ¬μ©νλλΌλ, TailwindCSS λ¬Έλ² νΉμ DaisyUI μ 곡 μμ±μ μ¬μ©νμ¬ λμμΈμ 컀μ€ν°λ§μ΄μ§ ν μ μμ΅λλ€. (DaisyUI λ₯Ό νμ©νλλΌλ μνλ λμμΈμ ꡬννλ €λ©΄ κΈ°λ³Έμ μΌλ‘ TailwindCSS λ¬Έλ²μ μμ§ν΄μΌ νλ€λ κ²μ λ€μ νλ² κΉ¨λ¬μμ΅λλ€.) μλμ μ½λλΈλμ ./src/routes/+layout.svelte νμΌ μ€, λ€λΉκ²μ΄μ λ°μ μ’μΈ‘ ννμ΄μ§ μ λͺ© λΆλΆμ λν λ³κ²½ μμμ λλ€. 곡ν΅μ μΌλ‘, κΈ°λ³Έ ν νλ¦Ώμμ μ λͺ©μ 'daisyUI' μμ 'GNGB-tech-blog' λ‘ λ³κ²½νμκ³ λ²νΌ μμμ λΆμ¬νμ΅λλ€. 첫 λ²μ§Έ μμλ class ꡬ문μ TailwindCSS λ¬Έλ²μΌλ‘, λ λ²μ§Έ μμλ DaisyUI μ 곡 μμ±μΌλ‘ 컀μ€ν°λ§μ΄μ§ νμμ΅λλ€. DaisyUI μ λ²νΌ Component μ 곡 μμ±μ λ§ν¬λ νμ΄μ§μμ μμΈμ¬νμ νμΈν μ μμ΅λλ€.
// κΈ°λ³Έ ν
νλ¦Ώ
<div class="flex-1">
<a class="btn btn-ghost normal-case text-xl">daisyUI</a>
</div>
// κΈ°λ³Έ ν
νλ¦Ώ 컀μ€ν°λ§μ΄μ§ (w/ TailwindCSS)
<div class="flex-1">
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">GNGB-tech-blog</button>
</div>
// κΈ°λ³Έ ν
νλ¦Ώ 컀μ€ν°λ§μ΄μ§ (w/ DaisyUI μ 곡 μμ±)
<div class="flex-1">
<button class="btn btn-primary normal-case text-xl">GNGB-tech-blog</button>
</div>
λΉμ 곡μκ° Svelte λ₯Ό 곡λΆνλ κ³Όμ μμ κ²ͺκ² λ μ΄λ €μκ³Ό μνμ°©μ€λ₯Ό λ¨Όμ κ²½ννκ³ , μ΄μ΄μ§ κ²μκΈμμ μ΅λν μ½κ² 곡μ ν΄λλ¦¬κ³ μ ν©λλ€. μλͺ»λ λ΄μ©μ λν μ§μ μ¬νμ΄λ λ¬Έμμ¬νμ μΈμ λ μ§ νΈνκ² λκΈλ‘ λ¨κ²¨μ£ΌμκΈΈ λ°λΌκ² μ΅λλ€.
