jamesknelson / gulp-rev-replace

Rewrite occurences of filenames which have been renamed by gulp-rev
MIT License
389 stars 62 forks source link

is it me, or this doesn't work with gulp-filter? #60

Open debuggerpk opened 8 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?

ermish commented 7 years ago

I had a similar issue using gulp-filter. I believe you need to add the manifest option to revReplace() . So:

.pipe($.revReplace())

becomes:

.pipe($.revReplace({ manifest: gulp.src('dist/manifestfile') })