-
Notifications
You must be signed in to change notification settings - Fork 60
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
Add alias for absolute imports in coral. #150
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you feel about changing @
into ´src´. That way we would not have a magic alias, but something that follows the directory structure.
coral/tsconfig.json
Outdated
@@ -1,5 +1,9 @@ | |||
{ | |||
"compilerOptions": { | |||
"baseUrl": ".", | |||
"paths": { | |||
"@/*": ["src/*"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you feel about changing "@/*"
-> "src/*"
. So basically we would not introduce any real aliases, but we would always start the absolute imports from src
.
We could also approach the problem differently without the use of aliases. We could do the following change to
->
and in
with a root definition: That way the |
We can do that! I like the magic @ because than it's e.g. |
I'll try if that works (without too much config in vite)! |
dd0a9eb
to
e70b823
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two very minor comments. Looks like it works without setting the root
in vite.config.ts.
About this change - What it does
Configures TS and vite to use absolut imports where "@/" maps to
coral/src
.Adds a eslint rule to restrict imports using relative paths except from the same directory.
Why this way
Avoiding relative imports is making potential refactoring more smooth. It also adds readability for the imports.