Modern, opinionated Rollup configuration for TypeScript projects.
Note: This configuration is designed for our organization's projects but is adaptable for your needs. Settings may evolve to enhance our codebase.
Your project needs to have rollup installed, as it is a peer dependency.
-
Install the necessary packages:
npm install -D @pixpilot/rollup-config rollup
Create a rollup.config.js file in your project root:
import { defineConfig } from '@pixpilot/rollup-config';
export default defineConfig({
// Options (all optional)
minify: true, // Enable minification (default: true)
multiEntry: false, // Treat all .ts files in src/ as entry points
bundleDependencies: false, // Include external dependencies in the bundle
entryPoints: 'src/index.ts', // Custom entry points (default: 'src/index.ts')
copy: [
{ src: 'README.md', dest: 'dist/' },
{ src: 'assets/**/*', dest: 'dist/assets/' },
], // Copy files to output directory
});Note:
defineConfigis an async function and returns a Promise. Rollup supports async configuration files, so you can export the result directly or useawaitif needed.
multiEntry(boolean): Whentrue, treats all.tsfiles in thesrc/directory as entry points (excluding.d.tsfiles and__tests__folders).bundleDependencies(boolean): Whentrue, includes external dependencies in the final bundle using@rollup/plugin-node-resolve. Also automatically creates workspace aliases to resolve internal monorepo packages from their builtdistfolders.minify(boolean): Enables minification of the output bundle using@rollup/plugin-terser. Defaults totrue.entryPoints(string | string[]): Custom entry points for the build. Overrides the defaultsrc/index.tsor multi-entry behavior.copy(array): File copy operations usingrollup-plugin-copy. Each item should be an object withsrcanddestproperties.tsconfig(string): Path to a custom TypeScript configuration file. If not provided, automatically searches fortsconfig.build.jsonor falls back totsconfig.json.
The configuration automatically:
- Outputs both CommonJS (
.cjs) and ES module (.js) formats - Uses TypeScript compilation with
@rollup/plugin-typescript - Excludes
peerDependenciesfrom the bundle - Preserves module structure unless
bundleDependenciesis enabled - When
bundleDependenciesis enabled, automatically resolves workspace packages from their built versions using@rollup/plugin-alias
When bundleDependencies: true is set, the configuration automatically:
- Discovers all workspace packages in your monorepo
- Creates aliases to resolve them from their built
distfolders instead of source - Excludes the current package and any private packages
- Uses the package's exports field to determine the correct entry point
This ensures that when bundling dependencies, internal workspace packages are resolved from their production-ready builds rather than source files.
import { defineConfig } from '@pixpilot/rollup-config';
export default defineConfig({
bundleDependencies: true, // Enables bundling AND automatic workspace aliases
minify: false,
});With this configuration, if your package imports @myorg/utils, it will automatically resolve to ../utils/dist/index.js (or the appropriate entry point) instead of the source files.