0.0.21 • Published 11 months ago

rollup-presets v0.0.21

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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
});
0.0.21

11 months ago

0.0.20

11 months ago

0.0.19

11 months ago

0.0.18

11 months ago

0.0.17

11 months ago

0.0.16

11 months ago

0.0.15

11 months ago

0.0.14

11 months ago

0.0.13

11 months ago

0.0.12

11 months ago

0.0.11

11 months ago

0.0.10

11 months ago

0.0.9

11 months ago

0.0.8

11 months ago

0.0.7

11 months ago

0.0.6

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago