You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The config optionbuild.rollupOptions.output.banner doesn't have any effect. Similar happens to footer and intro.
From what I understand, vite uses rollup for a production build, so rollupOptions should be applied to the output JS files. I've changed the build.rollupOptions.output.chunkFileNames and this one indeed is reflected.
git clone git@github.com:darekkay/vite-rollup-banner-bug.git
cd vite-rollup-banner-bug
yarn
yarn build
Open JS files under dist/assets (index.SHA.js and vendor.SHA.js)
Expected behavior: The banner string should be added at the top of the JS files.
Actual behavior: The banner string is ignored and not included in any of the JS files.
Note: The according esbuild banner config does work in development mode as expected (but this issue is regarding the build command which uses rollup instead of esbuild).
Note: Similar issue exists for the footer and intro options.
Config file:
exportdefaultdefineConfig({build: {rollupOptions: {output: {banner: "/* This banner is missing in the output */ var moo = 1;",},},},plugins: [reactRefresh()]})
System Info
Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Provide a description in this issue that describes the bug.
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 https://github.com/vuejs/vue-next instead.
These configs ARE working. Just you're not using them right.
For banner & footer, vite uses terser to minify (includes delete comments) during build. To keep the comment, you'll need to mark the comment as important by using /*! */ instead of /* */. (generally disabling comment deleting is a bad idea)
For your intro, it's just because you're not using ENVIRONMENT so it got automatically treeshaked. By setting treeshake and minify to false you'll see this appears.
Here is a working config for you:
exportdefaultdefineConfig({build: {rollupOptions: {output: {banner: "/*! This banner is added in the output */",footer: "/*! This footer is added in the output */",intro: 'const ENVIRONMENT = "production";',},treeshake: false,},minify: false,},});
Thanks a lot @QiroNT for the explanation, this makes sense. I didn't want to totally disable treeshaking/minification, but I needed a workaround for facebook/regenerator#378 . Assigning the variable to window was sufficient in my case:
Describe the bug
The config option
build.rollupOptions.output.banner
doesn't have any effect. Similar happens tofooter
andintro
.From what I understand, vite uses
rollup
for a production build, sorollupOptions
should be applied to the output JS files. I've changed thebuild.rollupOptions.output.chunkFileNames
and this one indeed is reflected.Reproduction
dist/assets
(index.SHA.js
andvendor.SHA.js
)banner
string should be added at the top of the JS files.banner
string is ignored and not included in any of the JS files.esbuild
banner config does work in development mode as expected (but this issue is regarding thebuild
command which usesrollup
instead ofesbuild
).Config file:
System Info
Output of
npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:Used package manager:
yarn
Before submitting the issue, please make sure you do the following
The text was updated successfully, but these errors were encountered: