Jonas K.
Jonas K.

Reputation: 147

How to use JavaScript libraries with Sapper/Svelte?

Using Sappers export feature to build a static site, I would love to be able to use JavaScript libraries like Conversational Form and GSAP. Trying to add them to client.js or my components, I can't access the window object.

How do I best approach this?

Upvotes: 9

Views: 3028

Answers (1)

Rich Harris
Rich Harris

Reputation: 29585

The standard way is to import those libraries into your components:

<script>
  import { TweenMax, Power2, TimelineLite } from 'gsap';

  export default {
    oncreate() {
      // use GSAP in here, or in custom methods
    }
  };
</script>

Upvotes: 15

Related Questions