Coder Social home page Coder Social logo

rollup-stream's Introduction

rollup-stream npm Dependency Status Build Status

This is a simple wrapper around Rollup that returns a readable stream instead of a Promise, like Browserify's bundle() method. It's designed to make using Rollup with gulp easier, but if you find another use for it, go ahead!

The options object is passed to Rollup's rollup() and generate() methods. This currently works because there's no overlap between the names of the options those methods take. Hopefully that won't change any time soon!

Installation

npm install --save-dev rollup-stream

Basic usage

var gulp = require('gulp'),
    rollup = require('rollup-stream'),
    source = require('vinyl-source-stream');

gulp.task('rollup', function() {
  return rollup({
      entry: './src/main.js'
    })
    
    // give the file the name you want to output with.
    .pipe(source('app.js'))
    
    // and output to ./dist/app.js as normal.
    .pipe(gulp.dest('./dist'));
});

Usage with sourcemaps

var gulp = require('gulp'),
    rollup = require('rollup-stream'),
    sourcemaps = require('gulp-sourcemaps'),
//  rename = require('gulp-rename'),
    source = require('vinyl-source-stream'),
    buffer = require('vinyl-buffer');

gulp.task('rollup', function() {
  return rollup({
      entry: './src/main.js',
      sourceMap: true
    })
    
    // point to the entry file.
    .pipe(source('main.js', './src'))
    
    // buffer the output. most gulp plugins, including gulp-sourcemaps, don't support streams.
    .pipe(buffer())
    
    // tell gulp-sourcemaps to load the inline sourcemap produced by rollup-stream.
    .pipe(sourcemaps.init({loadMaps: true}))
        
        // transform the code further here.
        
    // if you want to output with a different name from the input file, use gulp-rename here.
//  .pipe(rename('index.js'))
    
    // write the sourcemap alongside the output file.
    .pipe(sourcemaps.write('.'))
    
    // and output to ./dist/main.js as normal.
    .pipe(gulp.dest('./dist'));
});

Usage with caching

var gulp = require('gulp'),
    rollup = require('rollup-stream'),
    source = require('vinyl-source-stream');

var cache;
gulp.task('rollup', function() {
  return rollup({
      entry: './src/main.js',
      cache: cache
    })
    
    .on('bundle', function(bundle) {
      cache = bundle;
    })
    
    // after listening for the 'bundle' event, proceed as usual.
    .pipe(source('app.js'))
    .pipe(gulp.dest('./dist'));
});

gulp.task('watch', function() {
  gulp.watch('./src/**/*.js', ['rollup']);
});

Usage with newer, older, or custom Rollup

var gulp = require('gulp'),
    rollup = require('rollup-stream'),
    source = require('vinyl-source-stream');

gulp.task('rollup', function() {
  return rollup({
      entry: './src/main.js',
      rollup: require('rollup')
    })
    
    // after passing options.rollup, proceed as usual.
    .pipe(source('app.js'))
    .pipe(gulp.dest('./dist'));
});

Usage with Rollup config file

var gulp = require('gulp'),
    rollup = require('rollup-stream'),
    source = require('vinyl-source-stream');

gulp.task('rollup', function() {
  return rollup('rollup.config.js')
    .pipe(source('app.js'))
    .pipe(gulp.dest('./dist'));
});

rollup-stream's People

Contributors

lemmabit avatar snuggs avatar

Watchers

James Cloos avatar Etienne avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.