{"id":22587,"library":"vite-plugin-banner","title":"vite-plugin-banner","description":"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.","status":"active","version":"0.8.1","language":"javascript","source_language":"en","source_url":"https://github.com/chengpeiquan/vite-plugin-banner","tags":["javascript","vite-plugin","vite plugin","vite banner","typescript"],"install":[{"cmd":"npm install vite-plugin-banner","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-banner","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-banner","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is ESM-only since v0.3.0; use default import in Vite config.","wrong":"const banner = require('vite-plugin-banner')","symbol":"default","correct":"import banner from 'vite-plugin-banner'"},{"note":"TypeScript users may import the callback type alongside the default import.","wrong":"import { ContentCallback } from 'vite-plugin-banner'","symbol":"ContentCallback","correct":"import banner, { ContentCallback } from 'vite-plugin-banner'"},{"note":"TypeScript type for options object; exported alongside default.","symbol":"BannerPluginOptions","correct":"import banner, { BannerPluginOptions } from 'vite-plugin-banner'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite'\nimport banner from 'vite-plugin-banner'\n\nexport default defineConfig({\n  plugins: [\n    banner({\n      content: (fileName: string) => {\n        if (fileName.endsWith('.js')) {\n          return `/*! Bundle: ${fileName} */`\n        }\n        if (fileName.endsWith('.css')) {\n          return `/* Style: ${fileName} */`\n        }\n        return null\n      },\n      debug: true,\n      verify: true\n    })\n  ]\n})","lang":"typescript","description":"Basic setup with a callback that adds file-specific banners to JS and CSS chunks."},"warnings":[{"fix":"Ensure your Vite config has build.outDir set, or manually pass outDir option to plugin.","message":"v0.8.0: Removed default outDir value; plugin now uses Vite's build.outDir. Previously a hardcoded default could conflict.","severity":"breaking","affected_versions":">=0.8.0"},{"fix":"Upgrade to v0.7.1+ or ensure callback always returns a non-empty string or null.","message":"Callback content returning falsy values (e.g., '') was not properly skipped until v0.7.1; could cause empty banner or errors.","severity":"gotcha","affected_versions":"<0.7.1"},{"fix":"Set verify: false to skip content validation, or avoid problematic characters.","message":"verify option defaults to true; if content contains characters that could break JavaScript comments (e.g., */), plugin may reject it.","severity":"gotcha","affected_versions":">=0.5.0"},{"fix":"Use import banner from 'vite-plugin-banner' instead of require().","message":"v0.3.0: Dropped CJS require() support; after v0.3.0 only ESM import works.","severity":"deprecated","affected_versions":">=0.3.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Switch to ESM: use import banner from 'vite-plugin-banner' and ensure vite.config.ts is processed as ESM.","cause":"Using require('vite-plugin-banner') in a CommonJS context (Vite config using CJS).","error":"Error: The plugin 'vite-plugin-banner' doesn't have a default export"},{"fix":"Use correct options format: { content: '...' } or { content: (fileName) => '...' }.","cause":"Passed an object without content property or invalid ContentCallback.","error":"TypeError: content is not a function"},{"fix":"Set verify: false or sanitize content to avoid nested comment tokens.","cause":"verify option is true and content contains invalid comment characters like '/*' or '*/'.","error":"BannerPluginError: The banner content is invalid, please check it."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}