npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-rollup

v2.17.0

Published

gulp plugin for Rollup ES6 module bundler

Downloads

14,125

Readme

gulp-rollup npm Dependency Status Build Status

This plugin allows gulp to populate a virtual filesystem and feed it to the Rollup ES6 module bundler.

Note: This plugin is not appropriate for most use cases, as it requires every file expected to be imported by Rollup to be loaded into memory preemptively. rollup-stream is preferred for almost all purposes. If you want to transform/synthesize/alias/etc. the files Rollup processes, use Rollup plugins; if there's no Rollup plugin to do what you want, try the gulp-to-Rollup plugin adapter, rollup-plugin-gulp. If you really need to synthesize your files in gulp, go ahead and use gulp-rollup—that's what it's made for.

Install

npm install --save-dev gulp-rollup

Usage

var gulp       = require('gulp'),
    rollup     = require('gulp-rollup');

gulp.task('bundle', function() {
  gulp.src('./src/**/*.js')
    // transform the files here.
    .pipe(rollup({
      // any option supported by Rollup can be set here.
      input: './src/main.js'
    }))
    .pipe(gulp.dest('./dist'));
});

Usage with sourcemaps

var gulp       = require('gulp'),
    rollup     = require('gulp-rollup'),
    sourcemaps = require('gulp-sourcemaps');

gulp.task('bundle', function() {
  gulp.src('./src/**/*.js')
    .pipe(sourcemaps.init())
      // transform the files here.
      .pipe(rollup({
        input: './src/main.js'
      }))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('./dist'));
});

Multiple entry points

If an array of strings is passed into options.input, a separate bundle will be rolled up from each entry point. They will be processed in parallel and output in no particular order. As usual, each bundle will have the same path as the associated entry file.

In addition, a Promise that resolves to a string or array of strings can be passed into options.input. This is to make it more convenient to use asynchronous methods to locate entry files.

Options

options.rollup

In addition to the standard Rollup options, gulp-rollup supports options.rollup, allowing you to use an older, newer, or custom version of Rollup by passing in the module like so:

gulp.src('./src/**/*.js')
  .pipe(rollup({
    rollup: require('rollup'),
    input: './src/main.js'
  }))
  //...

options.allowRealFiles

If options.allowRealFiles is set to true, gulp-rollup will break the gulp plugin guidelines just for you and allow Rollup to read files directly from the filesystem when a file with a matching name isn't found in the gulp stream. You could use this to weasel your way out of having to use rollup-stream, but that would make you a terrible person.

options.impliedExtensions

By default, gulp-rollup will mimic Rollup by adding a .js extension to imports if necessary. You can customize this behavior by setting options.impliedExtensions to an array of extensions, like ['.js', '.es', '.jsx']. If options.impliedExtensions is set to false or an empty array, file extensions in imports will be treated as mandatory.

options.separateCaches

If options.separateCaches is supplied, it should be an object with property names corresponding to entry files. For each of those entry files, options.cache will be overridden with the corresponding property value. This is most useful in conjunction with the 'bundle' event:

var gulp       = require('gulp'),
    rollup     = require('gulp-rollup');

var caches = {};
gulp.task('bundle', function() {
  gulp.src('./src/**/*.js')
    .pipe(rollup({
      input: ['./src/main1.js', './src/main2.js'],
      separateCaches: caches
    }))
    .on('bundle', function(bundle, name) {
      caches[name] = bundle;
    })
    .pipe(gulp.dest('./dist'));
});

options.generateUnifiedCache

If options.generateUnifiedCache is set to true, gulp-rollup will try to construct a cache representing every file imported by any entry point, to be passed into future Rollup invocations (thus obviating the need for options.separateCaches) and deliver it via the 'unifiedcache' event. This should always work as long as all of the plugins you use have deterministic output. Since the internal structure of Rollup's cache objects can't be expected to remain stable, this option isn't guaranteed to work if you specify an options.rollup.

tl;dr: It works like this:

var gulp       = require('gulp'),
    rollup     = require('gulp-rollup');

var cache;
gulp.task('bundle', function() {
  gulp.src('./src/**/*.js')
    .pipe(rollup({
      input: ['./src/main1.js', './src/main2.js'],
      cache: cache,
      generateUnifiedCache: true
    }))
    .on('unifiedcache', function(unifiedCache) {
      cache = unifiedCache;
    })
    .pipe(gulp.dest('./dist'));
});