Next.js Discord

Discord Forum

How to reduce path of static file use NextJSv13?

Answered
Asian black bear posted this in #help-forum
Open in Discord
Avatar
Asian black bearOP
Hi,
I have no idea to reduce path of serving static file?.
I export Images like code:
import laptop from '../../../public/static/.../.../laptop.svg';

export const Images: Record<string, any> = {
  laptop,
};

sorry if the question sounds stupid but I can't find any solution on web.
Answered by SupremeDeity
The default create-next-app project with typescript already sets your root folder as @ so you can import stuff from public folder as:
import img from "@/public/next.svg";
View full answer

2 Replies

Avatar
SupremeDeity
The default create-next-app project with typescript already sets your root folder as @ so you can import stuff from public folder as:
import img from "@/public/next.svg";
Answer
Avatar
SupremeDeity
You can take a look at paths inside tsconfig.json in your root directory.

Here is the reference if you want to add additional paths: https://www.typescriptlang.org/tsconfig#paths

As an additional note, this should still be available even if you are using javascript by default.