imports from $lib
jjagielka opened this issue · 2 comments
jjagielka commented
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>
mattjennings commented
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
jjagielka commented
Perfect!