Convert Figma logo to code with AI

rollup logorollup

Next-generation ES module bundler

25,450
1,536
25,450
582

Top Related Projects

64,887

A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Through "loaders", modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.

43,547

The zero configuration build tool for the web. 📦🚀

69,346

Next generation frontend tooling. It's fast!

26,617

Build system optimized for JavaScript and TypeScript, written in Rust

31,493

Rust-based platform for the Web

Quick Overview

Rollup is a module bundler for JavaScript that compiles small pieces of code into larger, more complex libraries or applications. It uses the new standardized format for code modules included in the ES6 revision of JavaScript, instead of previous idiosyncratic solutions such as CommonJS and AMD.

Pros

  • Efficient bundling with tree-shaking, resulting in smaller bundle sizes
  • Supports ES6 modules out of the box
  • Highly configurable with a rich plugin ecosystem
  • Produces clean, readable output code

Cons

  • Less suitable for code-splitting and dynamic imports compared to webpack
  • Steeper learning curve for complex configurations
  • Limited built-in support for non-JavaScript assets
  • Smaller community compared to webpack

Code Examples

  1. Basic bundle configuration:
// rollup.config.js
export default {
  input: 'src/main.js',
  output: {
    file: 'bundle.js',
    format: 'iife'
  }
};
  1. Using plugins:
// rollup.config.js
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';

export default {
  input: 'src/main.js',
  output: {
    file: 'bundle.js',
    format: 'iife'
  },
  plugins: [
    resolve(),
    commonjs()
  ]
};
  1. Multiple output formats:
// rollup.config.js
export default {
  input: 'src/main.js',
  output: [
    {
      file: 'dist/bundle.cjs.js',
      format: 'cjs'
    },
    {
      file: 'dist/bundle.esm.js',
      format: 'esm'
    }
  ]
};

Getting Started

  1. Install Rollup:
npm install --save-dev rollup
  1. Create a configuration file (rollup.config.js):
export default {
  input: 'src/main.js',
  output: {
    file: 'dist/bundle.js',
    format: 'iife'
  }
};
  1. Add a build script to your package.json:
{
  "scripts": {
    "build": "rollup -c"
  }
}
  1. Run the build:
npm run build

Competitor Comparisons

64,887

A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Through "loaders", modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.

Pros of webpack

  • More comprehensive ecosystem with extensive plugin support
  • Better suited for complex applications with multiple entry points
  • Built-in code splitting and dynamic imports

Cons of webpack

  • Steeper learning curve and more complex configuration
  • Slower build times for larger projects
  • Larger bundle sizes if not optimized properly

Code Comparison

webpack configuration:

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
};

Rollup configuration:

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'iife',
  },
};

Both webpack and Rollup are popular JavaScript module bundlers, but they have different strengths and use cases. webpack is more feature-rich and suitable for complex applications, while Rollup is simpler and focuses on producing smaller, more efficient bundles for libraries and smaller projects.

webpack offers a more extensive plugin ecosystem and built-in features like code splitting, making it a better choice for large-scale applications. However, this comes at the cost of a steeper learning curve and potentially slower build times.

Rollup, on the other hand, excels at producing smaller, more optimized bundles and is easier to configure for simpler projects. It's particularly well-suited for creating libraries and frameworks.

When choosing between the two, consider your project's complexity, size, and specific requirements to determine which bundler best fits your needs.

43,547

The zero configuration build tool for the web. 📦🚀

Pros of Parcel

  • Zero configuration required out of the box
  • Built-in support for various file types and assets
  • Faster build times due to multicore processing

Cons of Parcel

  • Less flexible for complex configurations
  • Larger bundle sizes compared to Rollup
  • Limited plugin ecosystem

Code Comparison

Parcel:

// No configuration needed
// Just run: parcel index.html

Rollup:

// rollup.config.js
export default {
  input: 'src/main.js',
  output: {
    file: 'bundle.js',
    format: 'iife'
  }
};

