Grunt Rollup Plugin

12.0.0 · active · verified Tue Apr 21

grunt-rollup is a Grunt plugin that provides an interface to Rollup.js, a next-generation ES6 module bundler, within the Grunt build system. It enables developers to integrate Rollup's advanced tree-shaking and module bundling capabilities directly into their existing Grunt workflows. The package is currently stable at version 12.0.0, released recently with updates to Rollup v2.71.1 and Grunt v1.5.2, reflecting a cadence of updates to stay current with its core dependencies. Its primary function is to abstract the Rollup JavaScript API into Grunt tasks, allowing full configuration of Rollup options, sourcemap generation, and integration of Rollup plugins. This makes it a suitable choice for projects already heavily invested in Grunt that require modern JavaScript module bundling without migrating to a different task runner.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure 'grunt-rollup' in a Gruntfile.js, including setting up basic Rollup options, integrating the `@rollup/plugin-babel`, and correctly handling stateful plugins with a function for multiple output bundles.

const babel = require('@rollup/plugin-babel').default;

module.exports = function(grunt) {
  grunt.initConfig({
    rollup: {
      options: {
        // Common Rollup output options, often recommended to be explicit
        output: {
          format: 'es', // or 'cjs', 'umd', 'iife'
          sourcemap: true
        },
        // Use a function to return plugins for stateful plugins or multiple bundles
        plugins: function() {
          return [
            babel({
              babelHelpers: 'bundled',
              exclude: './node_modules/**' // Exclude node_modules to speed up transpilation
            })
            // Add other Rollup plugins here, e.g., require('@rollup/plugin-node-resolve').default()
          ];
        }
      },
      // Define multiple targets/bundles
      app: {
        files: {
          'dest/bundle.js': 'src/entry.js' // Bundle src/entry.js into dest/bundle.js
        }
      },
      anotherApp: {
        files: {
          'dest/bundle2.js': 'src/entry2.js' // Bundle src/entry2.js into dest/bundle2.js
        }
      }
    }
  });

  // Load the grunt-rollup plugin
  grunt.loadNpmTasks('grunt-rollup');

  // Register a default task to run rollup
  grunt.registerTask('default', ['rollup']);
};

view raw JSON →