Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including mustachec with all npm packages installed. Try it out:

var mustachec = require("mustachec")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

mustachec v0.2.1

Compiles Mustache templates in HTML to javascript

Compiles Mustache templates in HTML to javascript.

Compiled templates don't use eval nor Function so they can be used from restricted environments such as Chrome extension apps.


Stable and being used in commercial development.


npm install mustachec



mustachec main.html

compiles each Mustache template within main.html like below (expressed as Jade template)

      a.cancel.close ×
      .modal-title {{title}}

    center {{message}}
    button.cancel.btn Cancel
    button.ok.btn.btn-primary {{confirm}}

into javascript and save them as main-templates.js file like below in the same directory:

window.compiledTemplates = {}
window.compiledTemplates["dialog-template"] = ...;
window.compiledTemplates["confirm-dialog-subtemplate"] = ...;


var context = { title: "foobar" };
var renderedHtml = window.compiledTemplates["dialog-template"].render(context)

Generated code currently expects Hogan.js 2.0 to be loaded.


Use -s or --selector option to override jQuery selector used to identify Mustache template elements in HTML input. Default selector is script[type='text/x-mustache-template'] like this:

mustachec -s ".template" main.html

Use -a or --assign option to specify where to store the compiled templates. Default location is window.compiledTemplates.

mustachec -a "var compiledTemplates" main.html

Use -o or --out option to specify output directory.

mustachec -o ../build main.html
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free