lemmabit / rollup-stream

a wrapper around Rollup that returns a stream instead of a Promise
MIT License
68 stars 14 forks source link

pipe patching support #1

Open flying-sheep opened 8 years ago

flying-sheep commented 8 years ago

it seems that this doesn’t work together with gulp-plumber.

i think you have to splice in the plumber before running things that throw errors, but rollup-stream works by directly creating an output stream that emits errors.

it would be nice if there was a way to not rely on unsightly code like this:

gulp.task('build-react', () => {
    const stream = rollup({ entry: 'src/js/main.js' })
    return stream
        .on('error', e => {
            console.error(`${e.stack}`)
            stream.emit('end')
        })
        ...
})
lemmabit commented 8 years ago

Well... let's look at the big picture.

gulp.task('compile', (cb) => {
  return rollup({entry: './source/main.js', sourceMap: true, debug: true})
    .on('error', function(e) {
      console.error(e.stack);
      this.emit('end');
    })
    .pipe(source('main.js', './source'))
    .pipe(plumber())
    .pipe(buffer())
    .pipe(sourcemaps.init({loadMaps: true}))
      // ...
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('./dist'));
});

Using rollup-stream with gulp does result in a lot of unsightly code. I could make a Swiss Army knife of sorts for using Rollup with gulp, using rollup-stream behind the scenes, so that the above code would end up looking something like this instead:

gulp.task('compile', (cb) => {
  return rollup({
      filename: 'main.js',
      directory: './source',
      plumber,
      sourcemaps,
      buffer: true,
      debug: true
    })
      // ...
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('./dist'));
});

But that's only one line shorter, and I don't like the idea of centralizing everything in one module. I could also add the option to set die: false or something to make it set the error handler for you, but that seems weird and idiosyncratic.

The current way of using the module will probably stay, but if you have any ideas, I'd be open to them.

flying-sheep commented 8 years ago

yeah, this was mainly brainstorming.

i’d prefer fixing gulp-rollup to conform to gulp guidelines: gulpjs/plugins#205

TxHawks commented 8 years ago

@Permutatrix - Just out curiosity, what's debug: true in the following line in your answer?

return rollup({entry: './source/main.js', sourceMap: true, debug: true})
lemmabit commented 8 years ago

@TxHawks Good question. That snippet was adapted from some code copy-pasted from an old, beat-up testbed I use for this stuff. It originally used Browserify, then I adapted it to use gulp-rollup, then rollup-stream. I don't know where the debug: true came from, but I can say with near certainty that it doesn't do anything now.

erikkaplun commented 7 years ago

@Permutatrix you could mention the workaround in the "big picture" in the README for the time being, for newcomers to gulp like myself.