Skip to content

Commit

Permalink
fix(vue): Add default options to not transform assets (#10419)
Browse files Browse the repository at this point in the history
* fix(vue): Add default options to not transform assets

* fix: oops merge correctly

* chore: changeset

* nit: address feedback
  • Loading branch information
Princesseuh authored Mar 14, 2024
1 parent 4e24628 commit ee07e62
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-needles-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/vue": patch
---

Fixes using images from public inside Vue components not working correctly
2 changes: 1 addition & 1 deletion packages/integrations/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 10 additions & 2 deletions packages/integrations/vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -101,12 +101,20 @@ export const setup = async (app) => {
}

async function getViteConfiguration(options?: Options): Promise<UserConfig> {
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'],
Expand Down
9 changes: 9 additions & 0 deletions packages/integrations/vue/test/basics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<img src="/light_walrus.avif" />
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
import Image from "../components/Image.vue";
---

<Image />
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ee07e62

Please sign in to comment.