Import mustache templates in Function

Hi everyone! I'm relatively new in Pages/Functions. I'm trying to import some mustache templates in my Function like so:

import Mustache from 'mustache';

import view from '../app/views/main.mustache';
import home from '../app/pages/home.mustache';

export function onRequest(): Response {
const html = Mustache.render(view, { }, { page: home } );

return new Response(html, {
headers: {
'content-type': 'text/html;charset=UTF-8',
},
});
}

import Mustache from 'mustache';

import view from '../app/views/main.mustache';
import home from '../app/pages/home.mustache';

export function onRequest(): Response {
const html = Mustache.render(view, { }, { page: home } );

return new Response(html, {
headers: {
'content-type': 'text/html;charset=UTF-8',
},
});
}
From what it's my current understanding, it should be possible to include a mustache template as a Text asset by setting a proper bundling rule in wrangler.toml like so:
rules = [
{ type = "Text", globs = ["**/*.mustache"], fallthrough = true }
rules = [
{ type = "Text", globs = ["**/*.mustache"], fallthrough = true }
Anyway, when I run
wrangler pages dev public
wrangler pages dev public
I get the error "No loader is configured for ".mustache" files". Any ideas? Thank you in advance!
GitHub
GitHub - janl/mustache.js: Minimal templating with {{mustaches}} in...
Minimal templating with {{mustaches}} in JavaScript - janl/mustache.js
Cloudflare Docs
Configuration | Cloudflare Workers docs
Use a wrangler.toml configuration file to customize the development and deployment setup for your Worker project and other Developer Platform products.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server