mardi 28 octobre 2014

Rapid development using Handlebars


Vote count:

0




So, we are implementing Handlebars.js into our project, where the goal is to create a more JS-heavy web application.


Pretty much a simple setup where we fetch JSON data from our servers using AJAX and we run the Handlebars templates to put our objects into the DOM and whatnot. We are using RequireJS to structure and load our code.


During development we let RequireJS load each JS file/module asynchronously. When it is time for QA and Production environments we use r.js to optimize the Javascript into minified, cacheable files.


We would like to do the same for our Handlebars templates. I.e. compile them on the fly in our development environment, then optimize them for QA and Prod.


When writing JS that uses Handlebars, one can use Handlebars.compile(). However, when the files are optimized, they wont be able to be compiled anymore. Also, in QA and Production we will be using the runtime version of Handlebars, meaning that it won't be possible (or necessary) to compile any templates.


How can we handle the differences between the environments in our code? We want a smooth transition where we don't have to edit any templates to make it work between environments. Possibly let the scripts that build to QA/Prod handle things.


The goal is pretty much to be able to write code without having to recompile anything while developing.


Does anyone have an example setup using Handlebars, RequireJS and templates saved as AMD modules?


(We have considered using e.g. Grunt to watch the files and recompile them on the fly. But it feels like overkill if this is the only scenario we will use it for now. At least if there is an alternative along the above lines.)


We are using Python3 and Django, and have loaded some Node modules as utilities (i.e. r.js).



asked 55 secs ago

Skurpi

352






Rapid development using Handlebars

Aucun commentaire:

Enregistrer un commentaire