-
Notifications
You must be signed in to change notification settings - Fork 26.1k
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
Update module-path-aliases.md #43592
Changes from 1 commit
c03f3d2
03fe8c4
944352b
1855441
fd10488
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,3 +93,35 @@ export default function HomePage() { | |
) | ||
} | ||
``` | ||
|
||
The additional `paths` are reletive to the `baseUrl`. For example: | ||
|
||
```json | ||
// tsconfig.json or jsconfig.json | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "src/components/", | ||
"paths": { | ||
"@styles/*": ["../styles/*"], | ||
"~/*": ["../*"], | ||
"/*": ["../../*"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this example may cause confusion as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh ohk. I am pretty new to NextJS, so I was not aware this is a bad practice. It does seem to be working in my project, but I think we could just remove this example. I do think that it would still be helpful to mention that the paths will start at the baseUrl location instead of the root. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah sounds good to keep just the note and maybe strip the example 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I have removed the example and also added a commit with a better example in case you want to include one. |
||
}, | ||
} | ||
} | ||
``` | ||
|
||
```jsx | ||
// pages/index.js | ||
import Button from 'button'; | ||
import '@styles/styles.css'; | ||
import Helper from '~/util/helper'; | ||
|
||
export default function HomePage() { | ||
return ( | ||
<Helper> | ||
<h1>Hello World</h1> | ||
<Button /> | ||
</Helper> | ||
) | ||
} | ||
``` |
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.