Server Side Rendering of templates Cloudflare Pages without ‘node:fs’

Hi guys, I am trying to get a templating setup, using Mustache. Mustache however to render files on the server side requires the use of node:fs core module. Workers, however, is limited in what node modules it can support, according to - https://github.com/cloudflare/workers-sdk/issues/3430#issuecomment-1589351536. So Mustache templates cannot be read on the server side using node:fs Here is my problem, I want to have several HTML templates & partials, in many separate files that I want to render on the server side (using workers). Then send it to the front end. So, two questions. a) Is there a workaround/hack allowing me to use Mustache for server-side rendering template files? b) Can an alternative library/stack or technique help me achieve my goal?
3 Replies
papertokyo
papertokyo10mo ago
I'm also exploring template engines in Workers. It seems all of them except Liquid require using a bundler to precompile the templates into JS modules. https://liquidjs.com/index.html
LiquidJS
LiquidJS is a simple, expressive and safe Shopify / Github Pages compatible template engine in pure JavaScript.
Adi
Adi10mo ago
I personally wouldn't say this is a good alternative, but you can make the string contents of files available via wrangler bundling. See - https://developers.cloudflare.com/workers/wrangler/bundling/#files-which-will-not-be-bundled
Cloudflare Docs
Bundling · Cloudflare Workers docs
Review Wrangler's default bundling.
Adi
Adi10mo ago
It sounds like you are trying to make a website however? Since you asked for other tech stack suggestions, you can use any of the modern metaframeworks for React/Vue/Svelte etc and run your website using Cloudflare pages. I personally use Remix. But honestly you could use anything. If you give more details about your project I might be able to recommend something.
Want results from more Discord servers?
Add your server