The worlds tiniest rewrite from CJS to ESM
My favourite way of using Eleventy is using as little of it as possible. The starter projects are all too elaborate for my taste. I have my own: github.com/elisabethirgens/tiny11ty and it was set up two years ago, when @11ty/eleventy
used Common JS.
Historically, Eleventy (prior to version 3) has worked with the Node.js default flavor of JavaScript modules: CommonJS. However, ESM (ECMAScript Modules) are a newer JavaScript standard that will work in more JavaScript environments and runtimes.
โย www.11ty.dev/docs/cjs-esm/
I havenโt done any rewrites to ESM before, so I was hesitant. How much would I need to change? Well, it seems that I have now done the tiniest rewrite from CJS to ESM in the history of rewrites.
The entire thing in this commit has +3 -2 lines changed
๐
// First lines of eleventy.config.js before
const { DateTime } = require("luxon");
module.exports = (eleventyConfig) => {
// ...
// First lines of eleventy.config.js after
import { DateTime } from "luxon";
export default (eleventyConfig) => {
// ...
VS Code fixed that for me ๐ and in addition I needed to add "type": "module"
to my package.json
which I had forgotten but was reminded of when npm install
failed. And that was that! I have rewritten my first project from CJS to ESM.
Maintenance of tiny11ty
I remember it taking some work to figure out how to remove a lot of stuff from my set up of Eleventy, but it really turned out quite minimal. Now it is fun to see what a managable amount of work is needed to be done to keep this project updated. The build broke on a different project with the same set up, and that was due to outdated versions of actions in the GitHub workflow. So the first change was necessary, but the other three were more optional.
- Update GitHub workflow actions commit
- Update @11ty/eleventy to v3 commit
- Tiny rewrite from CommonJS to ESM commit
- Refactor from Nunjucks templating to use Liquid commit
Nunjucks is the templating I choose originally, but I get the impression that Mozilla is no longer maintaining that project? It still works just fine, but I wanted to try using Liquid. It will be fun to follow how much or little maintenance this project will need in upcoming years!