Astro
How to setup shadcn-svelte in an Astro project.
Setup your project
Create project
Start by creating a new Astro project:
Configure your Astro project
You will be asked a few questions to configure your project:
Add Svelte to your project
Install Svelte using the Astro CLI:
Answer Yes
to all the question prompted by the CLI when installing Svelte.
Add TailwindCSS to your project
Add Tailwind CSS using the Astro CLI:
Answer Yes
to all the question prompted by the CLI when installing Svelte.
Setup path aliases
Add the following code to the tsconfig.json
file to resolve paths:
If needed, adapt the path aliases to your specific needs (learn more about it).
Create a global CSS file
Create the global stylesheet in src/styles/app.css
:
Import the global CSS file
Import the app.css
file in the src/pages/index.astro
file:
Run the CLI
Run the shadcn-svelte
init command to setup your project:
Configure components.json
You will be asked a few questions to configure components.json
:
Update Astro's Tailwind config
To prevent serving the Tailwind base styles twice, we need to tell Astro not to apply the base styles, since we already include them in our own app.css
file. To do this, set the applyBaseStyles
config option for the tailwind plugin in astro.config.mjs
to false
.
Update tailwind.config.mjs
When running shadcn-svelte@next init
, your Tailwind config for content will be overwritten. To fix this, add astro
as one of the options inside of content
:
That's it
You can now start adding components to your project.
The command above will add the Button
component to your project. You can then import it like this:
Remember to use the client
directives inside .astro
files when dealing with interactive components (learn more about it).
On This Page