我有以下吞咽任务:
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>');
}]);
})();
这似乎非常低效,并设置了许多不需要的额外字节来下载。
有没有办法调整 gulp 任务以使结果更像:
(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>');
}]);
})();
澄清; 我正在寻找的是grunt-html2js singleModule option的等价物,但对于 Gulp。我已经尝试singleModule: true
为 ngHtml2Js 添加我的 gulp 任务选项。没用。