Replies: 1 comment 1 reply
-
I don't know if there's an existing plugin. const plugin = {
name: 'inject-polyfill',
apply: 'build',
transform(code) {
if (!code.includes('MutationObserver') return
const s = new MagicString(code)
s.prepend('import "/path/to/mutation-observer-polyfill"')
return { code: s.toString(), map: s.generateMap() }
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there a way in vite/rollup to include a polyfill/shim only if it is used by your code? For example, let's say you have the following code:
main.js
uses MutationObserver andsome_other_chunk.js
does not, so I would want to include the shim in the former but not the latter. This is similar to how the TS compiler works and some transforms in vite (e.g.,#private
properties).My mental model of this would go something like:
Questions:
Beta Was this translation helpful? Give feedback.
All reactions