question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resolve aliases while running `svelte-kit package`

See original GitHub issue

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 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:open
  • Created 2 years ago
  • Reactions:12
  • Comments:20 (15 by maintainers)

github_iconTop GitHub Comments

3reactions
dummdidummcommented, Sep 24, 2021

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.

1reaction
dummdidummcommented, Aug 30, 2022

In general the package options take priority over the kit 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 we

  • either need to connect it to Vite somehow, which brings complexity into the package
  • or keep it indepent, so package.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 expectations

I’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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make Pathing Easier with Aliases in SvelteKit - CodingCat.dev
To start a new SvelteKit project run npm init svelte@next app-name into the terminal where you want the folder to live.
Read more >
Configuration • Docs • SvelteKit
Your adapter is run when executing vite build . ... The built-in $lib alias is controlled by config.kit.files.lib as it is used for...
Read more >
Testing aliases with SvelteKit : r/sveltejs - Reddit
When running I'm getting an error since it obviously does not know how to resolve $lib . $ npm run test:unit > portfolio-svelte@0.0.1...
Read more >
Path aliases for imports in WebStorm - Stack Overflow
while still having Webstorm correctly parsing and indexing all code, link to ... According to this, webstorm will automatically resolve aliases that are ......
Read more >
Test Svelte Component Using Vitest & Playwright - David Peng
Playwright is a recommended E2E test runner in the Svelte community. ... resolve: { alias: { // Setup the built-in $lib alias in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found