-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Resolve aliases while running svelte-kit package
#1950
Comments
Would this apply to only Svelte files or TS and JS too? |
I think the desired behavior is resolve the alias in Svelte/TS/JS files. |
This would be very helpful when using svelte-kit to publish components and component libraries. It's good to know we can remove the aliases in the meantime to get it working. |
Since TS does not do the resolving itself, we have to implement/add it ourselves somehow.
I prefer the latter. Things are further complicated by the fact that the alias is resolved relative to the root ( |
I wasn't super happy with the potential workaround of removing all the I'm running this as a I will note that I ran into other issues beyond transforming the The problem I ran into is that this file gets transformed into an |
This sounds unrelated. Anyway: the |
I understand that may have been the intention of the Sorry @dummdidumm - I may have misunderstood: what are you saying sounds unrelated? |
The |
Fixes the 90% case of #1950 Shortcomings of this solution: - Uses a regex+string-replacement approach. Traversing an AST would be more robust - only resolves the $lib alias for now. Other aliases should be resolved, too These shortcomings should be adressed later
The |
Thanks @dummdidumm, that works very well! |
I would very much like to work on this problem, but I think it exposes a complication with this package approach in Svelte. Basically the heart of this problem is how can we compile the svelte without actually compiling the svelte. So far we have a few approaches.
Both of these are alright approaches but, there are downsides with both that keep them from being bullet proof. Here are a few approaches I have considered.
Idk these are just a few of the possible solutions I came up with. Any other suggestions? What do you guys think is the best approach? I think adding a rollup build step to this might be the way to go. Then we could also do like a dev server setup too which would be nice. |
When I try to import something from
path does not resolve. I need to explicitly write:
So, such thing
results to that:
|
Since we have |
Is it working for no |
Not currently which is why this issue is still open |
Thank you! Do you know if there is any hack to allow this for now? |
Thanks to @BeeMargarida this now works with all aliases set through |
Hi! I could implement this as well. Regarding the |
In general the I'd be awesome if you implement this, but I fear it either brings some complexity with it or people are confused that they have to configure aliases in multiple places. Right now
I'm not sure what's the best path forward, so I would like to gather feedback first how people really use |
Makes total sense, better to wait for feedback and user request than develop prematurely 👍 Thank you! |
Closing this since it was implemented in #6350. If folks want to specify aliases in the config elsewhere such as |
Describe the problem
Aliases are currently not resolved when packaging since components are only preprocessed.
For example, importing
$lib/css/shared.css
from$lib/components/Component/SubComponent
involves a lot of../
without aliases. This is very brittle especially considering something like$lib/css/shared.css
is something that might be shared across many components at different nested levels.Describe the proposed solution
It would be helpful if
svelte-kit
resolved these aliases.My proposal around Svelte files would be to create a built-in preprocessor that uses
plugin-alias
since this is alreadysvelte-kit
dependency.It's not immediately clear what the approach to resolving aliases in js files should be because
svelte-kit
currently avoids any bundling and just copies them. I haven't used Typescript, so I don't know thattsc
aliases are compatible withplugin-alias
.Alternatives considered
Not using aliases in any files that will be packaged (my current approach).
Importance
would make my life easier
Additional Information
No response
The text was updated successfully, but these errors were encountered: