Get your Eleventy Site into the real world (Netlify, Cloudflare pages or any host)
By Mike Street
Eleventy (11ty) is a great entry point for getting a markdown or JSON content from files to a website. There are plenty of tutorials out in the world to get 11ty up and running in a development environment.
But once you are ready to get your website out into the public domain, what are the options and how do you go about it? There are a couple of free options (with paid extras), as well as self-hosting if that is your JAM (geddit? Because 11ty is JAMstack... No? I'll move on...)
There were 3 main contenders when I planned this post a few weeks ago, however a new arrival (Cloudflare pages) gives an extra bit of variance. For ease of access with low barriers of entry, I would recommend:
This is the most manual of the options, but gives you the most control over your website. It is also the only one that requires a domain name of sorts to access the final result (the other options give you a placeholder/branded domain name).
With 11ty, you can either generate the site in a one-off, or run a watcher, which recompiles on save.
When self-hosting, you should run the "compile" step of Eleventy and manually move the source files to your designated hosting.
npx @11ty/eleventy --serve
This will compile your site into your
output dir as specified in your
.eleventy.js. You can transfer this directory to your hosting environment, be it via FTP, SCP/RSYNC or you can zip it up to transfer it.
The other option is to
git clone or similar your source files and run the compile step on the server you are hosting it on - some shared hosting environments, however, might not let you install npm/node.
Netlify is a fantastic hosting service that provides a fairly straightforward deployment pipeline, as long as you are comfortable with git (although if you're not, they offer alternatives).
To get your 11ty site onto Netlify with git:
- Push your git repository to Github, Gitlab or Bitbucket
- Sign up for a Netlify account
- Click "New site from Git"
- Connect to your git repository host & select the repository
- Choose the branch you want to use for deployment
- Enter the build command and publish directory
- Build command is
- Publish directory is your
outputdirectory specified in your
- Build command is
- Click "deploy site"
Netlify will take a few minutes to deploy your website but, once complete you are provided with a random
.netlify.app URL to view your website. You can rename this or you can link a custom domain (even using Cloudflare).
If you don't want to/can't connect your git provider (or your 11ty site isn't in a git repo), Netlify offer a drag and drop interface (at the bottom of the "Sites" page). Run the 11ty compilation steps locally and upload the output directory.
Gitlab and Github pages are another great way of hosting your website for free. It takes a bit more configuration than Netlify, but if your website data is hosted on one of these services, there might an argument to reduce the number of services required.
I'm not a Github user really, and haven't really investigated using Github pages so I won't attempt to muddle my way through a tutorial. Lea Tortay has written a comprehensive tutorial on this topic.
For Gitlab however, I have just experimented and been able to spin my site up in the space of 15 minutes (pray the lords for 11ty!).
- Ensure your git repository is on gitlab.com (this can be done with self-hosted instances too, but the following steps follow the provided Gitlab instance)
- Add a new file to the root directory called
- Add the following contents
# This folder is cached between builds
- npm install
- Enable CI/CD and Pages on your repository
- Push your changes to Gitlab
CI/CD should fire and compile your pages, you website should then be available at
<username>.gitlab.io/path/to/repo. You can add a custom domain in the Gitlab pages config if that is the route you choose to take.
Cloudflare pages are the new kids on the block and (at time of writing) in beta. Looking like a direct competitor to Netlify, it appeals to me as an avid Cloudflare user to keep everything in one place.
Currently they only support Github (but Gitlab and other things are planned), however the workflow should be very familiar.
- Sign up to Cloudflare and ensure your git repository is on Github
- Connect your Github account and select your repository
- Give it a name and select the branch
- Enter the build command (e.g.
npx @11ty/eleventy) and your output directory
- Click save and deploy
You'll get a
pages.dev domain, but this can be replaced with a custom domain name if desired.
And there we have it. 4 methods for getting your Eleventy site out into the wild. You have no excuse now!