Reputation: 315
I html file like this:
...
<!-- build:js build/js/vendor.js -->
<script src="dep/angular/angular.js"></script>
<!-- endbuild -->
Build file like this:
<script src="build/js/vendor.xxxxxxxx.js"></script>
Now I use gulp-angular-templatecache
package all the view files, generate a template.js, I would like to add this document to the compiled html file inside, how to do it?
I found the gulp-useref
document in the additionalStreams
settings options, but I used to find what is not want to achieve the function.
Upvotes: 1
Views: 305
Reputation: 315
I solved it in another way.
Write on the page first:
<!-- build:templates --><!-- endbuild -->
Before packing with gulp-replace
replaced with like this:
<!-- build:js build/js/templates.js -->
<script src="build/js/templates.js"></script>
<!-- endbuild -->
Finally unify compilation.
Code:
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'));
Upvotes: 1