我想将模板添加为JS缓存,就像您使用use-min添加JS一样。问题是use-min不允许在use-min步骤中添加任意内容。
html:
<!-- build:jslib assets/js/lib.js -->
<script src="bower_components/bower-stuff/some.js"></script>
<!-- endbuild -->
<!-- build:js assets/js/app.js -->
<script src="assets/app/main.js"></script>
<script src="assets/app/config.js"></script>
<script src="assets/app/routes.js"></script>
<!-- endbuild -->
<!-- build:templateCache assets/js/templateCache.js -->
<script src="assets/app/templateCachePlaceholder.js"></script>
<!-- endbuild -->
</body>
</html>
*(使用占位符的原因是use-min似乎读取输入文件而不是输出文件来确定类型)
gulp任务:
gulp.task('build', ['bower', 'compass'], function () {
return gulp.src(
[
'frontend-src/index.html',
'frontend-src/config/**/*',
'frontend-src/assets/img/**/*',
'frontend-src/assets/fonts/**/*',
'frontend-src/assets/translations/*'
],
{base: 'frontend-src/'})
.pipe(plugins.if(isIndexHtml, plugins.usemin({
js: [plugins.ngAnnotate(), plugins.uglify(), plugins.rev()],
jslib: [plugins.rev()],
css: [plugins.minifyCss(), 'concat', plugins.rev()],
templateCache: [
plugins.addSrc('frontend-src/assets/app/**/*.html'),
plugins.angularTemplatecache({
module: ANGULARJS_MODULE_NAME,
root: 'assets/app/'
}),
'concat',
plugins.rev()
]
})))
.pipe(gulp.dest('frontend-prod/'));
function isIndexHtml (file) {
return file.path.match('index\.html$');
}
});