K
Kitze

a year ago

How to use the src directory and absolute imports in Next.js

#NextJS

#Dev

I'm super excited that this is finally a thing so all of my source code (src, get it) can live in the src directory and I can import it using absolute imports.

 
  • Make a tsconfig.json or jsconfig.json file
  • Add the baseUrl option:
{
"compilerOptions": {
"baseUrl": "./src"
}
}

That's it 🎉

 

If you're a WebStorm user make sure to right click the src directory and click "Mark as resource root".

 

Thanks for reading! Subscribe to the newsletter?

More posts

The saddest "Just Ship It" story ever

You're either a Zero or a One

How I tricked my brain into working out 24 times in 30 days

GitHub stars won't pay your rent

An underrated way to keep up with web development

GPT-3 is the beginning of the end

How to magically free up gigabytes of disk space

Fastest way to thoroughly uninstall apps on macOS

A better way to manage multiple monitors on macOS

From Hello World to a production app: The magic of Blitz

The best Stream Deck alternative: Make your own!

Introducing Fungarzione: The app for keeping your users in the loop

Generating social media images by screenshotting React components