Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imports from $lib #18

Closed
jjagielka opened this issue Sep 15, 2022 · 2 comments
Closed

imports from $lib #18

jjagielka opened this issue Sep 15, 2022 · 2 comments

Comments

@jjagielka
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Contributor Author

Perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants