Coder Social home page Coder Social logo

ko-yelie / gulp-rollup-each Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 5.0 841 KB

Gulp plugin for Rollup. Yet another gulp-rollup plugin that allows to input/output multiple files.

License: MIT License

JavaScript 100.00%
gulp-plugins rollup static-site

gulp-rollup-each's Introduction

gulp-rollup-each

Gulp plugin for Rollup.
Yet another gulp-rollup plugin that allows to input/output multiple files for static site.

Installation

npm

npm i gulp-rollup-each

Usage

const gulp = require('gulp')
const rollupEach = require('gulp-rollup-each')

function scripts () {
  return gulp
    .src([
      'src/**/*.js',
      '!src/**/_*' // exclude modules
    ])
    .pipe(
      rollupEach({
        output: {
          // outputOptions
          format: 'iife'
        }
      })
    )
    .pipe(gulp.dest('dist'))
}

with sourcemaps and Buble

const gulp = require('gulp')
const sourcemaps = require('gulp-sourcemaps')
const rollupEach = require('gulp-rollup-each')
const buble = require('@rollup/plugin-buble')

function scripts () {
  return gulp
    .src([
      'src/**/*.js',
      '!src/**/_*' // exclude modules
    ])
    .pipe(sourcemaps.init())
    .pipe(
      rollupEach(
        {
          // inputOptions
          external: ['jquery'],
          plugins: [
            buble({
              target: {
                ie: 11
              }
            })
          ],
          isCache: true // enable Rollup cache
        },
        {
          // outputOptions
          format: 'iife',
          globals: {
            jquery: 'jQuery'
          }
        }
      )
    )
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('dist'))
}

Options

rollupEach(inputOptions [[, outputOptions], rollup])

inputOptions

The 1st argument is the same object as inputOptions.
However, the input option is the file specified in gulp.src(), so it can not be specified as gulp-rollup-each option.

If you want to enable the Rollup cache, set isCache option to true.

function scripts () {
  return gulp
    .src(['src/**/*.js'])
    .pipe(
      rollupEach(
        {
          isCache: true // enable Rollup cache
        },
        {
          format: 'iife'
        }
      )
    )
    .pipe(gulp.dest('dist'))
}

outputOptions

The 2nd argument is the same object as outputOptions.
If you omit the 2nd argument, output in the 1st argument changes to outputOptions.

function scripts () {
  return gulp
    .src(['src/**/*.js'])
    .pipe(
      rollupEach({
        output: {
          // outputOptions
          format: 'iife'
        }
      })
    )
    .pipe(gulp.dest('dist'))
}

You can also pass a function that returns rollup options object as an argument. The function will receive vinyl file object.

const path = require('path')
const gulp = require('gulp')
const rollupEach = require('gulp-rollup-each')

function scripts () {
  return gulp
    .src(['src/**/*.js'])
    .pipe(
      rollupEach(
        {
          external: [/* ... */],
          plugins: [/* ... */]
        },
        file => {
          return {
            format: 'umd',
            name: path.basename(file.path, '.js')
          }
        }
      )
    )
    .pipe(gulp.dest('dist'))
}

rollup

You can specify the 3rd argument for replacing rollup object by your dependency. It is useful if you want to use a new version of rollup than gulp-rollup-each is using.

function scripts () {
  return gulp
    .src(['src/**/*.js'])
    .pipe(
      rollupEach(
        {},
        {
          format: 'iife'
        },

        // Passing rollup object
        require('rollup')
      )
    )
    .pipe(gulp.dest('dist'))
}

License

MIT

gulp-rollup-each's People

Contributors

blackprincess avatar dependabot[bot] avatar kermage avatar ko-yelie avatar ktsn avatar panoply avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gulp-rollup-each's Issues

Rollup v1.0.0 changes

Rollups bundle.generate now returns a new format since v.1.0.0. The new format breaks loading Rollup by dependency. When rollup-each applies sourcemaps using rollup v1.0.0 it's passing an output of type array not an object which results in an UnhandledPromiseRejectionWarning, see changelog.

You must supply options.name for IIFE bundles

I get this error when trying to compile. I can specify the name as a string, but I need it to be a function. Ideally by default it would just be the name of the file.

Message:
    You must supply options.name for IIFE bundles
Details:
    code: INVALID_OPTION
    domainEmitter: [object Object]
    domain: [object Object]
    domainThrown: false

Compilation errors are not handled

Hi, I noticed gulp-rollup-each outputs unhandled promise rejections like the following log if the compiled code has some syntax errors.

(node:3864) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Unexpected token

I guess it is caused because gulp-rollup-each currently does not handle the errors from rollup.
Can we solve this problem so that providing readable errors?

UnhandledPromiseRejectionWarning with rollup plugin

I am getting the following error:

(node:93222) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): [object Object]
(node:93222) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I have narrowed it down to including the rollup-plugin-commonjs plugin. If I uncomment that plugin, works ๐Ÿ‘, but unfortunately, I need rollup-plugin-commonjs for a few npm packages in my project.

If I use a regular rollup config with the same files and config settings, instead of gulp-rollup-each, the rollup-plugin-commonjs plugin works perfectly fine.

If you have any thoughts on this issue, or need any further details, let me know!

Cache

Thank you for creating this solution. I was wondering about setting the rollup cache?

Update :
After briefly looking over the plugin code, it seems the rollup bundle parameter is not being exposed to the stream so it can not set the cacheof a previously-generated bundle without having access to the bundle object.

I'll make a PR so the plugin can support rollup cache.

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.