sindresorhus / gulp-rev

Static asset revisioning by appending content hash to filenames: `unicorn.css` → `unicorn-d41d8cd98f.css`
MIT License
1.54k stars 217 forks source link

when used as a dependency along with gulp-filter, it gives an error. #165

Closed debuggerpk closed 7 years ago

debuggerpk commented 8 years ago

It used to work with version 2, updated to version 3, updated the task, The task i.e.

gulp.task('minify:dashboard', ['inject:dashboard'], function() {
  var assets;

  return gulp.src(paths.django.templates.root + '/__dashboard.html')
    .pipe($.replace('script src="{{ STATIC_URL }}dashboard', 'script src="compile'))

    .pipe($.useref({
      searchPath: '.'
    }))

    // versioning assets
    .pipe(indexHtmlFilter)
      .pipe($.buffer())
      .pipe($.rev())
      .pipe($.debug())
      .pipe(indexHtmlFilter.restore)

    // processing scripts
    .pipe(jsFilter)
      // .pipe($.uglify({
      //   preserveComments: $.uglifySaveLicense,
      //   compress: uglifyCompressOptions
      // }))
      .pipe($.size())
      .pipe(gulp.dest(paths.django.assets.dashboard + '/builds'))
      .pipe(jsFilter.restore)

    // updating references
    .pipe($.revReplace())
    // adding django static url reference
    .pipe($.replace('src="scripts', 'src="{{ STATIC_URL }}dashboard/builds/scripts'))
    .pipe(gulp.dest('compile/builds'));
});

This tasks works fine on its own, e.g.

gulp minify:dashboard

however, when i introduce a new task

gulp.task('minify', ['minify:common', 'minify:dashboard']);

the above task gulp minify gives me this

events.js:154
      throw er; // Unhandled 'error' event
      ^
Error: write after end
    at writeAfterEnd (/magneto/dashboard/node_modules/readable-stream/lib/_stream_writable.js:203:12)
    at StreamFilter.Writable.write (/magneto/dashboard/node_modules/readable-stream/lib/_stream_writable.js:239:20)
    at write (/magneto/dashboard/node_modules/gulp-useref/node_modules/readable-stream/lib/_stream_readable.js:623:24)
    at flow (/magneto/dashboard/node_modules/gulp-useref/node_modules/readable-stream/lib/_stream_readable.js:632:7)
    at DestroyableTransform.pipeOnReadable (/magneto/dashboard/node_modules/gulp-useref/node_modules/readable-stream/lib/_stream_readable.js:664:5)
    at emitNone (events.js:80:13)
    at DestroyableTransform.emit (events.js:179:7)
    at emitReadable_ (/magneto/dashboard/node_modules/gulp-useref/node_modules/readable-stream/lib/_stream_readable.js:448:10)
    at emitReadable (/magneto/dashboard/node_modules/gulp-useref/node_modules/readable-stream/lib/_stream_readable.js:444:5)
    at readableAddChunk (/magneto/dashboard/node_modules/gulp-useref/node_modules/readable-stream/lib/_stream_readable.js:187:9)

the strange thing, i remove all the filters, i.e.

gulp.task('minify:dashboard', ['inject:dashboard'], function() {
  var assets;

  return gulp.src(paths.django.templates.root + '/__dashboard.html')
    .pipe($.replace('script src="{{ STATIC_URL }}dashboard', 'script src="compile'))

    .pipe($.useref({
      searchPath: '.'
    }))

    // versioning assets
    //.pipe(indexHtmlFilter)
      .pipe($.rev())
      .pipe($.debug())
      //.pipe(indexHtmlFilter.restore)

    // processing scripts
    //.pipe(jsFilter)
      // .pipe($.uglify({
      //   preserveComments: $.uglifySaveLicense,
      //   compress: uglifyCompressOptions
      // }))
      //.pipe($.size())
      //.pipe(gulp.dest(paths.django.assets.dashboard + '/builds'))
      //.pipe(jsFilter.restore)

    // updating references
    .pipe($.revReplace())
    // adding django static url reference
    .pipe($.replace('src="scripts', 'src="{{ STATIC_URL }}dashboard/builds/scripts'))
    .pipe(gulp.dest('compile/builds'));
});

then the task gulp minify works perfectly fine. Is it something wrong with gulp-filter package, or am i using it wrong?

zhouzi commented 7 years ago

Thanks for sharing @ysfjwd. Did you have a chance to figure this issue out?

To be honest, the steps to reproduce the issue are quite complex. That's probably why we haven't been addressing it yet. When facing an issue, it's good to remove everything bit by bit until you're left with the non-working code. You're likely to solve the issue along the process and if not, you'll have a simple reproduction scenario to share.

debuggerpk commented 7 years ago

i downgraded to gulp2 in order to use this and had been using gulp2 ever since for that particular project. let me upgrade to gulp3 and try to replicate it.

zhouzi commented 7 years ago

@ysfjwd did upgrading to gulp 3 solve this issue?

debuggerpk commented 7 years ago

the project i was on has been handed over to client. The code i have, i checked, shows gulp 2 in package.json.

zhouzi commented 7 years ago

Thanks, I'm closing this issue then 👍