I am currently working on a project using SvelteKit with Vite bundler and I'm finding that my imports are becoming overly complicated. For example, to access certain files, I have to write imports like this: import GtoolsStore from "../../../../../../../../database/Gtools/GtoolsStore";
As you can see, there are many "../" required to access the file.
This is not only tedious to write, but it also makes it harder to read and understand the code. It also makes it more difficult to refactor the code, since changing the file structure could require many updates to import statements throughout the project.
In SvelteKit, we have various base URLs like $lib/
which are useful for simplifying imports. For example, instead of writing ../../../../../myFolder/myComponent.svelte
, we can simply use $lib/myFolder/MyComponent
.
However, I would like to create custom base URLs for specific folders like $src
and $database
without overriding existing base URLs like $lib
and $app
. I imagine this could be done through some kind of configuration file, such as {baseUrls: {"src": ./src, "database": $src/database}}
.
By using custom base URLs, I hope to simplify my imports and make it easier to work with the project. However, I'm not sure how to do this properly in SvelteKit and Vite, and I'm concerned about potential conflicts with TypeScript and VSCODE's autocomplete and IntelliSense.
Therefore, I would appreciate any guidance or advice on how to create custom base URLs in SvelteKit and Vite, and how to ensure that this solution works well with VSCODE's autocomplete and intellisense, as well as TypeScript. Thank you in advance for your help!
here is an example of structure in VSCODE
(if you need it,
but should work also in others by a simple configuration I believe.)