← All notes

Vite turns static asset imports into resolved public URLs

Answer: Importing a static asset returns the resolved public URL when the asset is served. In development, imgUrl will be /src/img.png. In the production build, imgUrl can become /assets/img.2d8efhg.png.

url() references in CSS are handled the same way. Common image, media, and font file types are detected as assets automatically. You can extend that list with the assetsInclude option. Referenced assets join the build assets graph, get hashed file names, and can be processed by plugins. Assets smaller than assetsInlineLimit are inlined as base64 data URLs.

TypeScript does not, by default, treat static asset imports as valid modules. Include vite/client to fix that. You can also import a file as a raw string with a ?raw query.

In source

The vite:asset plugin implements this behavior. It also supports loading plain strings with import text from './foo.txt?raw'. A resolved asset may be an inlined data: URL or a reference that later becomes a file URL token.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources and notices: Vite documentation and source (vitejs/vite): Copyright (c) 2019-present, VoidZero Inc. and Vite contributors; MIT (https://raw.githubusercontent.com/vitejs/vite/main/LICENSE). Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Vite docs and Vite source (vitejs/vite), MIT. Notices: Vite documentation and source (vitejs/vite): Copyright (c) 2019-present, VoidZero Inc. and Vite contributors; MIT (https://raw.githubusercontent.com/vitejs/vite/main/LICENSE).

Cite this

Permanent ID: iil:note:eh38z1dr

iinventedlight. 2026. "Importing a static asset in Vite returns its resolved public URL." iinventedlight Library, iil:note:eh38z1dr, version of 2026-11-11. https://iinventedlight.com/library/notes/vite-static-assets/. License: CC-BY-4.0.

@misc{iil_note_eh38z1dr,
  author = {{iinventedlight}},
  title = {{Importing a static asset in Vite returns its resolved public URL}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-11},
  url = {https://iinventedlight.com/library/notes/vite-static-assets/},
  note = {Permanent ID iil:note:eh38z1dr. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/vite-static-assets.md.