Replies: 3 comments 1 reply
-
I'm still having similar issues |
Beta Was this translation helpful? Give feedback.
-
Usually you just use the magic of the build tools and enjoy the result, whether rollup, vite or esbuild. But if something doesn't work, you quickly find yourself knee-deep in the swamp behind the curtain that hides the magic from us mortals. And even if you are a fan of clean code and you prefer speaking function names instead of comments in the code, it still happens that someone else's comment catches your eye: vite/packages/vite/src/node/plugins/esbuild.ts Lines 281 to 290 in 5d55083 So I think, Vite is doing some first stage bundling (with Rollup maybe) and uses esbuild for a second stage bundling of that "lib" telling esbuild to not wrap it inside another IIFE, which leads to that helper declarations outside the IIFE. See my comment in esbuild repo for how I reproduced how the pollution of the global namespace occurs in the first place: evanw/esbuild#3275 (comment) And the code to "repair" this situation doesn't work when esbuild is told to minify the code. But where does that lead us? |
Beta Was this translation helpful? Give feedback.
-
I have the same problem. I use
I expect the output to be like this:
My expectation is that output format "iife" wraps everything in an IIFE so that the global namespace does not get polluted. |
Beta Was this translation helpful? Give feedback.
-
I tried to reprt an issue, but the process is very obstructive, but I can describe it very well, if someone is interested or wants to listen:
We are building different Svelte components written in Typescript as custom elements.
We configured Vite to minify the code and to wrap it as IIFE.
And although we are using the latest version of Svelte and Vite,
we encounter a problem quite similar to this issue from about a year ago:
#11641
The minified code declares a global variable
v
which is vulnerable of being overwritten by some other code on the same website.Minified the code reads like this (I added some linebreaks for readability):
Without minification the code is that:
Because minification renames
__publicField
tov
we run into a variable name collision and an error.I wonder, if the code that tries to move the declarations inside the IIFE doesn't work or if this is specifically related to Svelte?
We would appreciate if someone can confirm or even fix this or can transform this into an issue.
Beta Was this translation helpful? Give feedback.
All reactions