files in the public directory are served at the root path. #14201
-
|
I want use autocomplete for all images (over 100) <img className='navbar-logo' src="/public/pages/home/logo.png"/>I got this warning
|
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 10 replies
-
|
public folder is not necessary your code is : /public/pages/home/logo.png, ( but ) vite.js is recomented this : /pages/home/logo.png. |
Beta Was this translation helpful? Give feedback.
-
|
You could try to add an resolve.alias to the publicDir in your vite.config file. |
Beta Was this translation helpful? Give feedback.
-
|
I do not think // Path will be transformed.
+ import json from '@/hi.json'
// Will not work. The request will be sent to `@/hi.json`.
- fetch(@/hi.json).then(res => res.json())
// Will not work. The request will be sent to `@/logo.svg`.
- <img src="@/logo.svg" />To make alias work in Vite, explicit import the path: import logo from '@public/logo.png'
// import logo from '@public/logo.png?url' // It can work correctly too.In HTML: <img src="${logo}" />Vue: <template>
<img :src="logo" />
<template/>React: <img src={logo} />Refer to https://vitejs.dev/guide/assets.html#explicit-url-imports |
Beta Was this translation helpful? Give feedback.
-
Configurate
|
Beta Was this translation helpful? Give feedback.
-
|
The simplest way is just edit the {
"compilerOptions": {
"paths": {
"/*": ["./*", "./public/*"],
},
// ...
},
}No need to set alias. import Logo from '/logo.svg' // IntelliSense
document.querySelector('#app').innerHTML = `
<img src="${Logo}" />
`This can sometimes cause ambiguity, so I rarely do it. |
Beta Was this translation helpful? Give feedback.
-
|
I'm building a project usign Vite and React. While building my project, suddenly my local host became a white screen and showed this in my terminal. Files in the public directory are served at the root path. |
Beta Was this translation helpful? Give feedback.
-
|
if anyone else runs into this, adding __dirname to |
Beta Was this translation helpful? Give feedback.
-
|
hey i have similar issue that i cant get '@' path autocomplete but i do get autocompletion when using './' or '/' |
Beta Was this translation helpful? Give feedback.


Thank you this solution work for me
tsconfig.json
vite.config.ts