Parcel is designed for simplicity and ease of use, requiring no configuration to get started. It automatically handles various file types and assets, making it ideal for quick prototyping and smaller projects. Parcel also offers faster build times due to its multicore processing capabilities.

However, Parcel's simplicity comes at the cost of flexibility. For complex projects that require fine-tuned configurations, Rollup may be a better choice. Rollup generally produces smaller bundle sizes and has a more extensive plugin ecosystem, allowing for greater customization.

Rollup is particularly well-suited for library authors and projects that prioritize small bundle sizes. It excels at tree-shaking and producing efficient, optimized output. While it requires more initial setup, Rollup offers greater control over the bundling process and is often preferred for larger, more complex applications.

69,346

Next generation frontend tooling. It's fast!

Pros of Vite

  • Faster development server with instant hot module replacement (HMR)
  • Built-in support for TypeScript, JSX, and CSS pre-processors
  • Optimized build process with pre-bundling of dependencies

Cons of Vite

  • Less mature ecosystem compared to Rollup
  • More opinionated configuration, which may limit flexibility
  • Potential compatibility issues with some older plugins or libraries

Code Comparison

Vite configuration:

// vite.config.js
export default {
  plugins: [react()],
  build: {
    rollupOptions: {
      // Rollup-specific options
    }
  }
}

Rollup configuration:

// rollup.config.js
export default {
  input: 'src/main.js',
  output: {
    file: 'bundle.js',
    format: 'cjs'
  },
  plugins: [resolve(), commonjs()]
}

Both Vite and Rollup are powerful build tools, but Vite focuses on providing a faster development experience with its instant server start and HMR capabilities. Rollup, on the other hand, offers more flexibility and a larger ecosystem of plugins. Vite uses Rollup internally for production builds, combining the strengths of both tools. The choice between them depends on project requirements and developer preferences.

26,617

Build system optimized for JavaScript and TypeScript, written in Rust

Pros of Turborepo

  • Optimized for monorepo management with built-in task orchestration
  • Faster builds through intelligent caching and parallel execution
  • Seamless integration with other Vercel tools and services

Cons of Turborepo

  • Steeper learning curve for teams new to monorepo structures
  • Less flexible for non-monorepo projects compared to Rollup
  • Relatively newer project with a smaller ecosystem of plugins

Code Comparison

Turborepo (turborepo.json):

