rollup-plugin-banner
raw JSON → 0.2.1 verified Mon Apr 27 auth: no javascript
Rollup plugin that appends content before the JS bundle file, preserving the banner even after minification with plugins like rollup-plugin-uglify, which Rollup's built-in output.banner does not. Version 0.2.1 is the latest stable release. Differentiates from output.banner by ensuring the banner survives all plugin transformations.
Common errors
error Error: [object Object] is not a valid banner option ↓
cause Passing an object with unknown properties (e.g., missing 'file' key).
fix
Use an object with 'file' and optional 'encoding' keys.
error Cannot find module 'rollup-plugin-banner' ↓
cause Plugin not installed as devDependency.
fix
Run: npm install --save-dev rollup-plugin-banner
error SyntaxError: Unexpected token '<' ↓
cause Using 'import' syntax in a CommonJS context without transpilation.
fix
Use const banner = require('rollup-plugin-banner') instead of import.
Warnings
gotcha Banner is appended before the bundle content, not comments – ensure your banner string does not break JavaScript syntax. ↓
fix Wrap banner in comment syntax if needed, e.g., '/* My Banner */'
deprecated No new releases since 2020; plugin may be unmaintained. ↓
fix Consider using Rollup's built-in output.banner if not using minification plugins that strip it, or switch to active alternatives.
gotcha The banner is added as a string literal – template interpolation uses <%= %> syntax, not backticks. ↓
fix Use banner('String <%= pkg.xxx %>') instead of banner(`String ${pkg.xxx}`)
Install
npm install rollup-plugin-banner yarn add rollup-plugin-banner pnpm add rollup-plugin-banner Imports
- banner wrong
const banner = require('rollup-plugin-banner')correctimport banner from 'rollup-plugin-banner' - banner wrong
import { banner } from 'rollup-plugin-banner'correctconst banner = require('rollup-plugin-banner') - banner wrong
import * as banner from 'rollup-plugin-banner'correctimport banner from 'rollup-plugin-banner'
Quickstart
import banner from 'rollup-plugin-banner';
export default {
input: 'src/main.js',
output: {
file: 'dist/bundle.js',
format: 'iife',
},
plugins: [
banner('MyApp v<%= pkg.version %> by <%= pkg.author %>')
]
};