Open TomPradat opened 1 month ago
I haven't checked deeply but I guess we should use opts.format === 'iife' || opts.format === 'umd'
instead of config.build.lib
for people using IIFE/UMD format without turning lib mode on.
https://github.com/vitejs/vite/blob/22b299429599834bf1855b53264a28ae5ff8f888/packages/vite/src/node/plugins/esbuild.ts#L320
I haven't checked deeply but I guess we should use
opts.format === 'iife' || opts.format === 'umd'
instead ofconfig.build.lib
for people using IIFE/UMD format without turning lib mode on.
This is what I was thinking too 👍 . I can work on a PR as soon as this is confirmed as a bug
Yeah, I think it's a bug.
Describe the bug
I'm building a bundle with
umd
format as a target. When doing so I expect the result bundle to be wrapped in an iife function. The configuration looks like this :Instead, I have variables declared outside the
iife
:This is a problem because the variables' declaration might override previous variables with the same name. This is how I encountered the issue.
Workaround :
So far, I have used a homemade plugin to wrap my final code in a iife :
I'm willing to work on a PR. I believe the fix would be an extension of the https://github.com/vitejs/vite/pull/7948 so that is also applies when rollupOptions.output.format is
umd
oriife
.Reproduction
See steps
Steps to reproduce
umd
format as a targetdist/bundle.js
System Info
Used Package Manager
npm
Logs
No response
Validations