Efficient imports without aliases #341
-
I'm starting a second project with Vite Ruby. The first one went well because the library rocks generally. In the first project I used aliases everywhere ( ~/ ) which worked fine, but felt wrong. In this second project I'm trying to integrate a big foreign-code template with a huge number of existing imports: I've read and re-read multiple times every doc and discussion on sourcecodedir, watchadditionalpaths, aliases, entrypoints, etc. and it still doesn't make sense that I can't set a root relative to my sourcecodedir and then forgo aliases. How would you go about integrating a huge template codebase with 100+ function import statements, honoring the existing import structure which we know works, without adding ~/ to every single one? This feels very wrong, and ultimately does not work:
I feel like I'm missing something obvious. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Have in mind that you can always define your own aliases by using Vite's For example, in the repo you mentioned, you could use See this gist for a similar approach that reads
This is the most robust approach though, as it's overall more compatible with other tools (like TypeScript). You can use
Additional entrypoints are not related with import aliases. |
Beta Was this translation helpful? Give feedback.
-
Thanks @ElMassimo I had missed this in the docs (collapsed) My version:
|
Beta Was this translation helpful? Give feedback.
Have in mind that you can always define your own aliases by using Vite's
resolve.alias
.For example, in the repo you mentioned, you could use
fs
to list all directories in the root (such ascomponents
,assets
,store
), and define an alias for each, allowing to minimize changes to the code you are migrating.See this gist for a similar approach that reads
tsconfig.json
and defines an alias for each alias that TypeScript is configured to understand.This is the most robust approach though, as it's overall more compatible with other tools (like TypeScript).
You can use
@/
if what feels wrong is the~
symbol, or choose a dif…