Socket
Book a DemoInstallSign in
Socket

rollup-presets

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-presets

A collection of opinionated, production-ready Rollup presets

latest
Source
npmnpm
Version
0.0.25
Version published
Weekly downloads
7
-86.54%
Maintainers
1
Weekly downloads
 
Created
Source

rollup-presets banner

GitHub License NPM bundle minzipped size NPM total downloads Join Discord

rollup-presets is a collection of opinionated, production-ready Rollup presets for building TypeScript libraries and applications.

  • Simple & Flexible: Preconfigured yet highly customizable build presets
  • TypeScript-First: Built-in TypeScript support with path aliases and declaration files
  • Multi-Format: Supports ESM and CJS output with proper Node.js compatibility
  • Optimized: Production-ready with minification and tree-shaking
  • Extensible: Plugin system with four stages for maximum control

📖 Usage

// rollup.config.js
import { libraryPreset } from 'rollup-presets';

export default libraryPreset();

📙 Presets

libraryPreset()

Creates a production-ready Rollup configuration for TypeScript libraries. Bundle paths are automatically resolved from your package.json exports field or standard fields.

📖 Usage

First, configure your package.json to define the bundle paths. You can use either conditional exports (recommended) or standard fields:

{
	"name": "my-library",
	"version": "1.0.0",
	"exports": {
		".": {
			"import": "./dist/esm/index.js",
			"require": "./dist/cjs/index.js",
			"types": "./dist/types/index.d.ts",
			"source": "./src/index.ts"
		}
	}
}

Or using standard fields:

{
	"name": "my-library",
	"version": "1.0.0",
	"main": "./dist/cjs/index.js",
	"module": "./dist/esm/index.js",
	"types": "./dist/types/index.d.ts",
	"source": "./src/index.ts"
}

Then create your rollup.config.js:

import { libraryPreset } from 'rollup-presets';

export default libraryPreset();

That's it! This will automatically:

  • Build ESM and CJS formats
  • Generate TypeScript declarations
  • Support path aliases from tsconfig.json
  • Optimize for production by default

⚙️ Configuration

libraryPreset({
	// Build environment
	environment: 'production',
	// Keep directory structure
	preserveModules: true,
	// Output formats to generate
	formats: ['esm', 'cjs'],
	// Plugin stages for maximum control
	plugins: {
		// Stage 1: Pre-processing
		// Perfect for file replacements, virtual modules, or environment setup
		pre: [replacePlugin()],

		// Stage 2: Path-aware Transformations
		// Runs after TypeScript paths are resolved
		// Perfect for CSS imports, asset handling, or any path-dependent plugins
		transform: [cssPlugin()],

		// Stage 3: Post-processing
		// Perfect for bundle analysis, compression, or final optimizations
		post: [analyzePlugin()]
	},
	// Customize esbuild options
	esbuildOptions: {
		target: 'es2020'
	},
	// Modify final config for each bundle
	onCreateConfig: (config, bundlePath) => config
});

FAQs

Package last updated on 06 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts