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-banner2Verified import paths — ran on the pinned version, not inferred.
Basic Rollup config using banner2 with per-chunk banners and docBlock formatter.
Use import syntax. Update Node to >=12.13. If legacy CJS required, use dynamic import() or downgrade to rollup-plugin-banner (CJS).
Use resolveBanner function to implement custom formatting.
Ensure function always returns something (string, Buffer, etc.) or handle falsey explicitly.
If banner is stripped by minifier, try disabling sourcemaps (sourcemap: false) or use a dedicated banner plugin designed for minifiers.
Use import statement instead of require().
Use import banner2 from 'rollup-plugin-banner2' (correct) or const banner2 = (await import('rollup-plugin-banner2')).default.Change sourceMap to sourcemap in options object.