First steps with Astro

What is Astro ?

In the ever-evolving landscape of web development, new technologies emerge to streamline the process and enhance the developer experience.

One such groundbreaking technology is Astro, a modern JavaScript framework designed to optimize web performance and improve the overall development workflow for front-end focused websites. That’s why i used it for my personal website (The one you’re reading). To be more precise, Astro is a static site generator (SSG).

Here’s the link to the tool: https://astro.build

Astro


What is a Static Site Generator ?

A static site generator (SSG) is a tool that helps developers build static websites. Unlike dynamic websites, where content is generated on-the-fly by a server in response to user requests, static websites consist of pre-built HTML, CSS, and JavaScript files. The content on static sites remains the same until manually updated or regenerated.

Here’s how a static site generator typically works:

Popular static site generators include Jekyll, Hugo, Gatsby, and Next.js. These tools have gained popularity due to their simplicity, speed, and ease of deployment. They are often used for blogs, documentation sites, and other content-focused websites. Astro is one of them.

Pros and Cons for me

After a bit of discovering, i feel there’s a bunch of pros and cons i can share here, for my usecase.

Pros

Cons

If you want to see what can be made with Astro, here are examples of themes of the official website. As i wanted something “straight-forward”, for my website, i use one of their themes, they’re really good.

How to

Prerequisites

Node.js and npm: Ensure that you have Node.js and npm (Node Package Manager) installed on your machine. You can download them from nodejs.org.

Steps to Create an Astro Project:

Install Astro:

Open a terminal or command prompt and run the following command to install Astro globally on your machine:

npm install -g create-astro

Create a New Astro Project:

Run the following command to create a new Astro project. Replace my-astro-project with the desired name of your project: Here, you’ll be able to choose between multiple options for your project, such as Typescript support and more.

create-astro my-astro-project

Change into the newly created project directory:

cd my-astro-project

Install Dependencies

Install project dependencies using npm:

npm install

Start the Development Server:

Start the Astro development server to preview your project locally. This will also watch for changes in your code and update the preview in real-time !

npm run astro dev

The development server will provide you with a local URL (default is http://localhost:4321). Open this URL in your web browser to see your Astro project in action. In this page, you’ll find a little toolbar at the bottom of the page which can be useful in development phase, with a little button for accessibility check.

Explore the Project Structure:

Astro projects have a simple structure. Key files and directories include:

Build for Production:

When you’re ready to deploy your project, you can build it using the following command:

npm run build

This command generates the static files in the dist/ directory, which you can then deploy to your hosting provider of choice.

Additional Resources

Astro Documentation: The official documentation is an excellent resource for understanding and exploring the features of Astro.

With these steps, you should have a basic Astro project up and running. From here, you can explore advanced features, integrate with other libraries, and build powerful web applications with enhanced performance.

🌵 ThomasFAVRE

© 2024 Thomas Favre