Skip to main content
skill CX Codex

rollup-bundler — Claude Code skill: Rollup library bundling

This skill gives your agent Rollup.js rules: output formats, external dependencies, tree-shaking and the plugins needed to bundle a library.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add Mindrally/skills --skill rollup-bundler -a claude-code
Open on GitHub

What rollup-bundler does

The skill turns your agent into a Rollup.js hand. It walks through rollup.config.mjs, picks output formats — esm, cjs, umd or iife — and splits them across several output objects. External dependencies get their own section: peer dependencies and dependencies from package.json are marked external so they stay out of the bundle.

Plugin examples are ready to copy: @rollup/plugin-node-resolve, @rollup/plugin-commonjs, @rollup/plugin-babel, @rollup/plugin-typescript, @rollup/plugin-terser and @rollup/plugin-replace. There are sections on code splitting with multiple entry points and dynamic imports, on /*#__PURE__*/ annotations and the sideEffects field for better tree-shaking, plus watch mode and the rollup -c -w command.

The skill advises against bundling peer dependencies and against CommonJS where ES modules exist. For TypeScript libraries it flags declaration files — skip them and consumers lose your types. Everything assumes Node.js and Rollup installed; rollup-plugin-visualizer is mentioned for bundle analysis.

The skill lives in the Mindrally/skills repository and installs with one command per platform.

What it helps with

  • build a library in esm, cjs and umd at once
  • mark react and lodash as external so they stay out of the bundle
  • wire up @rollup/plugin-typescript with a separate tsconfig.json
  • enable tree-shaking with named exports and sideEffects
  • split a package into several entry points that share code

Example prompts for the agent

  • Set up rollup.config.mjs for a library: input src/index.ts, esm and cjs outputs with sourcemaps
  • Move the peer dependencies from package.json into external and add globals for the UMD build
  • Add watch mode with include: 'src/**' and hook up @rollup/plugin-terser

How to install rollup-bundler

1Skills CLI (Vercel)

npx skills add Mindrally/skills --skill rollup-bundler -a claude-code

2Manually: put the files in place

~/.claude/skills/rollup-bundler/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/rollup-bundler/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about rollup-bundler

How do I install rollup-bundler in Claude?

Run npx skills add Mindrally/skills --skill rollup-bundler -a claude-code. The skill lands in ~/.claude/skills/rollup-bundler/SKILL.md.

What does rollup-bundler do?

It gives the agent Rollup.js configuration rules: output formats, plugins, external dependencies, code splitting and tree-shaking. Useful when you ship a library or package.

Which platforms does this skill support?

Claude, Codex, Cursor, GitHub Copilot, Gemini CLI and OpenCode. Each platform has its own install command and SKILL.md path.

Source text

SKILL.md · Apache-2.0
---
name: rollup-bundler
description: Best practices and guidelines for Rollup.js module bundler configuration, ES modules, and library bundling
metadata:
  maintainer: Mindrally
  source: https://github.com/Mindrally/skills
---

# Rollup Bundler

You are an expert in Rollup.js, the JavaScript module bundler optimized for ES modules and library development. Follow these guidelines when working with Rollup configurations.

## Core Principles

- Rollup is designed for ES modules and produces cleaner, smaller bundles
- Superior tree-shaking through deep execution path analysis
- Ideal for libraries and packages that will be consumed by other projects
- Focus on producing efficient, readable output code

## Project Structure

```
project/
├── src/
│   ├── index.js          # Main entry point
│   ├── modules/          # Internal modules
│   └── utils/            # Utility functions
├── dist/                 # Build output
│   ├── bundle.esm.js     # ES module format
│   ├── bundle.cjs.js     # CommonJS format
│   └── bundle.umd.js     # UMD format
├── rollup.config.mjs     # Configuration file
└── package.json
```

## Configuration Basics

### Basic Configuration

```javascript
// rollup.config.mjs
export default {
  input: 'src/index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'esm',
    sourcemap: true
  }
};
```

### Multiple Output Formats

```javascript
export default {
  input: 'src/index.js',
  output: [
    {
      file: 'dist/bundle.esm.js',
      format: 'esm',
      sourcemap: true
    },
    {
      file: 'dist/bundle.cjs.js',
      format: 'cjs',
      sourcemap: true
    },
    {
      file: 'dist/bundle.umd.js',
      format: 'umd',
      name: 'MyLibrary',
      sourcemap: true
    }
  ]
};
```

## Output Formats

### ES Modules (esm)

- Keeps bundle as ES module file
- Best for modern bundlers and browsers
- Supports tree-shaking in consuming projects

### CommonJS (cjs)

- For Node.js environments
- Compatible with require() syntax

### UMD (Universal Module Definition)

- Works as AMD, CJS, and IIFE
- Best for libraries that need broad compatibility

### IIFE (Immediately Invoked Function Expression)

- Self-executing function
- Suitable for script tags in browsers

## ES Modules Best Practices

### Use Named Exports

```javascript
// Prefer named exports for better tree-shaking
export const add = (a, b) => a + b;
export const subtract = (a, b) => a - b;

// Avoid default exports when possible
// export default { add, subtract }; // Less tree-shakeable
```

### Static Imports

```javascript
// Static imports enable tree-shaking
import { specificFunction } from './utils';

// Avoid dynamic requires in library code
// const utils = require('./utils'); // CommonJS - no tree-shaking
```

## Essential Plugins

### Node Resolve

```javascript
import resolve from '@rollup/plugin-node-resolve';

export default {
  plugins: [
    resolve({
      browser: true,
      preferBuiltins: false
    })
  ]
};
```

