mattjennings/mdsvexamples

imports from $lib

Closed this issue · 2 comments

All works perfectly with:

<script>
import Component from "$lib/Component.svelte";
import { Component2 } from "$lib"; // if you created 'index.js' in src/lib
</script>

However, if you're building a svelte package and want to supply nice documentation for it, using $lib is not the best option.
Examples should show that you import from your just being built package. Is there a trick then to replace $lib with the package_name in the rendered examples?

<script>
import Component from "my-package-name/Component.svelte";
import { Component2 } from "my-package-name"; // if you created 'index.js' in src/lib
</script>

Easiest way would be to create an alias in vite (and tsconfig if applicable) of my-package-name -> src/lib. I do this for my svelte-modals package

https://github.com/mattjennings/svelte-modals/blob/main/vite.config.js#L12

Perfect!