As my website grew, I noticed I started using more and more environment conditionals, like checking whether the site is built for development or production (based on the value of the NODE_ENV environment variable). It’s not a code smell per se, and there are certainly many reasons to do so: Rendering draft posts (development only). Initializing the service worker (production only). Generating Markdown alternates for LLMs (production only). Inlining or minifying resources (production only). Optimizing watch performance (development only). Ultimately, I realised I wanted proper feature toggles. Let’s see how to set them up in Eleventy. In a nutshell If you do not use TypeScript in your Eleventy project (more on the TS approach below), and author everything in JavaScript, then the simplest approach is to have an object in a JavaScript file somewhere (or even in your .eleventy.js file): const PRODUCTION = process.env.NODE_ENV === 'production' export const FEATURES = { renderDrafts:…
No comments yet. Log in to reply on the Fediverse. Comments will appear here.