Getting Started with Eleventy

· Ga Satrya · Eleventy
Decoration

Static site generators have become increasingly popular in recent years, and for good reason. They allow developers to build fast and secure websites without the need for a backend. One such static site generator that has gained a lot of traction is Eleventy. In this blog post, we will take a look at what Eleventy is, how to set it up, and how to build your first website with it.

What is Eleventy?

Eleventy is a static site generator that is built on Node.js. It is flexible, easy to use, and highly configurable. It supports a wide range of template languages, including Liquid, Nunjucks, Handlebars, and Mustache. Not only that, but it also has a built-in development server, which makes it easy to see your changes in real-time.

Setting up Eleventy

To get started with Eleventy, you will need to have Node.js and NPM (Node Package Manager) installed on your computer. You can download them from the official website. Once you have Node.js and NPM installed, you can create a new project by running the following command in your terminal:

npm init

This will create a new package.json file in your project directory. Next, you will need to install Eleventy by running the following command:

npm install --save-dev @11ty/eleventy

Building Your First Eleventy Website

Now that you have Eleventy set up, it's time to start building your first website. You can use any template language you prefer, but for this example, we will use Nunjucks.

First, create a new directory called src in your project directory. This is where you will put all of your source files. Next, create a new file called index.njk in the src directory. This will be the main template for your website.

In your index.njk file, you can add the following code:

<!DOCTYPE html> 
<html> 
    <head>
        <title>Eleventy Website</title>
    </head> 
    <body> 
        <h1>Hello, Eleventy!</h1>
    </body>
</html>

This is a basic HTML template that displays the text "Hello, Eleventy!".

To build your website, you will need to create a new file called .eleventy.js or eleventy.config.js in your project directory. This is the configuration file for Eleventy. In this file, you can add the following code:

module.exports = function(eleventyConfig) {                      
    return { 
        dir: { 
            input: "src", 
            output: "dist" 
        } 
    }; 
};

This code tells Eleventy where to find your source files src and where to output the built website dist.

Finally, you can run the following command to build your website:

npx eleventy

This will take all of the files in the src directory and build them into the dist

Conclusion

In conclusion, Eleventy is a powerful and flexible static site generator that is easy to set up and use. It supports a wide range of template languages and has a built-in development server, making it a great choice for building fast and secure websites. With the step-by-step guide provided in this blog post, you should now be able to set up Eleventy and build your first website with it. Happy coding!🥳


I hope you enjoyed reading it and learned something. You can also connect with me on Twitter.

Website Design Services

Custom website design and development solutions to help your business grow!

Website Package

Website Package

The all-in-one website design services to support your business growth. Includes brand identity, website design & development, and copywriting.

Get The Website Package
Website Design & Dev

Website Design & Dev

Get personalized website design & development that are user-friendly, conversion-focused, and visually appealing.

See Services Pricing
Website Maintenance

Website Maintenance

Keep your website running smoothly with regular updates, bug fixes, security checks, and content management for a hassle-free website.

Get hassle-free website