Building a weather application
Learn how to build a fully styled weather dashboard in Aurelia 2 with Tailwind CSS and Vite.
Aurelia 2 provides a powerful and flexible framework for building modern web applications. By integrating Tailwind CSS and Vite, we can create a fully responsive and beautifully styled weather dashboard that fetches real-time weather data. This guide will walk you through setting up the project, configuring Tailwind CSS, and building the UI.
Prerequisites
Ensure you have Node.js (latest LTS version recommended) installed.
1. Setting Up the Aurelia Project with Vite
Create a New Aurelia Project
Run the following command to scaffold a new Aurelia 2 project using Vite:
Select "Default TypeScript App" and "Vite" as the bundler when prompted. When you're asked for a name, make something up or use weather-app
.
Navigate to Your Project Directory
2. Installing and Configuring Tailwind CSS
Install Tailwind CSS and Its Vite Plugin
To integrate Tailwind CSS with Vite, install the required dependencies:
Configure Vite to Use Tailwind CSS
Update your vite.config.ts
to include the Tailwind CSS Vite plugin:
Include Tailwind in Your CSS
In your scaffolded project, you'll see a my-app.css
file. Open it and add the following:
Aurelia will automatically include this file when you run npm start
because of the default conventions support in Aurelia projects.
3. Implementing the Weather Dashboard
Fetching Weather Data
Sign up for a free API key from OpenWeatherMap to fetch real-time weather data. You get a few thousand requests per day for free.
Create a Weather Service to handle API requests:
4. Creating the Weather Dashboard Component
Weather Dashboard View Model
Create a component that fetches weather data and manages state:
Weather Dashboard View (HTML)
Now, style the dashboard UI with Tailwind CSS:
5. Adding the Component to the Application
Include the Weather Dashboard component in your main app:
6. Running the Application
Start the development server:
The browser will open automatically to the Aurelia app.
7. Additional Enhancements
Dark Mode Support: Configure Tailwind to support dark mode and apply corresponding styles.
Responsive Design: Utilize Tailwind’s responsive utilities for mobile-friendly UI.
Custom Themes: Extend Tailwind’s theme in tailwind.config.js for custom branding.
Hourly Forecast: Fetch and display hourly or weekly weather forecasts.
Conclusion
This guide demonstrated how to integrate Tailwind CSS with Aurelia 2 using Vite, enabling a responsive, modern, and styled weather dashboard. With real-time weather data from OpenWeatherMap, this project highlights Aurelia’s data-binding and service integration capabilities.
For more details on Tailwind CSS, refer to the official documentation.
Last updated
Was this helpful?