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

strip all html instead of build sections #179

Closed algebris closed 8 years ago

algebris commented 8 years ago

Hi I'm trying to process my html with useref 3.0.5 and output looks like

<link rel="stylesheet" href="styles/lib.css">
<link rel="stylesheet" href="styles/app.css">
<script src="js/lib.js"></script>
<script src="js/app.js"></script>

only 4 lines instead of whole html!

I use this setup

return gulp
        .src(config.index)
        .pipe($.plumber())
        .pipe($.useref({searchPath: './'}))
        .pipe($.if('*.css', $.minifyCss()))
        .pipe($.if('*.js', $.uglify()))
        .pipe(gulp.dest(config.build));

In previous versions (1.0.*) it works the same manner. I found that after assets.restore() html file is ok, but after useref() it cleaning up my html again ... I can't understand where i'm wrong.

Thanks

algebris commented 8 years ago

I just found it goes like that because of no new line breaks for every html tag (it was just joined together) like <div>..</div><div>...</div> It would be great to distinguish not only by new lines. For an instance if i use this code </div><!-- build:js js/lib.js --> it will never find lib.js section

jonkemp commented 8 years ago

So it worked before with no new lines in the html?

algebris commented 8 years ago

nope, it seems main logic of useref works "by lines" but not "by chars" when it looks for necessary entities like build section etc.

jonkemp commented 8 years ago

Yes, this is correct.

algebris commented 8 years ago

thank you for quick answers! is it possible to improve it?

jonkemp commented 8 years ago

Not without rewriting it, as far as I can tell, and I am not inclined to do that right now.

jonkemp commented 8 years ago

Related #177.