{
  "pipeline": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": ["dist/**"]
    }
  }
}

Rollup (rollup.config.js):

export default {
  input: 'src/main.js',
  output: {
    file: 'bundle.js',
    format: 'cjs'
  }
};

Summary

Turborepo excels in monorepo management and build optimization, while Rollup offers more flexibility for various project structures. Turborepo's configuration focuses on defining task dependencies and outputs, whereas Rollup's configuration specifies input and output details for bundling. Choose Turborepo for large-scale monorepo projects, and Rollup for more general-purpose bundling needs.

31,493

Rust-based platform for the Web

Pros of SWC

  • Significantly faster compilation speeds due to being written in Rust
  • Supports both JavaScript and TypeScript out of the box
  • Can be used as a drop-in replacement for Babel in many cases

Cons of SWC

  • Less mature ecosystem and plugin support compared to Rollup
  • May have fewer configuration options for advanced use cases
  • Documentation can be less comprehensive than Rollup's

Code Comparison

SWC configuration example:

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": true
    },
    "target": "es2015"
  }
}

Rollup configuration example:

export default {
  input: 'src/main.js',
  output: {
    file: 'bundle.js',
    format: 'cjs'
  }
};

While both tools serve different primary purposes (SWC as a compiler/transpiler and Rollup as a module bundler), this comparison highlights some key differences in their approach and capabilities. SWC excels in speed and language support, while Rollup offers more mature bundling features and ecosystem integration.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

npm version node compatibility install size code coverage backers sponsors license Join the chat at https://is.gd/rollup_chat

Rollup

Overview

Rollup is a module bundler for JavaScript which compiles small pieces of code into something larger and more complex, such as a library or application. It uses the standardized ES module format for code, instead of previous idiosyncratic solutions such as CommonJS and AMD. ES modules let you freely and seamlessly combine the most useful individual functions from your favorite libraries. Rollup can optimize ES modules for faster native loading in modern browsers, or output a legacy module format allowing ES module workflows today.

Quick Start Guide

Install with npm install --global rollup. Rollup can be used either through a command line interface with an optional configuration file or else through its JavaScript API. Run rollup --help to see the available options and parameters. The starter project templates, rollup-starter-lib and rollup-starter-app, demonstrate common configuration options, and more detailed instructions are available throughout the user guide.

Commands

These commands assume the entry point to your application is named main.js, and that you'd like all imports compiled into a single file named bundle.js.

For browsers:

# compile to a <script> containing a self-executing function
rollup main.js --format iife --name "myBundle" --file bundle.js

For Node.js:

# compile to a CommonJS module
rollup main.js --format cjs --file bundle.js

For both browsers and Node.js:

# UMD format requires a bundle name
rollup main.js --format umd --name "myBundle" --file bundle.js

Why

Developing software is usually easier if you break your project into smaller separate pieces, since that often removes unexpected interactions and dramatically reduces the complexity of the problems you'll need to solve, and simply writing smaller projects in the first place isn't necessarily the answer. Unfortunately, JavaScript has not historically included this capability as a core feature in the language.

This finally changed with ES modules support in JavaScript, which provides a syntax for importing and exporting functions and data so they can be shared between separate scripts. Most browsers and Node.js support ES modules. However, Node.js releases before 12.17 support ES modules only behind the --experimental-modules flag, and older browsers like Internet Explorer do not support ES modules at all. Rollup allows you to write your code using ES modules, and run your application even in environments that do not support ES modules natively. For environments that support them, Rollup can output optimized ES modules; for environments that don't, Rollup can compile your code to other formats such as CommonJS modules, AMD modules, and IIFE-style scripts. This means that you get to write future-proof code, and you also get the tremendous benefits of...

Tree Shaking

In addition to enabling the use of ES modules, Rollup also statically analyzes and optimizes the code you are importing, and will exclude anything that isn't actually used. This allows you to build on top of existing tools and modules without adding extra dependencies or bloating the size of your project.

For example, with CommonJS, the entire tool or library must be imported.

// import the entire utils object with CommonJS
var utils = require('node:utils');
var query = 'Rollup';
// use the ajax method of the utils object
utils.ajax('https://api.example.com?search=' + query).then(handleResponse);

But with ES modules, instead of importing the whole utils object, we can just import the one ajax function we need:

// import the ajax function with an ES import statement
import { ajax } from 'node:utils';

var query = 'Rollup';
// call the ajax function
ajax('https://api.example.com?search=' + query).then(handleResponse);

Because Rollup includes the bare minimum, it results in lighter, faster, and less complicated libraries and applications. Since this approach is based on explicit import and export statements, it is vastly more effective than simply running an automated minifier to detect unused variables in the compiled output code.

Compatibility

Importing CommonJS

Rollup can import existing CommonJS modules through a plugin.

Publishing ES Modules

To make sure your ES modules are immediately usable by tools that work with CommonJS such as Node.js and webpack, you can use Rollup to compile to UMD or CommonJS format, and then point to that compiled version with the main property in your package.json file. If your package.json file also has a module field, ES-module-aware tools like Rollup and webpack will import the ES module version directly.

Contributors

This project exists thanks to all the people who contribute. [Contribute]. . If you want to contribute yourself, head over to the contribution guidelines.

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

Special Sponsor

TNG Logo

TNG has been supporting the work of Lukas Taegert-Atkinson on Rollup since 2017.

License

MIT

NPM DownloadsLast 30 Days