I would like to precompile Handlebars templates, but I'm not sure how this works in design mode.
Is there a background process in common practice, for example, Guard, for constantly monitoring changes to Handlebars template files?
I use RequireJS to create templates; eg:.
define(['jquery', 'handlebars', 'text!templates/my_template'], function($, Handlebars, myTemplate) { // ... var data = {"some": "data", "some_more": "data"}; var templateFn = Handlebars.compile(myTemplate); $('#target').append(templateFn(data)); // ... });
So, I understand that when the templates are precompiled, you can do the following:
define(['jquery', 'handlebars'], function($, Handlebars) { // ... var data = {"some": "data", "some_more": "data"}; var template = Handlebars.templates['my_template']; $('#target').append(template(data)); // ... });
Notice the following in the second code snippet:
- The RequireJS module no longer draws a template.
- Handlebars.compile () is no longer used.
As a rule, I have a Guard so that my templates are compiled whenever there are file changes at the file level with the template files?
Mostly my question is , the intention of the developers to do this?
if (development) { compile templates } else { use precompiled templates }
I also use Rails, so there may be black magic like sass-rails.
Chad johnson
source share