jonkemp / gulp-useref

Parse build blocks in HTML files to replace references to non-optimized scripts or stylesheets.
MIT License
705 stars 93 forks source link

useref not concatenating blocks #195

Closed marioloncarek closed 8 years ago

marioloncarek commented 8 years ago

I have 5 HTML files in my project and every has a useref block in the bottom like this:

<!-- build:js static/js/main.js -->
<script src="static/js/plugins.js"></script>
<!-- endbuild -->

Common JS file in all 5 files are plugins.js . I need that JS file in every HTML file and its repeating in all my files. My second HTML file has this block (again plugins.js is there) :

<!-- build:js static/js/main.js -->
<script src="static/js/jquery.barrating.min.js"></script>
<script src="static/js/plugins.js"></script>
<!-- endbuild -->

And my fifth HTML file has this block:

<!-- build:js static/js/main.js -->
<script src="static/js/jquery.matchHeight-min.js"></script>
<script src="static/js/jquery.barrating.min.js"></script>
<script src="static/js/plugins.js"></script>
<!-- endbuild -->

So in every file im using plugins.js and in some files i use some other libraries. But when i run task this three files are not concatenated into main.js. Only thing in main.js is content from plugins.js . Other libraries are not included into main.js. Why is that so? Can i even use this plugin like that?

My gulp task:

gulp.task('compress:js:html', ['clear:dist'], function () {
    return gulp.src('./*.html')
        .pipe(useref())
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest('./dist/'))
});
jonkemp commented 8 years ago

It would seem that the problem is in the way you have it set up. You are generating a different main.js file in every block. How will you know which one is right? My guess is which ever one gets written by gulp last is the one you get.

marioloncarek commented 8 years ago

Yes i missed the point behind this plugin, i needed something else. Thanks for your time!