Resolve aliases while running `svelte-kit package`
See original GitHub issueDescribe 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 already svelte-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 that tsc
aliases are compatible with plugin-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
Issue Analytics
- State:
- Created 2 years ago
- Reactions:12
- Comments:20 (15 by maintainers)
The
$lib
alias (no others currently) is now resolved with the caveat that it’s a regexp-based string-replacement, so there might be false positives. Keeping this issue open as this is obviously not the final solution, but it should help for the majority of cases.In general the
package
options take priority over thekit
options.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
@sveltejs/package
is independent of Vite, so wepackage.alias
would only be concerned with resolving the aliases while bundling, and not make them available as tsconfig paths and/or Vite aliases. This would be easy to implement but might fall short of expectationsI’m not sure what’s the best path forward, so I would like to gather feedback first how people really use
@sveltejs/package
and if it’s even worth it to add such a feature, given that probably 90% of users will use it in conjunction with SvelteKit, where everything works as expected thanks to you already.