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
Is there a way to remove the injected __vite_legacy_guard function without needing to write a generateBundle plugin to remove it?
Why?
I'm attempting to generate a bundle which is intended to be used within a classic <script /> tag (no type=module).
My ideal format for the bundle is iife, which aligns with what is proposed in Rollup output formats.
However, when I generate the bundle, plugin-legacy injects an exported function __vite_legacy_guard, which means I end up with a bundle which looks like:
export function __vite_legacy_guard(){import.meta.url,import("_").catch(()=>1),async function*(){}().next()}(function(){...})();
This added function causes an error to be thrown when the bundle is loaded by the <script />:
SyntaxError: Unexpected token 'export'
Fwiw, the need for a legacy guard is obsolete in my use-case. My server has logic to determine which chunks to serve (modern or legacy); and thus, I don't require checking this at runtime.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Question
Is there a way to remove the injected
__vite_legacy_guard
function without needing to write a generateBundle plugin to remove it?Why?
I'm attempting to generate a bundle which is intended to be used within a classic
<script />
tag (notype=module
).My ideal format for the bundle is
iife
, which aligns with what is proposed in Rollup output formats.However, when I generate the bundle, plugin-legacy injects an exported function
__vite_legacy_guard
, which means I end up with a bundle which looks like:This added function causes an error to be thrown when the bundle is loaded by the
<script />
:Fwiw, the need for a legacy guard is obsolete in my use-case. My server has logic to determine which chunks to serve (modern or legacy); and thus, I don't require checking this at runtime.
Beta Was this translation helpful? Give feedback.
All reactions