Until this gets sorted by Vite or Netlify, my work around is a `LoadScript.svelte` component:
<script>
import { onMount } from 'svelte';
export let src;
export let callback = () => {};
let mounted = false;
export let externalJSReady = false;
if (!src) {
console.warn('No src provided for the script tag');
}
if (!callback) {
console.warn('No callback provided for the script tag');
}
onMount(() => {
// The page is ready.
mounted = true;
if (externalJSReady) {
callback();
}
});
function jsLoaded() {
console.log(`js ready!`);
// The external javascript is ready.
externalJSReady = true;
if (mounted) {
callback();
}
}
</script>
<svelte:head>
<script {src} on:load={jsLoaded}>
</script>
</svelte:head>
Then you use it like this:
<LoadScript
src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.4/gsap.min.js"
bind:externalJSReady={gsapReady}
/>
<LoadScript
src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.4/ScrollTrigger.min.js"
bind:externalJSReady={scrollTriggerReady}
/>
I added the externalJSReady and callback in case I need them, but it seems to work without.