使用grunt将id插入脚本标记

时间:2015-04-15 21:59:11

标签: gruntjs grunt-contrib-watch grunt-contrib-concat

我想将id插入脚本标记

gruntfile.js

var obj = ['id1', 'id2', 'id3'];
var i = 0;

grunt.initConfig({
    concat:{
                    basic:{
                        options:{                               
                            banner:'<script type="text/ng-template" id=' +obj[i] + ' >',
                            separator:'</script><script type="text/ng-template" id=' + obj[i++] + ' >',
                            footer:'</script>'
                        },
                        files:[{
                            src:['./src/folder/*.html'],
                            dest:'./src/foler/index.ftl'
                        }]
                    }
        }
})

但是在文件汇总到index.ftl时的输出中,所有id都具有相同的id ='id3'

如何获得包含所有唯一ID的最终连接文件。

1 个答案:

答案 0 :(得分:0)

以下链接解决了添加ID的问题部分, 我创建了自己的包装插件,并在代码中使用它来动态添加id,

Replace all the text with specified replacement using grunt replace