GiS#91
GiS#91
CDCloudflare Developers
Created by GiS#91 on 8/31/2024 in #pages-help
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!
1 replies