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

Can't run call gulp-useref from parallel gulp workflows #201

Open orzarchi opened 8 years ago

orzarchi commented 8 years ago

I tried to run useref from two task in parallel, using the new gulp 4 gulp.parallel method. The result is that one of the tasks almost always gets an error (no stack), or that I get the error Error: stream.push() after EOF.

After looking at index.js, I have a suspicion at to what the problem is:

    streamManager = require('./lib/streamManager');

module.exports = function (options) {
    streamManager.transforms = Array.prototype.slice.call(arguments, 1);
    streamManager.options = options || {};

    streamManager.additionalStreams();

    return through.obj(streamManager.transformFunction, streamManager.flushFunction);
};

Instead of setting properties on a global streamManager object, you could just pass these in as arguments to a function? If you approve, I'll try to find the time to submit a pull request this week.

jonaszuberbuehler commented 8 years ago

I think I'm facing the same issue, although I'm still using gulp 3.

To support localisation (in a SEO friendly way) I process the resources in parallel streams, one for each supported locale (called version in code). My minification task looks like this:

gulp.task('minify', function () {
    return execForLocales(function (version) {
        return gulp.src(version.tmp + '/*.html')
                .pipe(useref())
                .pipe(defer())
                .pipe(gulpif('*.html', htmlmin({
                    collapseWhitespace: true,
                    conservativeCollapse: true,
                    removeComments: false,
                    minifyCSS: true,
                    minifyJS: true
                })))
                .pipe(gulpif('*.js', uglify()))
                .pipe(gulpif('*.css', cssnano()))
                .pipe(gulp.dest(version.dist));
    });
});

function execForLocales(task) {
    var tasks = versions.map(function (version) {
        return task(version);
    });
    return merge(tasks);
}

This all works if I process it for one locale only but fails without any error if I try to process more locales.

orzarchi commented 8 years ago

Yup seems similar alright, me using gulp4 probably has nothing to do with it.

On Mon, Apr 11, 2016 at 12:38 PM Jonas Zuberbuehler < notifications@github.com> wrote:

I think I'm facing the same issue, although I'm still using gulp 3.

To support localisation (in a SEO friendly way) I process the resources in parallel streams, one for each supported locale (called version in code). My minification task looks like this:

gulp.task('minify', function () { return execForLocales(function (version) { return gulp.src(version.tmp + '/.html') .pipe(useref()) .pipe(defer()) .pipe(gulpif('.html', htmlmin({ collapseWhitespace: true, conservativeCollapse: true, removeComments: false, minifyCSS: true, minifyJS: true }))) .pipe(gulpif('.js', uglify())) .pipe(gulpif('.css', cssnano())) .pipe(gulp.dest(version.dist)); }); }); function execForLocales(task) { var tasks = versions.map(function (version) { return task(version); }); return merge(tasks); }

This all works if I process it for one locale only but fails without any error if I try to process more locales.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/jonkemp/gulp-useref/issues/201#issuecomment-208254797

bryk commented 8 years ago

+1 - this is also a problem for our parallel build pipeline

orzarchi commented 8 years ago

Still hoping for @jonkemp to weigh in on this.. In the mean time I've switched to gulp-usemin, as that seems to work with parallel workflows.

jonkemp commented 8 years ago

Have you tried it with the latest version 3.1.0?

orzarchi commented 8 years ago

Yep, still have the same problems. I'll try to create a minimal reproduction, but really you just need to run any sort of build in parallel.

jonkemp commented 8 years ago

I am working on a refactor which would get rid of streamManager.js. I plan on merging it in sometime this weekend. That may do what you are wanting.

noderat commented 8 years ago

Yeah, looks like reverting to 3.0.4 has resolved this issue for now, until @jonkemp merges in his changes to remove streamManager

jonkemp commented 7 years ago

Version 3.1.2 is out. Please try with the latest version and see if that fixes the issue.

danjarvis commented 7 years ago

Just hit the same issue running 3.1.2

NullSoldier commented 7 years ago

Same issue running 3.1.2 except it's june of 2017 now......

jonkemp commented 7 years ago

@NullSoldier let me know if you're willing to help!