rollup-plugin-license
raw JSON → 3.7.1 verified Mon Apr 27 auth: no javascript
Rollup plugin that adds a license banner to the final bundle and generates a file listing all third-party licenses. Current stable version is 3.7.1, released with support for Rollup 4.x peer dependency. Key differentiators: supports multiple banner comment styles (regular, ignored, slash, none), file or string content with Lodash template interpolation, third-party license output with version deduplication, and custom data injection. Widely used for compliance in open-source and enterprise bundles. Ships TypeScript definitions. Maintained actively with regular updates.
Common errors
error Error: Cannot find module 'rollup-plugin-license' ↓
cause Package not installed or ESM-only module imported via require() in CommonJS context.
fix
npm install rollup-plugin-license --save-dev; in .cjs, use dynamic import: const license = await import('rollup-plugin-license').then(m => m.default)
error TypeError: license is not a function ↓
cause Importing the module incorrectly; likely using `require('rollup-plugin-license')` in ESM context.
fix
Use default import: import license from 'rollup-plugin-license'
error Error: Banner file not found: 'LICENSE' ↓
cause The path provided in `banner.content.file` is relative and may not resolve correctly.
fix
Use absolute path: path.resolve(__dirname, 'LICENSE')
error Error: Template execution failed: ... ↓
cause The banner contains invalid Lodash template syntax (e.g., unescaped `<%`).
fix
Escape template tags: use
<%% for literal <% or remove template syntax. Warnings
breaking Version 3.x dropped support for Node <14 and Rollup <1.x. The plugin now requires Rollup ^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.0. ↓
fix Upgrade Node to >=14 and Rollup to ^1.0.0 or higher.
deprecated The option `dependencies` in banner template data is deprecated since version 3.0.0. Use `thirdParty` options instead. ↓
fix Use `thirdParty.dependencies` or `thirdParty.output`.
gotcha Using `commentStyle: 'ignored'` may not work in some minifiers (e.g., Terser) if they strip all comments by default. Ensure your minifier is configured to keep the banner. ↓
fix Set minifier option to preserve comments, e.g., terser({ format: { comments: 'all' } }).
gotcha The banner content is processed as a Lodash template with `dependencies` array. If the template contains `<%` or `%>`, these must be escaped or the plugin will throw a lodash error. ↓
fix Use `data` function to pass custom escaping or avoid template tags in banner.
breaking Version 0.10.0 changed `banner` from string to object with `content` and `commentStyle`. String usage still works but with deprecation warning. ↓
fix If passing a string, use `banner: 'your string'` or `banner: { content: 'your string' }`.
Install
npm install rollup-plugin-license yarn add rollup-plugin-license pnpm add rollup-plugin-license Imports
- license (default) wrong
const license = require('rollup-plugin-license')correctimport license from 'rollup-plugin-license' - license (type import)
import type { LicenseOptions } from 'rollup-plugin-license' - license (in CommonJS via .cjs) wrong
const license = require('rollup-plugin-license')correctconst license = await import('rollup-plugin-license').then(m => m.default)
Quickstart
// rollup.config.js (ESM)
import license from 'rollup-plugin-license'
import path from 'node:path'
export default {
input: 'src/main.js',
output: { file: 'dist/bundle.js', format: 'esm' },
plugins: [
license({
sourcemap: true,
banner: {
content: {
file: path.resolve('LICENSE'),
encoding: 'utf-8',
},
},
thirdParty: {
includePrivate: false,
includeSelf: true,
output: {
file: path.resolve('dist/dependencies.txt'),
},
},
}),
],
}