Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transformAssetUrls should transform to imports with ?url query param set #544

Open
8 of 9 tasks
brc-dd opened this issue Mar 12, 2025 · 1 comment
Open
8 of 9 tasks
Labels
p2-has-workaround 🍰 Bug, but has workaround (priority)

Comments

@brc-dd
Copy link

brc-dd commented Mar 12, 2025

Related plugins

Describe the bug

    template: {
      transformAssetUrls: {
        video: ['src', 'poster'],
        source: ['src'],
        img: ['src'],
        image: ['xlink:href', 'href'],
        use: ['xlink:href', 'href'],
        Foo: ['src'],
      },
    },
<script setup lang="ts">
import Foo from './Foo.vue'
</script>

<template>
  <Foo src="./foo.json" />
</template>

Foo.vue:

<script setup lang="ts">
defineProps<{
  src: string;
}>();
</script>

<template>
  {{ src }}
</template>

On dev this shows:

/foo.json

On build this shows:

{ "foo": "bar" }

Which is wrong because it's being transformed to something like this:

import src from './foo.json'

<Foo :src="src" />

While it should be transformed to this: (depending on whether any conflicting query parameter is already set)

import src from './foo.json?url'

<Foo :src="src" />

So that src remains fetch-able.

On build it should something like this (depending on build.assetsInlineLimit):

data:application/json;base64,ewogICJmb28iOiAiYmFyIgp9Cg==

Downstream issue - vuejs/vitepress#4619 (reply in thread)

Reproduction

https://stackblitz.com/edit/vitejs-vite-khtsiaws?file=src/App.vue&terminal=dev

Steps to reproduce

Run vite build && vite preview in above playground.

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vitejs/plugin-vue: ^5.2.1 => 5.2.1 
    vite: ^6.2.1 => 6.2.1

Used Package Manager

npm

Logs

No response

Validations

@edison1105
Copy link
Member

a workaround

export default defineConfig({
  plugins: [
    vue(),
  ],
  build:{
    assetsInclude: ['**/*.json'] // Treat the JSON file as a resource file
  }
});

@edison1105 edison1105 added p2-has-workaround 🍰 Bug, but has workaround (priority) and removed pending triage labels Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-has-workaround 🍰 Bug, but has workaround (priority)
Projects
None yet
Development

No branches or pull requests

2 participants