A node.js module for precompile JavaScript templates (ex. mustache or jQuery.tmpl) to one file

npm install jsttojs
1 downloads in the last day
25 downloads in the last week
55 downloads in the last month


NPM version

A node.js module for precompile JavaScript templates (ex. mustache or jQuery.tmpl) to one file.

You can to precompile some static mustache, hogan.js, jQuery.tmpl, underscore.js or any other templates and include them in generated javascript function that could be stitched and compressed in a single file.

And if you set the flag --watch, you can compile templates automatically!


$ npm install jsttojs -g


jsttojs allows templates to be precompiled and included in javascript code

Precompile JavaScript templates.
Usage: jsttojs <input> <output> [options]


  -h, --help        output usage information
  -V, --version     output the version number
  -e, --ext <n>     extension for templates, default "jst"
  -n, --name <n>    name variable stores temapltes, default "JSTmpl"
  -w, --watch       watch files and automatic compile output file
  -r, --removebreak remove line breaks
  -a, --amd         wrap templates in AMD module
  -o, --onlyname    use as a key only file name, without directory


  $ jsttojs templates compiled/templates/index.js --ext mustache --watch

Use with grunt

Use it with grunt, install grunt-jsttojs and add this line to your project's Gruntfile:




// tamplates/index.jst
Hello world {{ username }}
second line
// tamplates/video/index.jst
Hello {{ username }} on index video page

Run precompile templates

$ jsttojs templates compiled/templates/index.js --name MyGlobalVariable


// compiled/templates/index.js
window.MyGlobalVariable = {
  "index" : "Hello world {{ username }}\nsecond line",
  "video/index" : "Hello {{ username }} on index video page"


Copyright (c) 2012 Alexey Kupriyanenko a.kupriyanenko@gmail.com

jsttojs is released under the MIT license.

npm loves you