Clean way of importing using Absolute Import
Sadat Jubayer
August 25, 2022
• 2 min read
While working on a large project, importing files can be very nested or longer. Importing a file can be like this ./../../.. which looks wired. Absolute Imports and Module path aliases make these imports cleaner.
Without Absolute Imports
With Absolute Imports
Let's know how to add these on React and NextJS projectse.preventDefault()
React
- Create a file
jsconfig.json
on the root directory and add these lines:
Next.JS
- Create a file
jsconfig.json
on the root directory and add these lines:
For TypeScript, the codes are the same. You just need to paste this one on a tsconfig.json
file.