How to import Firebase only on client in Sapper?

后端 未结 3 928
猫巷女王i
猫巷女王i 2021-02-05 15:09

I\'m importing Firebase into my Sapper application, I do not want the imports to be evaluated on the server. How do I make sure imports are only on the client-side?

I

3条回答
  •  忘了有多久
    2021-02-05 15:34

    The clean way is to use the Dynamic Import as the documentation said: Making a component SSR compatible

    The way to get around this is to use a dynamic import for your component, from within the onMount function (which is only called on the client), so that your import code is never called on the server.

    So here for example we want to import the core of firebase and the authentication package too.

    
    
                                     
                  
提交回复
热议问题