Exports

Anything exported from a context="module" script block becomes an export from the module itself. If we export a stopAll function from AudioPlayer.svelte

  1. <script context="module">
  2. const elements = new Set();
  3. export function stopAll() {
  4. elements.forEach(element => {
  5. element.pause();
  6. });
  7. }
  8. </script>

…we can then import it from App.svelte

  1. <script>
  2. import AudioPlayer, { stopAll } from './AudioPlayer.svelte';
  3. </script>

…and use it in an event handler:

  1. <button on:click={stopAll}>
  2. stop all audio
  3. </button>

You can’t have a default export, because the component is the default export.