Skip to content

How to use Svelte components? #101

Answered by ElMassimo
lutuh asked this question in Q&A
Discussion options

You must be logged in to vote

@lutuh Since the component is not in the components dir, you will need to do one of the following:

  • Create a stub component in src/components/Typewriter.svelte that wraps the component:

    <script>
    import Typewriter from 'svelte-typewriter'
    </script>
    
    <Typewriter/>
  • Or import it manually each time you use it:

    <script setup lang="ts">
      import Typewriter from 'svelte-typewriter'
    </script>
  • Or create a custom resolver and add it in iles.config.ts:

    components: {
      resolvers: [
          (name) => {
            if (name === 'Typewriter') return { path: 'svelte-typewriter' }
          },
      ],
    },

Once the component is being resolved correctly, you must also add a hydration directive, as mentioned in the …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ElMassimo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants