How to use the template function from handlebars

Find comprehensive JavaScript handlebars.template code examples handpicked from public code repositorys.

25
26
27
28
29
30
31
32
33
34
const code = fs.readFileSync(filename, "utf8");
const pc = hb.precompile(code, {preventIndent: true, srcName: filename});
const node = new SourceNode();
node.add([
    'const Handlebars = require("handlebars/runtime");\n',
    "module.exports = Handlebars.template(",
    SourceNode.fromStringWithSourceMap(pc.code, new SourceMapConsumer(pc.map)),
    ");\n",
]);
const out = node.toStringWithSourceMap();
fork icon0
star icon0
watch icon0

+ 4 other calls in file

6
7
8
9
10
11
12
13
14
15
  const precompiled = Handlebars.precompile(content);
  asset.setCode(`
  import Handlebars from 'handlebars';
  import { registerHelpers } from "@hbs-helpers";
  registerHelpers(Handlebars);   
  const templateFunction = Handlebars.template(${precompiled});
  export default templateFunction`);
  asset.type = "js";
  return [asset];
},
fork icon0
star icon0
watch icon0

+ 2 other calls in file