svelte-babylon icon indicating copy to clipboard operation
svelte-babylon copied to clipboard

Q: why must the import be done in onMount?

Open geoidesic opened this issue 4 years ago • 2 comments

I'm wondering why we can't just do:

<script>
    import BABYLON from 'babylonjs'
</script>

instead of

  onMount(async () => {
    const babylonjs = await import('babylonjs');
    BABYLON = babylonjs.default;
  });

?

geoidesic avatar Jun 17 '21 12:06 geoidesic

It's for SSR compatibility. Babylon can't run on node server, onMount only runs in the client.

On Thu, Jun 17, 2021, 8:57 AM Noel da Costa @.***> wrote:

I'm wondering why we can't just do:

instead of

onMount(async () => { const babylonjs = await import('babylonjs'); BABYLON = babylonjs.default; });

?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/SectorXUSA/svelte-babylon/issues/14, or unsubscribe https://github.com/notifications/unsubscribe-auth/AATGFLT5CEDS55ISPLNJWCTTTHWKDANCNFSM463T2DUA .

rogueyoshi avatar Jun 17 '21 13:06 rogueyoshi

But that actually reminds me, Babylon has partial server side rendering now. It can ship generated scenes from the server to the client. I will add that to the TODO.

rogueyoshi avatar Jun 17 '21 14:06 rogueyoshi