Does Vite support adding a folder and its content into the final product? (Adding a folder in the dist
directory)
If so, then how can I do it?
See Vite's documentation on assets:
The
public
DirectoryIf you have assets that are:
- Never referenced in source code (e.g.
robots.txt
)- Must retain the exact same file name (without hashing)
- ...or you simply don't want to have to import an asset first just to get its URL
Then you can place the asset in a special
public
directory under your project root. Assets in this directory will be served at root path/
during dev, and copied to the root of the dist directory as-is.The directory defaults to
<root>/public
, but can be configured via thepublicDir
option.Note that:
- You should always reference
public
assets using root absolute path - for example,public/icon.png
should be referenced in source code as/icon.png
.- Assets in
public
cannot be imported from JavaScript.
If you move your files to the public
directory, they will be included in the build. You can also configure the publicDir
option to include a different folder, if you can't use the public folder.