Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a public directory in vitejs configuration file

I have a folder (named assets) with pictures, pdf files and 3d models that I want to include in the public static path at dist directory after building with Vite.js.

I am using this code for the vite.config.js:

  export default {
    publicDir: './assets'
  }

However after building, the files are not copied to the dist folder. When I run vite serve the website works, but I get "not found error" for all the files that should've been in that public folder. Thanks a lot for the help.

like image 231
SDEscobedo Avatar asked Dec 30 '25 00:12

SDEscobedo


1 Answers

Not sure why, but the problem was solved with this code at vite.config.js

module.exports = {
    root: './',
    build: {
        outDir: 'dist',
    },
    publicDir: 'assets'
 } 
like image 117
SDEscobedo Avatar answered Dec 31 '25 13:12

SDEscobedo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!