This Blog Is Now A Monorepo
This blog consists of two parts: A static blog (powered by Eleventy) and a small API that powers the favs and the guestbook. They always lived in two different repositories, which made developing and testing things together a little awkward, but not anymore! Everything is now united in one repository.
This enables me also to move things (e.g. into a more traditional vps kind-of situation) much more easily, if I ever chose to do so.
Some quick notes on how this works in the context of the Cloudflare Dev Platform:
- both the blog and the api now live - more or less as they were - as subfolders under
apps
(e.g.apps/blog
andapps/blog-api
) - the Cloudflare pages project that builds this blog on push was reconfigured[1]:
- Root directory:
apps/blog
- Build watch paths
- Include paths:
apps/blog/*
- Include paths:
- Rest as before/default
- only noteworthy configurations
- an R2 Bucket was bound to serve images
- build cache is activated
- I use pnpm instead of npm to build this site, so
NODE_VERSION
andPNPM_VERSION
env vars are set and the build command ispnpx @11ty/eleventy
- only noteworthy configurations
- Root directory:
- since the blog-api workers project was always deployed manually using wrangler, I will just have to do this now using the new repo
To help facilitate building/developing/deploying from this new repo, I have the following package.json in the repo root:
{
"name": "blog-monorepo",
"private": true,
"version": "0.1.0",
"type": "module",
"packageManager": "pnpm@10.15.0+sha512.486ebc259d3e999a4e8691ce03b5cac4a71cbeca39372a9b762cb500cfdf0873e2cb16abe3d951b1ee2cf012503f027b98b6584e4df22524e0c7450d9ec7aa7b",
"workspaces": [
"apps/*"
],
"scripts": {
"dev": "pnpx concurrently -k \"pnpm --dir apps/blog start\" \"pnpm --dir apps/blog wrangler:proxy\" \"pnpm --dir apps/cloudflare-blog-api dev\"",
"dev:api": "pnpm --dir apps/cloudflare-blog-api dev",
"dev:blog": "pnpm --dir apps/blog start",
"build": "pnpm --dir apps/blog build && pnpm --dir apps/cloudflare-blog-api check",
"build:blog": "pnpm --dir apps/blog build",
"build:api": "pnpm --dir apps/cloudflare-blog-api check",
"deploy:api": "pnpm --dir apps/cloudflare-blog-api deploy",
"test": "pnpm --dir apps/cloudflare-blog-api test",
"types:api": "pnpm --dir apps/cloudflare-blog-api types",
"format": "prettier . --check ./.prettierignore",
"format:write": "prettier . --write ./.prettierignore",
"prepare": "husky",
"lint": "eslint apps/cloudflare-blog-api apps/blog",
"lint:fix": "eslint apps/cloudflare-blog-api apps/blog --fix",
"lint:api": "eslint apps/cloudflare-blog-api",
"lint:blog": "eslint apps/blog"
},
"devDependencies": {
"@eslint/js": "^9.22.0",
"eslint": "^9.22.0",
"eslint-config-prettier": "^10.1.1",
"globals": "^16.0.0",
"husky": "^9.1.7",
"prettier": "3.5.3",
"typescript-eslint": "^8.26.0"
}
}
Developing things for my blog - including the interactive parts - is now just a question of doing pnpm dev
in the repo root. Deployment of the blog happens on push - as before - and deploying the API is a simple pnpm deploy:api
.
P.S.: Moving away from Cloudflare will mean to not rely anymore on wrangler and its local development features (as well as cloudflare's dev platform with its KV store, database and object storage as regards to actually deploying this thing, of course). Looking at the tools I'm comfortable with, this would probably mean moving to a docker based workflow. But I'll cross that bridge when I come to it.
P.P.S.: Calling this a monorepo feels almost like stolen monorepo valor, since it's only two projects that don't even share any dependencies. I hope big monorepo will understand.
P.P.P.S.: Cloudflare offers more complex monorepo features for pages and workers projects.
actually, I created a new one, because the monorepo is technically a new repo ↩︎
-
← Previous
DailyDogo 1372 🐶 -
Next →
DailyDogo 1373 🐶