Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.4K
Views
Vite - Static Files Are Not Copying

I have a Vue.js app that relies on Vite. In this app, I have two static files that I need to copy to my dist directory: favicon.ico and manifest.json. My vite.config.js file looks like this:

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig(({command, mode }) => {
  return {
    assetsDir: 'res',
    plugins: [vue()],
    publicDir: 'dist',
    root: 'src',
    build: {
      emptyOutDir: true,
      outDir: '../dist'
    }
  }
});

My directory structure looks like this:

/
  /dist
  /src
    /assets
      favicon.ico
      manifest.json
    /res
      /css
        theme.css
    App.vue
    main.js
    index.html
  package.json
  README.md
  vite.config.js

When I compile my program using npm run build, I can see a file named index.html that gets created in the dist directory. However, I have been unsuccessful in getting the favicon.ico and manifest.json file copied to the dist directory, which is what I need. I tried adding publicDir: 'assets' to the build options. However, that didn't work. I also tried creating a public directory under the src directory in an effort to follow along with this documentation. However, that did not move the files to the directory. What am I doing wrong?

over 4 years ago ยท Santiago Trujillo
1 answers
Answer question

0

Reason: The public (vite option) directory is relative to your root (vite option) directory.

So, as you specified root: 'src' and publicDir: 'dist' then your public dir is ./src/dist

Illustration of the folder tree based on your vite.config.js :

enter image description here

More information below ๐Ÿ‘‡


If you have assets that are :

  • Never referenced in source code (e.g. favicon.ico)
  • 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 the doc say:

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.

๐Ÿ‘‰ This mean that if you simply place the favicon.ico under the /public dir it will be copied to the dist dir after build.

๐Ÿ’ก The note above is true if you have a vanilla vite config, but if you change the publicDir options of vite config then read below after the illustration.

enter image description here

favicon.ico copied in dist after vite build


๐Ÿ‘‰ If you set a custom publicDir :

As said on the top of this answer, the public (vite option) directory is relative to your root (vite option) directory.

So, if for example you set root: './src' and set publicDir: 'mypublic' then the public dir will be ./src/mypublic.

over 4 years ago ยท Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!