grunt-requirejs-templates
A plugin to insert the content of template files like underscore, handlebars to variables into the javascript code
Getting Started
This plugin requires Grunt ~0.4.2
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-requirejs-templates --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt;
What it does
Supposing that you have your template files in a separated folder and loads them with Require.js like this:
;
The grunt-requirejs gets the content of the template file and put it into a string to prevent your application to make a XMLHttpRequest to load it:
;
Supported template engines
Today grunt-requirejs-templates supports this template engines:
Help us to write tests and support another template engines!
The "requirejs_templates" task
Overview
In your project's Gruntfile, add a section named requirejs_templates
to the data object passed into grunt.initConfig()
.
grunt;
Options
options.appDir
Type: String
Default value: '.'
Path to your application
options.scripts
Type: String
Default value: 'scripts'
Path to your javascript files
options.templates
Type: String
Default value: 'templates'
options.output
Type: String
Default value: null
Path to your create the script files after processing, the default value will output to the source folder.
Usage Examples
;
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.