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

Does not work with gulp-filter, when used along with gulp-rev #198

Closed debuggerpk closed 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($.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?

jonkemp commented 8 years ago

Not sure. Closing since this does not seem to be related to gulp-useref.