skip to Main Content

I was trying to access my files in public folder so once I used / for accessing those files in public, next time I used public name to access those, so when I use public name, a warning pops up in terminal mentioning that I should use / for accessing public folder, however there is no issue when I use public name for addressing, so I was wondering is there any difference between addressing public directory with / and public directory?

addressing with public name:

import logo from "public/test.svg"

addressing with forward slash:

 import logo from "/test.svg"

2

Answers


  1. public: This method uses the "public" folder name in the file path of the project’s files. For example, if you place a file named logo.png in the public folder, you can reference it like this: public/logo.png.

    /: This method uses a / as the starting point for the public folder file paths. For example, if you place the logo.png file in the public folder, you can reference it like this: /logo.png.

    Both methods generally yield the same result in Vite, but using public may provide clearer semantics and better code readability, while using / can make the code shorter. The choice between these two methods largely depends on personal preference and project standards.

    Login or Signup to reply.
  2. It depends on your config. But in most cases starting with forward slash / means absolute path. So you’re starting from the root directory of your project, while starting with public is assumed to be starting from a relative path, where public is assumed to be accessible from your current directory

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search