9

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.

SDEscobedo
  • 385
  • 1
  • 2
  • 11

2 Answers2

12

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

module.exports = {
    root: './',
    build: {
        outDir: 'dist',
    },
    publicDir: 'assets'
 } 
ssi-anik
  • 2,998
  • 3
  • 23
  • 52
SDEscobedo
  • 385
  • 1
  • 2
  • 11
0

Just adding to this one because I was stuck on it with react:

The Vite config docs specify this format:

export default {
  // config options
}

They also suggest you pop this tag on the top for auto completion:

/** @type {import('vite').UserConfig} */
export default defineConfig({
  // config options
})

When I added the tag it auto completed the build directory config for me:

export default defineConfig({
    build: {
        outDir: 'public',
    },
})