`build.rollupOptions.output.banner` does not work when it is a comment string.
Describe the bug
{
build: {
minify: false,
rollupOptions: {
output: {
banner: '/* test commnet */',
},
},
},
}
After configuring as described above, there are no related comments at the top of the built artifacts.
context https://github.com/vitejs/vite/pull/21073#issuecomment-3495208448
Reproduction
https://stackblitz.com/edit/vitejs-vite-1cksxf2d?file=vite.config.js
Steps to reproduce
pnpm build
System Info
System:
OS: Windows 10 10.0.19045
CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Memory: 3.83 GB / 15.86 GB
Binaries:
Node: 24.8.0 - C:\Users\admin\AppData\Local\Volta\tools\image\node\24.8.0\node.EXE
Yarn: 4.6.0 - C:\Users\admin\AppData\Local\Volta\tools\image\yarn\4.6.0\bin\yarn.CMD
npm: 11.6.0 - C:\Users\admin\AppData\Local\Volta\tools\image\node\24.8.0\npm.CMD
pnpm: 8.14.1 - C:\Program Files\Volta\pnpm.EXE
Browsers:
Chrome: 115.0.5790.171
Edge: Chromium (140.0.3485.54)
Internet Explorer: 11.0.19041.5794
Used Package Manager
pnpm
Logs
No response
Validations
- [x] Follow our Code of Conduct
- [x] Read the Contributing Guidelines.
- [x] Read the docs.
- [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [x] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- [x] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [x] The provided reproduction is a minimal reproducible example of the bug.
Quoting some comments from #21073:
I have another question: when I configure the banner as shown in the example below, the related comments don't appear in the actual output. It seems they've been removed by esbuild plugins. Is it possible to configure some options to retain the comments?
Ah, that's unexpected. Esbuild probably stripped them off when we run it on each output chunks, so probably you'd have to configure the banner on the
esbuildoption instead to workaround, but I wonder if we should like passbuild.rollupOptions.output.bannertoesbuild.bannerto make it work.
This will not work with rolldown-vite as
esbuild.banneris removed andoxc.bannerdoes not exist. It has to usegenerateBundlehook to inject code/comments after minification (related: https://github.com/rolldown/rolldown/issues/6790).
This will not work with rolldown-vite as
esbuild.banneris removed andoxc.bannerdoes not exist. It has to usegenerateBundlehook to inject code/comments after minification (related: rolldown/rolldown#6790).
Should we add the relevant logic plugins internally or explain it in the documentation?
It appears that Vite can currently use esbuild.banner to configure comments to take effect.
Doing this properly requires having the knowledge of sourcemap combination, which feels too complicated for just injecting a string.
I think we should provide a plugin or add output.postBanner/output.postFooter.