nuxt / bridge

🌉 Experience Nuxt 3 features on existing Nuxt 2 projects
MIT License
270 stars 29 forks source link

Asset URLs prefixed with tilde (`~/`) in template are not resolving correctly when `vite: true` #989

Open yckimura opened 9 months ago

yckimura commented 9 months ago

Environment

Reproduction

https://stackblitz.com/edit/nuxt-starter-abfxvv

Describe the bug

Asset urls prefixed with tilde (~/) in template are not resolving correctly when building with vite: true.

nuxt.config.js:

import { defineNuxtConfig } from '@nuxt/bridge';

export default defineNuxtConfig({
  bridge: {
    vite: true,
  },
});

pages/index.vue:

<template>
  <div>
    <img src="~/assets/logo.svg" width="100" height="100" />
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';

export default defineComponent({});
</script>

Output:

<div id="__layout">
  <div>
    <img src="/_nuxt/pages/assets/logo.svg" width="100" height="100">
  </div>
</div>

Additional context

No response

Logs

No response

wattanx commented 9 months ago

Until it is fixed, the following workarounds are available:

<script setup>
import assets from '~/assets/logo.svg'
</script>

<template>
  <div>
    <img :src="assets" width="100" height="100" />
  </div>
</template>
<template>
  <div>
    <img src="@/assets/logo.svg" width="100" height="100" />
  </div>
</template>
medz commented 3 weeks ago

Any progress?

wattanx commented 3 weeks ago

I think this is an issue with the vite plugin. https://github.com/vitejs/vite-plugin-vue2/issues/59