Registry / devops / rollup-plugin-banner2

rollup-plugin-banner2

JSON →
library1.3.1jsnpmunverified

Rollup plugin to prepend a banner (e.g., license, metadata) before bundled JavaScript code, surviving minification where Rollup's built-in output.banner is stripped by plugins like rollup-plugin-uglify. Version 1.3.1 (stable; maintained as of 2024). Key differentiators from rollup-plugin-banner (unmaintained): supports sourcemaps, per-chunk banners via ChunkInfo, custom formatters (docBlock, docBlockAndGap), and async resolveBanner. Drawbacks vs alternatives: no file path loading, no package.json template injection, no automatic JS comment wrapping. Requires Node >=12.13 and Rollup.

npm install rollup-plugin-banner2
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-BANN
R
rollup-plugin-banner2
devopsjavascriptv1.3.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

banner2
import banner2 from 'rollup-plugin-banner2'
const banner2 = require('rollup-plugin-banner2')
Package is ESM-only; CJS require will fail with ERR_REQUIRE_ESM in Node >=12.
banner2
export default { plugins: [banner2(() => '/* my banner */')] }
export default { plugins: [banner2('/* my banner */')] }
resolveBanner must be a function, not a string literal.
BannerFunction
import type { BannerFunction } from 'rollup-plugin-banner2'
import { BannerFunction } from 'rollup-plugin-banner2'
Type-only import; runtime import will throw TypeError.

Basic Rollup config using banner2 with per-chunk banners and docBlock formatter.

import banner2 from 'rollup-plugin-banner2'; export default { input: 'src/index.js', output: { dir: 'dist', format: 'es' }, plugins: [ banner2( (chunk) => `/** * Bundle: ${chunk.fileName} */ `, { formatter: 'docBlock' } ) ] };
Debug
Known issues
breakingPackage is ESM-only since v1.0. Node <12 incompatible; CJS require() fails.
fix
Use import syntax. Update Node to >=12.13. If legacy CJS required, use dynamic import() or downgrade to rollup-plugin-banner (CJS).
affects: >=1.0
deprecatedThe 'formatter' option only supports 'docBlock' and 'docBlockAndGap'; custom formatters were removed in a prior version.
fix
Use resolveBanner function to implement custom formatting.
affects: >=1.2
gotcharesolveBanner must return a string, stringifiable object, or falsey. Returning undefined or null results in empty banner.
fix
Ensure function always returns something (string, Buffer, etc.) or handle falsey explicitly.
affects: >=1.0
gotchaWhen sourcemaps are enabled (default), banner content is added to sourcemaps; minifiers may still strip banner if not sourcemap-aware.
fix
If banner is stripped by minifier, try disabling sourcemaps (sourcemap: false) or use a dedicated banner plugin designed for minifiers.
affects: >=1.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/rollup-plugin-banner2/index.js not supported.
Using CommonJS require() with ESM-only package.
fix
Use import statement instead of require().
TypeError: banner2 is not a function
Importing with incorrect syntax or using default import for a named export.
fix
Use import banner2 from 'rollup-plugin-banner2' (correct) or const banner2 = (await import('rollup-plugin-banner2')).default.
Error: The "sourceMap" option is deprecated; use "sourcemap" (all lowercase).
Using incorrect camelCase option name.
fix
Change sourceMap to sourcemap in options object.
Upgrade
Version history
1.3.1latest on npm
Audit
Dependencies
rollupoptionalPeer dependency; plugin is a Rollup plugin and requires Rollup at runtime.
Agent activity
5 hits · last 30 days
node
4
Resources
rollup-plugin-banner2 — npm install rollup-plugin-banner2 · libregistry