grunt-mustache-precompile v0.1.1
grunt-mustache-precompile
Precompiles Mustache templates and optionally creates AMD modules.
Getting Started
This plugin requires Grunt ~0.4.1
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-mustache-precompile --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-mustache-precompile');
The "mustache_precompile" task
Overview
In your project's Gruntfile, add a section named mustache_precompile
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
mustache_precompile: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
})
Options
options.AMD
Type: boolean
Default value: false
Whether to wrap the output file as an AMD module.
options.namespace
Type: String
Default value: TEMPLATES
A string value that determines the name of the object that will contain all your templates.
Usage Examples
Default Options
In this example, the default options simply trigger a compile and concatenation. This outputs the mustache functions into an object of name TEMPLATES. The result will be an object whose members you can call with TEMPLATES.main({/templateArgumentsHere/});
grunt.initConfig({
mustache_precompile: {
options: {},
files: {
'dest/default.templates.js': ['templates/main.mustache', 'templates/widget.mustache'],
},
},
})
Custom Options
In this example, the custom options specify that the templates should be exposed as an AMD module. To use you can simply require that package and use it as a collection of functions to yield your templates.
require(['custom.templates'], function(templates) {
document.body.innerHTML = templates.main({/* template data here */});
}
```js
grunt.initConfig({
mustache_precompile: {
options: {
AMD: true,
},
files: {
'dest/custom.templates.js': ['templates/main.mustache', 'templates/widget.mustache'],
},
},
})
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Release History
(Nothing yet)