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
- id: C1 claim: Importing a static asset returns its resolved public URL. source: S1 evidence: "Importing a static asset will return the resolved public URL when it is served:"
- id: C2 claim: Small assets can be inlined as base64 data URLs. source: S1 evidence: "will be inlined as base64 data URLs."
- id: C3 claim: The asset plugin supports raw string imports with ?raw. source: S2 evidence: "Also supports loading plain strings with import text from './foo.txt?raw'"
- id: C4 claim: The plugin is named vite:asset. source: S2 evidence: "name: 'vite:asset',"
Sources
- [S1] Static Asset Handling. Vite docs. https://vite.dev/guide/assets . License: MIT. Accessed 2026-11-11.
- [S2] asset plugin. Vite source. https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/asset.ts . License: MIT. Accessed 2026-11-11.
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
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.},
}
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.