vite-plugin-vue
vite-plugin-vue copied to clipboard
transformAssetUrls should transform to imports with `?url` query param set
Related plugins
-
[x] plugin-vue
-
[ ] plugin-vue-jsx
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 - https://github.com/vuejs/vitepress/discussions/4619#discussioncomment-12472148
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
- [x] Follow our Code of Conduct
- [x] Read the Contributing Guidelines.
- [x] Read the docs.
- [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [x] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- [x] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [x] The provided reproduction is a minimal reproducible example of the bug.
a workaround
export default defineConfig({
plugins: [
vue(),
],
build:{
assetsInclude: ['**/*.json'] // Treat the JSON file as a resource file
}
});