@wangxingkang
2017-06-14T15:45:19.000000Z
字数 1946
阅读 1759
gulp
目录:
项目地址:gulp-angular-templatecache
在$templateCache中连接并注册AngularJS模板。
npm i -D gulp-angular-templatecache
yarn add -D gulp-angular-templatecache
gulpfile.js
连接目录所有的.html模板保存到 public/templates.js(默认的文件名字)
var templateCache = require('gulp-angular-templatecache');
gulp.task('default', function() {
return gulp.src('templates/**/*.html')
.pipe(templateCache())
.pipe(gulp.dest('public'))
})
结果(public/templates.js)
angular.module('templates').run([$templateCache,
function($templateCache) {
$templateCache.put('template1.html',
// template1.html content (escaped)
);
$templateCache.put('template2.html',
// template2.html content (escaped)
);
// etc.
};
])
gulp-angular-templatecache(filename, options)
名字在连接时使用
模板的url前缀
angular模块的名字
创建一个新的AngularJS模块,而不是使用现有的。
覆盖文件基本路径
包装templateCache模块系统,目前支持系统:RequireJS、Browserify ES6和IIFE
在放入$templateCache之前转换生成的URL
transformUrl: function(url) {
return url.replace(/\.tpl\.html$/, '.html')
}
覆盖模板头部
var TEMPLATE_HEADER = 'angular.module("<%= module %>"<%= standalone %>).run(["$templateCache", function($templateCache) {';
覆盖模板主要部分
var TEMPLATE_BODY = '$templateCache.put("<%= url %>","<%= contents %>");';
覆盖模板页脚
var TEMPLATE_FOOTER = '}])';