Saturday, 15 September 2012

backbone.js - How to merge multiple html files into one with brunch.js -


I am using underscore.js for my templates, which are many different is stored in XXX_tpl.html files inside such sections:

  & lt; Script type = "text / x-template" id = "tpl_XXX" & gt; & Lt; H1 & gt; Hi & lt; / H1> & Lt; / Script & gt;  

I am using backbone.js scenes inside of this post:

  render: function () {this . $ El.html (. $ ('# Tpl_XXX') text ()); } 
I am now using the brunch.js manufacturing tool which outputs all my Libs / JS / CSS code to many optimized files but I am facing problems managing / templates on my templates. How do I create a brunch.js build tool to add all * _tpl.html files at the end of index.html ? How to use the template to merge the template in brunch.js
to .js files, but I still do not know how it works (The templates are a combination of Html / js and I lose the use of both when compiling the ID and syntax formatting / highlighting in .js files.)

Q1. If I am doing what I am doing right (how many different templates in the various .tpl.html files are added at the end of index.html ) I build.js match all that?

Question 2. If what I'm doing is not right, then what's the best way to do it:

  • There are multiple templates that are organized and easily managed
  • Dragging
  • Want to get syntax highlighting in my IDE for template markup (i.e. no JS string concatenation, etc.)
  • Good question, but I do not know Well understand how templates should work at least fine.

    Template compilation

    An underscore template source is any text containing the interpreted code. For example:

      var myTemplateString = "hello: & lt;% = name% & gt;";  

    When you want to use that template, you have to first compile it in a function? Here's how it works:

      var myTemplateFunction = _.template (myTemplateString);  

    This creates a myTemplateFunction that contains your template logic. On the way with a very simplified, pseudo-code, you can work like myTemplateFunction :

      function (reference) {return "hello:" + reference Name};  

    So, now you understand why you can call this function and create a string!

      myTemplateFunction ({name: 'moe'}) // Hello: Mo  

    use of compiled template

    OK, But why do you need to compile it first? Why does not always call:

      _ Template (myTemplateString) ({name: 'moe'})  

    Because compile CPU may be intense . Therefore, to use a pre-compiled template, it is very fast and you should not force the user's browser to do this! You should do it for him!

    Distributed Template Distributed

    By now, you understand that you do not care about delivering text to your tasks, the client only Compiled template function .

    Brunch has a bunch of plugins for pre-compiled templates, but apparently none for underscores:

    You can use and this is.

    Your code will look something like this:

      var myTemplateFunction = requirement ('./ template.html') console.log (myTemplateFunction);  

    You can also use it and this template underlines:.

    Whatever you choose, they will all work equally: they will compile your template into the function and you will be able to use that function. Personally, I learning webpacks !


No comments:

Post a Comment