### CommonJS Conversion

```javascript
import commonjs from '@rollup/plugin-commonjs';

export default {
  plugins: [
    commonjs()
  ]
};
```

### Babel Transpilation

```javascript
import babel from '@rollup/plugin-babel';

export default {
  plugins: [
    babel({
      babelHelpers: 'bundled',
      presets: ['@babel/preset-env']
    })
  ]
};
```

### TypeScript Support

```javascript
import typescript from '@rollup/plugin-typescript';

export default {
  input: 'src/index.ts',
  plugins: [
    typescript({
      tsconfig: './tsconfig.json'
    })
  ]
};
```

### Minification

```javascript
import terser from '@rollup/plugin-terser';

export default {
  plugins: [
    terser()
  ]
};
```

### Environment Variables

```javascript
import replace from '@rollup/plugin-replace';

export default {
  plugins: [
    replace({
      preventAssignment: true,
      'process.env.NODE_ENV': JSON.stringify('production')
    })
  ]
};
```

## External Dependencies

### Marking Dependencies as External

```javascript
export default {
  input: 'src/index.js',
  external: ['react', 'react-dom', 'lodash'],
  output: {
    file: 'dist/bundle.js',
    format: 'esm',
    globals: {
      react: 'React',
      'react-dom': 'ReactDOM'
    }
  }
};
```

### Peer Dependencies Pattern

```javascript
import pkg from './package.json';

export default {
  external: [
    ...Object.keys(pkg.peerDependencies || {}),
    ...Object.keys(pkg.dependencies || {})
  ]
};
```

## Code Splitting

### Multiple Entry Points

```javascript
export default {
  input: {
    main: 'src/index.js',
    utils: 'src/utils/index.js'
  },
  output: {
    dir: 'dist',
    format: 'esm'
  }
};
```

### Dynamic Imports

```javascript
// Rollup handles dynamic imports automatically
async function loadModule() {
  const module = await import('./heavy-module.js');
  return module.default;
}
```

## Tree Shaking Optimization

### Pure Function Annotations

```javascript
// Mark functions as pure for better tree-shaking
export const compute = /*#__PURE__*/ createCompute();
```

### Side Effects Configuration

```json
{
  "name": "my-library",
  "sideEffects": false
}
```

## Watch Mode

```javascript
// rollup.config.mjs
export default {
  watch: {
    include: 'src/**',
    clearScreen: false
  }
};
```

Command line:

```bash
rollup -c -w
```

## Package.json Configuration

```json
{
  "name": "my-library",
  "version": "1.0.0",
  "main": "dist/bundle.cjs.js",
  "module": "dist/bundle.esm.js",
  "browser": "dist/bundle.umd.js",
  "types": "dist/index.d.ts",
  "exports": {
    ".": {
      "import": "./dist/bundle.esm.js",
      "require": "./dist/bundle.cjs.js"
    }
  },
  "files": ["dist"],
  "sideEffects": false
}
```

## Best Practices

### Do

- Use ES6 module syntax consistently
- Mark third-party dependencies as external
- Generate source maps for debugging
- Use named exports for better tree-shaking
- Test all output formats
- Use watch mode during development

### Avoid

- Bundling peer dependencies
- Using CommonJS modules when ES modules are available
- Ignoring bundle size
- Skipping TypeScript declaration files for libraries

## Common Configuration Patterns

### Library Configuration

```javascript
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';
import pkg from './package.json';

export default {
  input: 'src/index.ts',
  external: Object.keys(pkg.peerDependencies || {}),
  plugins: [
    resolve(),
    commonjs(),
    typescript({ tsconfig: './tsconfig.json' }),
    terser()
  ],
  output: [
    { file: pkg.main, format: 'cjs', sourcemap: true },
    { file: pkg.module, format: 'esm', sourcemap: true }
  ]
};
```

## Debugging and Analysis

- Use `--configDebug` flag for configuration debugging
- Generate source maps for all formats
- Use rollup-plugin-visualizer for bundle analysis
- Check output code readability

© Mindrally · Apache-2.0 · Mindrally/skills

Similar skills

Everything for Frontend and UI →

From the same set168

viewcomfy-api-rules Guides an agent through wiring the ViewComfy API into a Python and FastAPI web app: flatten workflow params, call the endpoint, save the returned files. CX Codex +1 663installs salesforce-development A skill that gives your agent Salesforce coding rules: Apex, triggers, Lightning Web Components, SOQL and metadata. Useful when you build on the platform and want the agent to respect its limits. CX Codex +1 659installs graphql-development A skill that gives the agent GraphQL guidelines: schema design, type-safe clients, React and Next.js integration. Useful when it writes resolvers and queries. CX Codex +1 661installs turborepo A skill that tells the agent how to configure Turborepo: workspace layout, turbo.json, caching and task filters. Useful once the monorepo already exists. CX Codex +1 658installs serverless A skill that gives the agent rules for FastAPI services in serverless and microservice setups: AWS Lambda, Azure Functions, API gateways. CX Codex +1 655installs convex Tells the agent how to write Convex code: queries, mutations, actions, indexes and file uploads. Useful once Convex is your backend. CX Codex +1 651installs lerna A skill that gives your coding agent Lerna conventions: package layout, versioning, publishing and running scripts across a monorepo. CX Codex +1 650installs onchainkit A skill that teaches your coding agent the OnchainKit SDK: identity, wallet, transaction, swap and frame components with TypeScript examples. CX Codex +1 641installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor