rollup-plugin-by-output
raw JSON → 1.0.1 verified Mon Apr 27 auth: no javascript
A Rollup plugin (or plugin helper) that allows applying Rollup plugins conditionally based on output options (format, file, etc.). Version 1.0.1 is the latest stable release. It helps reduce duplicate config when Rollup has multiple outputs that need different plugins (e.g., minification only for UMD builds). Key differentiator: provides elegant helpers like `when`, `whenAll`, `prop`, `format`, and `file` to filter plugins per output. Unlike manual array configs, it keeps code DRY. Requires Node >=8.3.0.
Common errors
error TypeError: plugins is not a function ↓
cause Using default import as an array or passing incorrect arguments to 'plugins'.
fix
Call plugins() with arguments: plugins(pluginA, [filter, pluginB]). Do not wrap in array brackets.
error when is not a function ↓
cause Importing 'when' incorrectly (e.g., import { when } from 'rollup-plugin-by-output' but package doesn't export it as named in CJS).
fix
Ensure your bundler supports ESM or use import { when } from 'rollup-plugin-by-output' with ES modules; in CJS, use const { when } = require('rollup-plugin-by-output').
error Module not found: Error: Can't resolve 'rollup-plugin-by-output' ↓
cause Package not installed or missing in node_modules.
fix
Run npm install --save-dev rollup-plugin-by-output
Warnings
gotcha The 'file' helper compares exact string equality, not a suffix. To match by file extension, use a custom function. ↓
fix Use when(file.name => name.endsWith('.min.js'), plugin) or prop('file', f => f.endsWith('.min.js'))
deprecated The package exports using default export for 'plugins' but named exports for helpers – mixing can cause confusion. ↓
fix Be explicit: import plugins, { when } from 'rollup-plugin-by-output'
Install
npm install rollup-plugin-by-output yarn add rollup-plugin-by-output pnpm add rollup-plugin-by-output Imports
- plugins wrong
const plugins = require('rollup-plugin-by-output')correctimport plugins from 'rollup-plugin-by-output' - when wrong
const { when } = require('rollup-plugin-by-output')correctimport { when } from 'rollup-plugin-by-output' - file
import { file } from 'rollup-plugin-by-output' - format
import { format } from 'rollup-plugin-by-output'
Quickstart
import babel from 'rollup-plugin-babel';
import terser from 'rollup-plugin-terser';
import plugins, { file } from 'rollup-plugin-by-output';
export default {
input: 'src/index.js',
output: [
{ file: 'dist/bundle.js', format: 'cjs' },
{ file: 'dist/bundle.min.js', format: 'cjs' },
],
plugins: plugins(
babel(),
[file('dist/bundle.min.js'), terser()]
)
};