Node.js ngHtml2Js从结果中删除多个模块运行定义

Node.js ngHtml2Js从结果中删除多个模块运行定义,node.js,gulp,ng-html2js,Node.js,Gulp,Ng Html2js,我有以下任务: gulp.task('html', function () { // Compile templates return gulp.src(templateFiles) .pipe(htmlmin({ removeComments: true, collapseWhitespace: true, conservativeCollapse: true, re

我有以下任务:

gulp.task('html', function () {
    // Compile templates
    return gulp.src(templateFiles)
        .pipe(htmlmin({
            removeComments: true,
            collapseWhitespace: true,
            conservativeCollapse: true,
            removeScriptTypeAttributes: true
        }))
        .pipe(ngHtml2Js({
            moduleName: 'my.tpls',
            prefix: 'tpl/'
        }))
        .pipe(concat(libName + '.tpls.js'))
        .pipe(gulp.dest(destDirectory));
});
在一个文件中生成多个代码块,类似于:

(function(module) {
try {
  module = angular.module('my.tpls');
} catch (e) {
  module = angular.module('my.tpls', []);
}
module.run(['$templateCache', function($templateCache) {
  $templateCache.put('tpl/my/templates/template1.html',
    '<some-html></<some-html>');
}]);
})();

(function(module) {
try {
  module = angular.module('my.tpls');
} catch (e) {
  module = angular.module('my.tpls', []);
}
module.run(['$templateCache', function($templateCache) {
  $templateCache.put('tpl/my/templates/template2.html',
    '<some-html></<some-html>');
}]);
})();
这似乎效率很低,并且设置了大量不需要的额外字节供下载

有没有办法调整“吞咽”任务以使结果更像:

(function(module) {
try {
  module = angular.module('my.tpls');
} catch (e) {
  module = angular.module('my.tpls', []);
}
module.run(['$templateCache', function($templateCache) {
  $templateCache.put('tpl/my/templates/template1.html',
    '<some-html></<some-html>');
  $templateCache.put('tpl/my/templates/template2.html',
    '<some-html></<some-html>');
}]);
})();

澄清;我要找的是相当于,但是一口。我已经准备好在ngHtml2Js的gulp任务选项中添加singleModule:true。不起作用。

我通过覆盖标准的ngHtml2Js模板来完成,然后使用gulp tap修改文件。工作起来很有魅力-

gulp.task('html', function () {
    // Compile templates
    return gulp.src(templateFiles)
        .pipe(htmlmin({
            removeComments: true,
            collapseWhitespace: true,
            conservativeCollapse: true,
            removeScriptTypeAttributes: true
        }))
        .pipe(ngHtml2Js({
            template: "    $templateCache.put('<%= template.url %>',\n        '<%= template.prettyEscapedContent %>');",
            prefix: 'tpl/'
        }))
        .pipe(concat(libName + '.tpls.js'))
        .pipe(tap(function(file, t) {
            file.contents = Buffer.concat([
                new Buffer("(function(module) {\n" +
                "try {\n" +
                "  module = angular.module('my.tpls');\n" +
                "} catch (e) {\n" +
                "  module = angular.module('my.tpls', []);\n" +
                "}\n" +
                "module.run(['$templateCache', function($templateCache) {\n"),
                file.contents,
                new Buffer("\n}]);\n" +
                "})();\n")
            ]);
        }))
        .pipe(gulp.dest(destDirectory));
});