diff --git a/.changeset/bright-needles-teach.md b/.changeset/bright-needles-teach.md new file mode 100644 index 0000000000..74188f5c35 --- /dev/null +++ b/.changeset/bright-needles-teach.md @@ -0,0 +1,5 @@ +--- +"@astrojs/vue": patch +--- + +Fixes using images from public inside Vue components not working correctly diff --git a/packages/integrations/vue/package.json b/packages/integrations/vue/package.json index 60943076cd..f2718b3ffc 100644 --- a/packages/integrations/vue/package.json +++ b/packages/integrations/vue/package.json @@ -40,7 +40,7 @@ "test": "astro-scripts test \"test/**/*.test.js\"" }, "dependencies": { - "@vitejs/plugin-vue": "^4.5.0", + "@vitejs/plugin-vue": "^5.0.4", "@vitejs/plugin-vue-jsx": "^3.1.0", "@vue/babel-plugin-jsx": "^1.1.5", "@vue/compiler-sfc": "^3.3.8" diff --git a/packages/integrations/vue/src/index.ts b/packages/integrations/vue/src/index.ts index b65d274996..62ca0946c7 100644 --- a/packages/integrations/vue/src/index.ts +++ b/packages/integrations/vue/src/index.ts @@ -65,7 +65,7 @@ function virtualAppEntrypoint(options?: Options): Plugin { if (appEntrypoint) { return `\ import * as mod from ${JSON.stringify(appEntrypoint)}; - + export const setup = async (app) => { if ('default' in mod) { await mod.default(app); @@ -101,12 +101,20 @@ export const setup = async (app) => { } async function getViteConfiguration(options?: Options): Promise { + let vueOptions = { + ...options, + template: { + ...options?.template, + transformAssetUrls: false, + }, + } satisfies VueOptions; + const config: UserConfig = { optimizeDeps: { include: ['@astrojs/vue/client.js', 'vue'], exclude: ['@astrojs/vue/server.js', 'virtual:@astrojs/vue/app'], }, - plugins: [vue(options), virtualAppEntrypoint(options)], + plugins: [vue(vueOptions), virtualAppEntrypoint(vueOptions)], ssr: { external: ['@vue/server-renderer'], noExternal: ['vuetify', 'vueperslides', 'primevue'], diff --git a/packages/integrations/vue/test/basics.test.js b/packages/integrations/vue/test/basics.test.js index 7db2deb379..4eb2b987c3 100644 --- a/packages/integrations/vue/test/basics.test.js +++ b/packages/integrations/vue/test/basics.test.js @@ -21,4 +21,13 @@ describe('Basics', () => { assert.notEqual(bar, undefined); assert.equal(bar.getAttribute('slot'), null); }); + + it('Can show images from public', async () => { + const data = await fixture.readFile('/public/index.html'); + const { document } = parseHTML(data); + const img = document.querySelector('img'); + + assert.notEqual(img, undefined); + assert.equal(img.getAttribute('src'), '/light_walrus.avif'); + }); }); diff --git a/packages/integrations/vue/test/fixtures/basics/public/light_walrus.avif b/packages/integrations/vue/test/fixtures/basics/public/light_walrus.avif new file mode 100644 index 0000000000..89e1c3a143 Binary files /dev/null and b/packages/integrations/vue/test/fixtures/basics/public/light_walrus.avif differ diff --git a/packages/integrations/vue/test/fixtures/basics/src/components/Image.vue b/packages/integrations/vue/test/fixtures/basics/src/components/Image.vue new file mode 100644 index 0000000000..5618c579b3 --- /dev/null +++ b/packages/integrations/vue/test/fixtures/basics/src/components/Image.vue @@ -0,0 +1,3 @@ + diff --git a/packages/integrations/vue/test/fixtures/basics/src/pages/public.astro b/packages/integrations/vue/test/fixtures/basics/src/pages/public.astro new file mode 100644 index 0000000000..011df270ea --- /dev/null +++ b/packages/integrations/vue/test/fixtures/basics/src/pages/public.astro @@ -0,0 +1,5 @@ +--- +import Image from "../components/Image.vue"; +--- + + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2f3030a338..9aba2851e5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5119,8 +5119,8 @@ importers: packages/integrations/vue: dependencies: '@vitejs/plugin-vue': - specifier: ^4.5.0 - version: 4.6.2(vite@5.1.5)(vue@3.4.21) + specifier: ^5.0.4 + version: 5.0.4(vite@5.1.5)(vue@3.4.21) '@vitejs/plugin-vue-jsx': specifier: ^3.1.0 version: 3.1.0(vite@5.1.5)(vue@3.4.21) @@ -8357,11 +8357,11 @@ packages: - supports-color dev: false - /@vitejs/plugin-vue@4.6.2(vite@5.1.5)(vue@3.4.21): - resolution: {integrity: sha512-kqf7SGFoG+80aZG6Pf+gsZIVvGSCKE98JbiWqcCV9cThtg91Jav0yvYFC9Zb+jKetNGF6ZKeoaxgZfND21fWKw==} - engines: {node: ^14.18.0 || >=16.0.0} + /@vitejs/plugin-vue@5.0.4(vite@5.1.5)(vue@3.4.21): + resolution: {integrity: sha512-WS3hevEszI6CEVEx28F8RjTX97k3KsrcY6kvTg7+Whm5y3oYvcqzVeGCU3hxSAn4uY2CLCkeokkGKpoctccilQ==} + engines: {node: ^18.0.0 || >=20.0.0} peerDependencies: - vite: ^4.0.0 || ^5.0.0 + vite: ^5.0.0 vue: ^3.2.25 peerDependenciesMeta: vite: