Gruntjs: grunt-contrib-jst

预编译Underscore模板到JST文件(Underscore:JS工具库)

generate JavaScript template functions

Gruntfile的配置实例:

 1 module.exports = function(grunt) {
 2 
 3     grunt.initConfig({
 4         jst: {
 5             bulid: {
 6                 files: [{
 7                     expand: true,                   // 开启构建动态文件对象
 8                     cwd: 'static/tpl/',             // 模板目录(源文件)
 9                     src: ['**/*.html'],             // 能匹配到模板的二级目录
10                     dest: 'static/build/',          // 目标文件目录
11                     ext: '.js'                      // 目标文件的后缀名
12                 }]
13             },
14             options: {                              // jst插件的一些配置
15                 amd: true,                          // define()的方法包裹生成的内容
16                 namespace: false,                   // 直接返回模板函数(等价于_.template(tmpl))
17                 prettify: true                      // 生成的内容在一行
18             }
19         },
20         watch: {
21             files: ['static/tpl/**/*.html'],
22             tasks: ['newer:jst:bulid']
23         }
24     });
25 
26     grunt.loadNpmTasks('grunt-contrib-jst');
27     grunt.loadNpmTasks('grunt-contrib-watch');
28     grunt.loadNpmTasks('grunt-newer');
29 }

参考:

http://www.gruntjs.org/article/configuring_tasks.html

https://github.com/gruntjs/grunt-contrib-jst

https://github.com/gruntjs/grunt-contrib-watch

原文地址:https://www.cnblogs.com/mackxu/p/gruntjs-jst.html