使用gulp-useref如何添加额外的文件?

我的HTML文件是这样的:

... <!-- build:js build/js/vendor.js --> <script src="dep/angular/angular.js"></script> <!-- endbuild --> 

像这样构build文件:

 <script src="build/js/vendor.xxxxxxxx.js"></script> 

现在我用gulp-angular-templatecache打包所有的视图文件,生成一个template.js,我想将这个文件添加到编译后的html文件里面,怎么做呢?

我在additionalStreams设置选项中find了gulp-useref文件,但是我用来find不想实现的function。

我用另一种方式解决了它。

先写在页面上:

 <!-- build:templates --><!-- endbuild --> 

在包装之前,用下面gulp-replace代替:

 <!-- build:js build/js/templates.js --> <script src="build/js/templates.js"></script> <!-- endbuild --> 

最后统一编译。

码:

 var indexHtmlFilter = $.filter(['**/*', '!**/index_dev.html'], { restore: true }); var fontglyphiconsMatch = /^\.\.\/fonts\/glyphicons/; var fontawesomeMatch = /^\.\.\/fonts\/fontawesome-/; var imgMatch = /^\.\.\/img\//; var matchUrlType = function(url){ if(fontglyphiconsMatch.test(url)) return url.replace(/^\.\./, '/dep/bootstrap-css-only'); if(fontawesomeMatch.test(url)) return url.replace(/^\.\./, '/dep/font-awesome'); if(imgMatch.test(url)) return url.replace(/^\.\./, ''); }; gulp.src('app/index_dev.html') .pipe($.htmlReplace({ templates: ` <!-- build:js build/js/templates.js --> <script src="build/js/templates.js"></script> <!-- endbuild --> ` })) .pipe($.useref()) .pipe($.if('*.js', $.uglify({ output: { ascii_only: true } }))) .pipe($.if('*.css', $.modifyCssUrls({ modify: matchUrlType }))) .pipe($.if('*.css', $.cleanCss())) .pipe(indexHtmlFilter) .pipe($.rev()) .pipe($.revFormat({ prefix: '.' })) .pipe(indexHtmlFilter.restore) .pipe($.revReplace()) .pipe($.if('*.html', $.htmlmin({ collapseWhitespace: true }))) .pipe($.if('index_dev.html', $.rename('index.html'))) .pipe(gulp.dest('./app'));