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

Unhandled stream error in transformStream #168

Open youngboy opened 8 years ago

youngboy commented 8 years ago

From reading code example, it is using lazypipe as transformStream, but lazypipe can only attach error listener after it is initialized. So I guess there is no way to capture transformStream's error in our gulpfile.

My situation is running a watch task for babel transformStream, once babel throw error a syntax error, it will exit the watch process, here is a short code example:

  return gulp.src('./www/index.html')
    .pipe(plugins.useref(
      {},
      lazypipe().pipe(function () {
        return plugins.babel()
          .on('error', onError);
        });
    ));

In this case my onError won't end the transformStream as I wish. My question is if we can add on('error') on those transformStream by default to emit('end') and let gulpfile handling the error itself. I would also appreciate any suggestion for how to handle this?

Thanks.

iliakan commented 8 years ago

1) You don't have to use lazypipe, just use a function, like

useref({}, function(name) { return babel() })

2) What do you do on error? Why not emit end in onError?