How do I precompile partials for handlebars.js?

后端 未结 7 1334
心在旅途
心在旅途 2021-02-01 03:10

I\'m using handlebars.js and I want to start precompiling everything, but I can\'t seem to find a way to precompile the partials. The majority of my templates are actually parti

7条回答
  •  我在风中等你
    2021-02-01 03:53

    Instead of replacing all the registered partials I recommend instead explicitly adding the partials, possibly filtering them as well such as:

    Object.entries(Handlebars.templates).forEach(([k, v]) => { if ( k.indexOf('partial') != -1 ) Handlebars.partials[k] = v })
    

    In this case we only insert precompiled templates that contain "partial" in the name. This would allow you to either store these in a partials/ subfolder or within the name such as some-partial.hbs

提交回复
热议问题