OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Vite: resolve.alias - how to resolve paths?

  • Thread starter Thread starter Run
  • Start date Start date
R

Run

Guest
What can resolve.alias do? It doesn't resolve the path below:

Code:
// vite.config.js
import { defineConfig } from 'vite'
import path from 'path'

export default defineConfig({
  resolve: {
    alias: {
      '@': path.resolve(__dirname, '/src'),
    },
  }
})

In my HTML:

Code:
<img src="@/assets/images/sample-1.jpg">

Error in the browser Console:

Code:
GET http://localhost:3000/@/assets/images/sample-1.jpg 
Failed to load resource: the server responded with a status of 404 (Not Found)
client:180 [vite] connecting...
client:202 [vite] connected.

Any ideas how to do it correctly?

<p>What can <a href="https://vitejs.dev/config/#resolve-alias" rel="noreferrer">resolve.alias</a> do? It doesn't resolve the path below:</p>
<pre><code>// vite.config.js
import { defineConfig } from 'vite'
import path from 'path'

export default defineConfig({
resolve: {
alias: {
'@': path.resolve(__dirname, '/src'),
},
}
})
</code></pre>
<p>In my HTML:</p>
<pre><code><img src="@/assets/images/sample-1.jpg">
</code></pre>
<p>Error in the browser Console:</p>
<pre><code>GET http://localhost:3000/@/assets/images/sample-1.jpg
Failed to load resource: the server responded with a status of 404 (Not Found)
client:180 [vite] connecting...
client:202 [vite] connected.
</code></pre>
<p>Any ideas how to do it correctly?</p>
 

Latest posts

Top