프로젝트 생성
새로운 Astro 프로젝트를 생성하는 것부터 시작합니다:
Astro 프로젝트 구성
프로젝트를 구성하기 위한 몇 가지 질문이 표시됩니다:
- Where should we create your new project?
./your-app-name
- How would you like to start your new project?
Choose a starter template (or Empty)
- Install dependencies?
Yes
- Initialize a new git repository? (optional)
Yes/No 프로젝트에 Svelte 추가
Astro CLI를 사용하여 Svelte를 설치합니다:
Svelte 설치 시 CLI에서 표시되는 모든 질문에 Yes로 답변하세요.
프로젝트에 TailwindCSS 추가
Astro CLI를 사용하여 Tailwind CSS를 추가합니다:
TailwindCSS 설치 시 CLI에서 표시되는 모든 질문에 Yes로 답변하세요.
전역 CSS 파일 불러오기
src/pages/index.astro 파일에 global.css 파일을 불러옵니다:
---
import "../styles/global.css";
--- 경로 별칭 설정
경로를 해석하기 위해 tsconfig.json 파일에 다음 코드를 추가합니다:
{
"compilerOptions": {
// ...
"baseUrl": ".",
"paths": {
"$lib": ["./src/lib"],
"$lib/*": ["./src/lib/*"]
}
// ...
}
} 필요한 경우, 특정 요구사항에 맞게 경로 별칭을 조정하세요 (자세히 알아보기).
CLI 실행
프로젝트를 설정하기 위해 shadcn-svelte init 명령어를 실행합니다:
components.json 구성
components.json을 구성하기 위한 몇 가지 질문이 표시됩니다:
Which base color would you like to use? › Slate
Where is your global CSS file? (this file will be overwritten) › src/styles/global.css
Configure the import alias for lib: › $lib
Configure the import alias for components: › $lib/components
Configure the import alias for utils: › $lib/utils
Configure the import alias for hooks: › $lib/hooks
Configure the import alias for ui: › $lib/components/ui 완료
이제 프로젝트에 컴포넌트를 추가할 수 있습니다.
위 명령어는 프로젝트에 Button 컴포넌트를 추가합니다. 다음과 같이 불러올 수 있습니다:
---
import { Button } from "$lib/components/ui/button/index.js";
---
<html lang="en">
<head>
<title>Astro</title>
</head>
<body>
<Button>Hello World</Button>
</body>
</html> 인터랙티브 컴포넌트를 다룰 때는 .astro 파일 내에서 client 디렉티브를 사용해야 합니다 (자세히 알아보기).