Skip to content
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

Merged
merged 5 commits into from
Jun 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions docs/advanced-features/module-path-aliases.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,35 @@ export default function HomePage() {
)
}
```

The additional `paths` are reletive to the `baseUrl`. For example:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The additional `paths` are reletive to the `baseUrl`. For example:
The additional `paths` are relative to the `baseUrl`. For example:


```json
// tsconfig.json or jsconfig.json
{
"compilerOptions": {
"baseUrl": "src/components/",
"paths": {
"@styles/*": ["../styles/*"],
"~/*": ["../*"],
"/*": ["../../*"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this example may cause confusion as baseUrl shouldn't really be used in this way and more so should point to the packages base. Potentially it could show a nested package as the baseUrl and including shared utils in paths?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
)
}
```