Registry / devops / vite-plugin-banner

vite-plugin-banner

JSON →
library0.8.1jsnpmunverified

A Vite plugin that adds a banner comment to the top of each generated chunk (JS and CSS files). Current stable version is 0.8.1, compatible with Vite 6. Released under active maintenance with monthly updates. Key differentiators: lightweight (no extra dependencies), supports string or callback-based banner content, allows debug mode and content verification toggle. Compared to alternatives like rollup-plugin-banner, it is Vite-native and supports ESM/CJS.

npm install vite-plugin-banner
INSTALL
IMPORT
SIG · VITE-PLUGIN-BANNER
V
vite-plugin-banner
devopsjavascriptv0.8.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.

default
import banner from 'vite-plugin-banner'
const banner = require('vite-plugin-banner')
Package is ESM-only since v0.3.0; use default import in Vite config.
ContentCallback
import banner, { ContentCallback } from 'vite-plugin-banner'
import { ContentCallback } from 'vite-plugin-banner'
TypeScript users may import the callback type alongside the default import.
BannerPluginOptions
import banner, { BannerPluginOptions } from 'vite-plugin-banner'
TypeScript type for options object; exported alongside default.

Basic setup with a callback that adds file-specific banners to JS and CSS chunks.

// vite.config.ts import { defineConfig } from 'vite' import banner from 'vite-plugin-banner' export default defineConfig({ plugins: [ banner({ content: (fileName: string) => { if (fileName.endsWith('.js')) { return `/*! Bundle: ${fileName} */` } if (fileName.endsWith('.css')) { return `/* Style: ${fileName} */` } return null }, debug: true, verify: true }) ] })
Debug
Known issues
breakingv0.8.0: Removed default outDir value; plugin now uses Vite's build.outDir. Previously a hardcoded default could conflict.
fix
Ensure your Vite config has build.outDir set, or manually pass outDir option to plugin.
affects: >=0.8.0
gotchaCallback content returning falsy values (e.g., '') was not properly skipped until v0.7.1; could cause empty banner or errors.
fix
Upgrade to v0.7.1+ or ensure callback always returns a non-empty string or null.
affects: <0.7.1
gotchaverify option defaults to true; if content contains characters that could break JavaScript comments (e.g., */), plugin may reject it.
fix
Set verify: false to skip content validation, or avoid problematic characters.
affects: >=0.5.0
deprecatedv0.3.0: Dropped CJS require() support; after v0.3.0 only ESM import works.
fix
Use import banner from 'vite-plugin-banner' instead of require().
affects: >=0.3.0
Errors
Common errors & fixes
Error: The plugin 'vite-plugin-banner' doesn't have a default export
Using require('vite-plugin-banner') in a CommonJS context (Vite config using CJS).
fix
Switch to ESM: use import banner from 'vite-plugin-banner' and ensure vite.config.ts is processed as ESM.
TypeError: content is not a function
Passed an object without content property or invalid ContentCallback.
fix
Use correct options format: { content: '...' } or { content: (fileName) => '...' }.
BannerPluginError: The banner content is invalid, please check it.
verify option is true and content contains invalid comment characters like '/*' or '*/'.
fix
Set verify: false or sanitize content to avoid nested comment tokens.
Upgrade
Version history
0.8.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
vite-plugin-banner — npm install vite-plugin-banner · libregistry