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:
import handlebars from "handlebars";
import runtime from "./node_modules/handlebars/dist/handlebars.runtime.js";
await write_to_path("./precompiled.js", `export default ${handlebars.precompile("{{foo}}")}`);
import precompiled from "./precompiled.js";
console.log(runtime.template(precompiled)({foo: "bar"}));
// -> bar
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,
import {default as handlebars, runtime} from "handlebars";
await write_to_path("./precompiled.js", `export default ${handlebars.precompile("{{foo}}")}`);
import precompiled from "./precompiled.js";
console.log(runtime.template(precompiled)({foo: "bar"}));
// -> bar
Referencing #955, which seems to suggest a similar way, but does not specify how to get the runtime on the server.
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_modulesdirectory? Perhaps something like,Referencing #955, which seems to suggest a similar way, but does not specify how to get the runtime on the server.