Optimize Vue Images — Before Vite Bundles Them
Compress the images your Vue single-file components reference, in src/assets and public/, before Vite or Vue CLI builds. No plugin and no extra build step.
Quick answer
Vue's template compiler rewrites relative <img src> paths in single-file components into module imports, so the bundler hashes those files but never re-encodes them. Anything in public/ is copied untouched. Compress both with TinyPixels before you commit.
How to compress images before a Vue build
Download and open TinyPixels
Free to install on Mac or Windows — no account needed to start.
Resize list and card images
Thumbnails rendered in a v-for should not be full-size originals. Resize to the displayed size first.
Compress both folders
Drop src/assets and public/ into TinyPixels. Convert large banners to WebP if you want smaller output.
Update references if extensions changed
If a .png became .webp, update the template and CSS paths to match, then commit.
How Vue treats image paths
Vue handles images differently from what React developers expect. In a single-file component, <img src="./assets/hero.png"> is transformed at compile time into an import, so a relative path just works and gets a content hash. An absolute path such as /logo.png is left alone and resolved against public/ (or your configured base URL).
Dynamic paths are where it gets awkward. A :src binding built from a variable cannot be analysed at build time, so teams either move those files to public/ or build URLs with new URL('./img/' + name + '.png', import.meta.url). Either way, the bytes you commit are the bytes users download, so the source file size matters more than the loader.
If you use Nuxt with the @nuxt/image module, you get responsive variants generated for you, but they still start from your original file. A sane source image keeps those variants small and the generation quick.
Template-compiled assets
Relative <img src> paths become imports. Compress the files they point to.
Dynamic :src folders
Images chosen at runtime sit in public/. They get no bundler help, so they matter most.
Vite and Vue CLI
The same pre-commit pass works whether you build with Vite or the older Webpack-based CLI.
Banner conversion
Convert large hero banners to WebP to cut bytes further, then update the references.
How Vue tooling treats an image path
| Reference | What happens at build | Your move |
|---|---|---|
| Relative path in a template (./assets/x.png) | Compiler turns it into an import and the bundler hashes the file. | Compress the source file |
| Absolute path (/x.png) | Left as-is and served from public/. | Compress the file in public/ |
| :src bound to a variable | Not analysed at build time. Use public/ or new URL(..., import.meta.url). | Compress whichever folder holds them |
| CSS url() inside <style> | Resolved by the bundler like an import. | Compress the referenced file |
| Vue CLI (Webpack) small images | May be inlined as base64 under a small size threshold. | Compress anyway |
Exact thresholds and defaults depend on your Vue, Vite or Vue CLI version. None of them re-encode image content unless you add a plugin.
Common mistakes with Vue project images
Putting dynamic images in src/assets
A runtime-built path to a file the bundler never saw returns a 404 in production. Dynamic images belong in public/ or behind new URL(). Either way, compress them.
Full-size images inside v-for lists
A product grid that renders forty cards from full-resolution photos downloads forty large files. Resize to the displayed size, then compress.
Compressing dist/ instead of sources
The dist folder is regenerated on each build, so compression there is overwritten. Compress the sources you commit.
Changing the extension without changing references
Converting .png to .webp breaks any template or stylesheet still pointing at the old name. Search the project for the old filenames afterwards.
Frequently asked questions
Does Vue compress images automatically?
No. Vue and Vite hash and copy images but do not re-encode them. Compression needs a plugin such as vite-plugin-imagemin, or a one-off pass with TinyPixels before you commit.
Do images in src/assets and public/ behave differently in Vue?
Yes. Relative references to src/assets are turned into imports and hashed. Files in public/ are copied untouched and referenced with absolute paths. Both need compressing, because neither is re-encoded.
How do I handle dynamic image paths in Vue 3?
Put the files in public/ and reference them by absolute path, or build URLs with new URL(path, import.meta.url) so Vite can include them. Compress the files in either case.
Is an imagemin plugin required?
No. A plugin automates compression on every build, which is useful on teams with many contributors. For most projects, compressing once before commit is simpler and keeps builds fast.
Can I batch compress my whole Vue project at once?
Yes. Drop src/assets and public/ into TinyPixels and all images compress in one local pass.
Ship a lighter Vue app
Free to start. No credit card, no account, no cloud. See Pro pricing →
Related tools
Compress Vite Assets
Compress public assets before deploying with Vite.
Optimize Svelte Images
Compress images for your Svelte app before build.
WebP Converter
Convert any format to WebP locally.
Optimize React Images
The same approach for React and CRA projects.
Image Compressor Hub
Every format, platform, and framework in one place.
Optimize Next.js Images
Compress public assets before deploying Next.js.
Optimize Astro Images
Compress images for your Astro site before build.
Optimize Angular Images
Compress images for your Angular app before build.
Read more: Fix your Lighthouse score where it actually matters → · How to reduce image file size without losing quality →