{"id":17242,"library":"gulp-best-rollup-2","title":"Gulp Plugin for Rollup ES6 Bundler","description":"gulp-best-rollup-2 is a Gulp plugin designed for integrating the Rollup ES6 module bundler into a Gulp build pipeline. As a fork rewritten for Rollup v2.X and modern ES6, it provides a deeper integration than its predecessors and alternatives like `gulp-rollup`. The current stable version is 5.0.3, with maintenance releases occurring as needed for compatibility or bug fixes. Its key differentiator lies in how it handles file paths from `gulp.src()` directly within Rollup, allowing other Gulp plugins to operate effectively in the pipeline before or after the bundling step. This approach deviates from Rollup's typical file-reading mechanism, enabling greater flexibility in complex Gulp workflows by treating Rollup primarily as an in-memory transformation step, rather than a file handler.","status":"active","version":"5.0.3","language":"javascript","source_language":"en","source_url":"git://github.com/noxasch/gulp-better-rollup-2","tags":["javascript","gulp","gulpplugin","rollup","es6"],"install":[{"cmd":"npm install gulp-best-rollup-2","lang":"bash","label":"npm"},{"cmd":"yarn add gulp-best-rollup-2","lang":"bash","label":"yarn"},{"cmd":"pnpm add gulp-best-rollup-2","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core bundler engine; required as a peer dependency for functionality.","package":"rollup","optional":false}],"imports":[{"note":"The plugin exports a default function. While Gulpfiles typically use CommonJS `require`, if using ESM Gulpfiles, `import rollup from 'gulp-better-rollup'` would be the equivalent correct import.","wrong":"import { rollup } from 'gulp-better-rollup'","symbol":"rollup","correct":"const rollup = require('gulp-better-rollup')"},{"note":"Standard import for the Gulp core library used to define tasks and pipelines.","symbol":"gulp","correct":"const gulp = require('gulp')"},{"note":"This demonstrates importing a common Rollup plugin (like `@rollup/plugin-babel`). Ensure all Rollup plugins are installed separately and imported similarly for inclusion in the `plugins` array.","symbol":"babel","correct":"const babel = require('rollup-plugin-babel')"}],"quickstart":{"code":"var gulp = require('gulp')\nvar sourcemaps = require('gulp-sourcemaps')\nvar rollup = require('gulp-better-rollup')\nvar babel = require('rollup-plugin-babel')\n\ngulp.task('lib-build', () => {\n  gulp.src('lib/index.js')\n    .pipe(sourcemaps.init())\n    .pipe(rollup({\n      // There is no `input` option as rollup integrates into the gulp pipeline\n      plugins: [babel({ babelHelpers: 'bundled' })] // Note: babelHelpers option often needed for babel plugin\n    }, {\n      // Rollups `sourcemap` option is unsupported. Use `gulp-sourcemaps` plugin instead\n      format: 'cjs'\n    }))\n    // inlining the sourcemap into the exported .js file\n    .pipe(sourcemaps.write())\n    .pipe(gulp.dest('dist'))\n})","lang":"javascript","description":"Demonstrates bundling an ES6 library with Rollup and Babel, applying sourcemaps, and outputting the CJS bundle to a 'dist' directory."},"warnings":[{"fix":"Ensure `gulp-better-rollup` is placed early in the pipeline if other plugins' transformations are not meant to be superseded, or use plugins that don't perform source transformations (e.g., `gulp-sourcemaps`) before it.","message":"Transformations from Gulp plugins executed *before* `gulp-better-rollup` in the pipeline will be lost. The plugin operates on file paths provided by `gulp.src()` directly, not on in-memory buffers transformed by previous plugins.","severity":"gotcha","affected_versions":"*"},{"fix":"Specify input files using `gulp.src()` instead of Rollup's `input` option. The plugin will automatically use the file paths from the Gulp stream.","message":"The Rollup `input` option (e.g., `input: 'src/main.js'`) is explicitly unsupported and will be ignored or cause errors.","severity":"gotcha","affected_versions":"*"},{"fix":"Remove any `sourcemap: true` or similar options from Rollup's `outputOptions`. Instead, integrate `gulp-sourcemaps` into your Gulp pipeline before and after `gulp-better-rollup`.","message":"Rollup's native `output.sourcemap` option is unsupported. Sourcemap generation is delegated entirely to `gulp-sourcemaps`.","severity":"gotcha","affected_versions":"*"},{"fix":"If `.mjs` is critical, consider inlining sourcemaps (`sourcemaps.write()`) or creating external sourcemaps with a different file extension/naming convention. Check `gulp-sourcemaps` documentation for potential updates or workarounds for `.mjs`.","message":"When using `gulp-sourcemaps` with `.mjs` files, the sourcemap linking comment (`//# sourceMappingURL=`) may not be inserted, rendering external sourcemaps ineffective.","severity":"gotcha","affected_versions":"*"},{"fix":"When using `gulp.dest()`, specify a target directory to allow Rollup's `output.file` to name the bundled output. Alternatively, use `gulp-rename` after `gulp-better-rollup` for precise output filename control.","message":"The Rollup `output.file` argument can only influence the filename if `gulp.dest()` specifies a directory. If `gulp.dest()` specifies a full file path, Rollup's `output.file` is completely ignored.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Run `npm install rollup --save-dev` in your project directory.","cause":"`rollup` is a peer dependency of `gulp-better-rollup-2` and must be installed separately.","error":"Error: Cannot find module 'rollup'"},{"fix":"Remove the `input` option from the first argument (Rollup `inputOptions`) passed to the `rollup()` plugin function.","cause":"This error occurs if you are mistakenly passing an `input` option to the `rollup()` plugin call. `gulp-better-rollup-2` expects input to be handled by `gulp.src()`.","error":"Input option must be specified."},{"fix":"Ensure `gulp-sourcemaps` is installed (`npm install gulp-sourcemaps --save-dev`) and correctly imported (`const sourcemaps = require('gulp-sourcemaps')`).","cause":"This usually indicates `sourcemaps.init()` was called, but `gulp-sourcemaps` was not properly imported or installed.","error":"TypeError: Cannot read properties of undefined (reading 'init')"}],"ecosystem":"npm","meta_description":null}