Astro
Install and configure Astro.
Create a New Astro Project
Start by initializing your new Astro project using npm. This command will launch an interactive setup process:
During initialization, you'll be guided through several important configuration choices:
Take your time with these choices as they'll set up the foundation of your project.
Add React Integration
Now we'll enhance your Astro project with React support. This integration allows you to use React components seamlessly within your Astro pages:
When the CLI prompts you with configuration questions, answer "Yes" to all of them. This ensures React is fully integrated with your Astro setup, including all necessary dependencies and configuration settings.
Install Tailwind CSS
Let's add Tailwind CSS to provide powerful utility-first styling capabilities:
This command not only installs Tailwind CSS but also sets up all the necessary configuration files and integrates it with your Astro build process.
Set Up Global Styles
Create a new directory for your styles and add the essential Tailwind directives:
Then create src/styles/globals.css
with these fundamental Tailwind imports:
These directives enable Tailwind's core functionality throughout your project.
Import Global Styles
Connect your global styles to your application by adding this import to your main page:
Place this import in src/pages/index.astro
to ensure your Tailwind styles are available throughout your application.
Configure Tailwind Base Styles
To prevent style duplication, update your astro.config.mjs
to manage Tailwind's base styles:
This configuration ensures that Tailwind's base styles are only applied once, preventing any potential styling conflicts.
Set Up TypeScript Path Resolution
Enhance your development experience by configuring TypeScript path aliases in tsconfig.json
:
This configuration enables clean and consistent import paths throughout your project.
Initialize shadcn
Set up shadcn to access its component library:
Follow the CLI prompts to configure shadcn according to your project needs. This step prepares your environment for using shadcn's pre-built components.
Add Your First Component
Install your first shadcn component. Let's start with the fundamental Button component:
This command adds the Button component and all its dependencies to your project's component library.
Implement Your First Component
Finally, put your new component to use in an Astro page:
This implementation demonstrates how to integrate shadcn components within your Astro pages.