【发布时间】:2015-10-06 03:39:13
【问题描述】:
我正在使用 gulp-angular-templatecache 生成一个 templateCache.js 文件,它将我所有的 HTML 模板文件合并为 1. (my full gulpfile)
将新模块注入我的应用程序后,我的指令将自动获取模板,我不需要将部分 .html 文件添加到我的构建文件夹中。
问题是前导文件夹路径被切断,请参见下面的示例:
我的指令中的路径:
templateUrl : "panels/tags/tagsPanel.html"...
templateUrl : "header/platform_header/platformHeader.html"...
我生成的templateCache文件中的路径:
$templateCache.put("tags/tagsPanel.html"...
$templateCache.put("platform_header/platformHeader.html"...
^ panels 和 header 迷路了。
我正在尝试编写一个函数来修复我的 Gulpfile 中的问题。
我的Gulpfile的配置部分:
var config = {
srcPartials:[
'app/beta/*.html',
'app/header/**/*.html',
'app/help/*.html',
'app/login/*.html',
'app/notificaitons/*.html',
'app/panels/**/*.html',
'app/popovers/**/*.html',
'app/popovers/*.html',
'app/user/*.html',
'app/dashboard.html'
],
srcPaths:[
'beta/',
'header/',
'help/',
'login/',
'notificaitons/',
'panels/',
'popovers/',
'popovers/',
'user/',
'dashboard.html'
],
destPartials: 'app/templates/'
};
我的html-templatesgulp.task
gulp.task('html-templates', function() {
return gulp.src(config.srcPartials)
.pipe(templateCache('templateCache.js', {
root: updateRoot(config.srcPaths)
},
{ module:'templateCache', standalone:true })
).pipe(gulp.dest(config.destPartials));
});
function updateRoot(paths) {
for (var i = 0; i < paths.length; i++) {
// console.log(paths);
console.log(paths[i]);
return paths[i];
}
}
^ 以上是有效的,因为它使用gulp-angular-templatecache 中的root option 在模板路径前面附加一个新字符串。
问题是我上面的代码返回一次并更新所有路径到路径数组中的第一项,即beta/。
您将如何编写它以正确替换每个文件的路径?
【问题讨论】:
标签: javascript angularjs gulp angular-templatecache