项目作者: ko-yelie

项目描述 :
Gulp plugin for Rollup. Yet another gulp-rollup plugin that allows to input/output multiple files.
高级语言: JavaScript
项目地址: git://github.com/ko-yelie/gulp-rollup-each.git
创建时间: 2017-01-22T17:52:53Z
项目社区:https://github.com/ko-yelie/gulp-rollup-each

开源协议:MIT License

下载


gulp-rollup-each

Gulp plugin for Rollup.

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

Installation

npm

  1. npm i gulp-rollup-each

Usage

  1. const gulp = require('gulp')
  2. const rollupEach = require('gulp-rollup-each')
  3. function scripts () {
  4. return gulp
  5. .src([
  6. 'src/**/*.js',
  7. '!src/**/_*' // exclude modules
  8. ])
  9. .pipe(
  10. rollupEach({
  11. output: {
  12. // outputOptions
  13. format: 'iife'
  14. }
  15. })
  16. )
  17. .pipe(gulp.dest('dist'))
  18. }

with sourcemaps and Buble

  1. const gulp = require('gulp')
  2. const sourcemaps = require('gulp-sourcemaps')
  3. const rollupEach = require('gulp-rollup-each')
  4. const buble = require('@rollup/plugin-buble')
  5. function scripts () {
  6. return gulp
  7. .src([
  8. 'src/**/*.js',
  9. '!src/**/_*' // exclude modules
  10. ])
  11. .pipe(sourcemaps.init())
  12. .pipe(
  13. rollupEach(
  14. {
  15. // inputOptions
  16. external: ['jquery'],
  17. plugins: [
  18. buble({
  19. target: {
  20. ie: 11
  21. }
  22. })
  23. ],
  24. isCache: true // enable Rollup cache
  25. },
  26. {
  27. // outputOptions
  28. format: 'iife',
  29. globals: {
  30. jquery: 'jQuery'
  31. }
  32. }
  33. )
  34. )
  35. .pipe(sourcemaps.write())
  36. .pipe(gulp.dest('dist'))
  37. }

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.

  1. function scripts () {
  2. return gulp
  3. .src(['src/**/*.js'])
  4. .pipe(
  5. rollupEach(
  6. {
  7. isCache: true // enable Rollup cache
  8. },
  9. {
  10. format: 'iife'
  11. }
  12. )
  13. )
  14. .pipe(gulp.dest('dist'))
  15. }

outputOptions

The 2nd argument is the same object as outputOptions.

If you omit the 2nd argument, output in the 1st argument changes to outputOptions.

  1. function scripts () {
  2. return gulp
  3. .src(['src/**/*.js'])
  4. .pipe(
  5. rollupEach({
  6. output: {
  7. // outputOptions
  8. format: 'iife'
  9. }
  10. })
  11. )
  12. .pipe(gulp.dest('dist'))
  13. }

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

  1. const path = require('path')
  2. const gulp = require('gulp')
  3. const rollupEach = require('gulp-rollup-each')
  4. function scripts () {
  5. return gulp
  6. .src(['src/**/*.js'])
  7. .pipe(
  8. rollupEach(
  9. {
  10. external: [/* ... */],
  11. plugins: [/* ... */]
  12. },
  13. file => {
  14. return {
  15. format: 'umd',
  16. name: path.basename(file.path, '.js')
  17. }
  18. }
  19. )
  20. )
  21. .pipe(gulp.dest('dist'))
  22. }

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.

  1. function scripts () {
  2. return gulp
  3. .src(['src/**/*.js'])
  4. .pipe(
  5. rollupEach(
  6. {},
  7. {
  8. format: 'iife'
  9. },
  10. // Passing rollup object
  11. require('rollup')
  12. )
  13. )
  14. .pipe(gulp.dest('dist'))
  15. }

License

MIT