Replies: 3 comments 3 replies
-
You can't import both runtime and the full version in one import statement, but you can do this: import handlebars from "handlebars";
import runtime from "handlebars/runtime"; |
Beta Was this translation helpful? Give feedback.
-
any update? @jaylinski |
Beta Was this translation helpful? Give feedback.
-
I have been trying to do something similar with AWS SAM using the lambda layer build step to precompile the .hbs files into templates used in the lambda endpoints. I am using ES6 style modules. This may be a bit of a hacky solution. I use a custom makefile in the build step to run Since lambda runs in a container, you also need to do Modifying
Finally, we can add an export after the IIFE to export the Handlebars instance which has the precompiled templates loaded:
Then, at runtime / on your backend you can do Pre-compiled templates are then accessible at hbs.templates['template_name']. Hopefully this is helpful! Took me a good amount of experimenting to figure this out. |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm trying to precompile a template at build time and then render it at runtime (the data could be different every time) on the server.
I'm currently using this code:
This works perfectly for me, I was wondering if it were possible to expose the runtime per a package.json export, to avoid me reaching directly into the
node_modules
directory? Perhaps something like,Referencing #955, which seems to suggest a similar way, but does not specify how to get the runtime on the server.
Beta Was this translation helpful? Give feedback.
All reactions