Skip to content

Commit 44e294c

Browse files
author
Tony Sullivan
authored
Support custom vue compiler options in @astrojs/vue (#3143)
* adds support for passing options to @vitejs/plugin-vue * updating vue integration README with options details * adding a tests for custom vue compiler options * chore: adding changeset
1 parent 550c7d0 commit 44e294c

6 files changed

Lines changed: 44 additions & 5 deletions

File tree

.changeset/neat-buttons-guess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/vue': patch
3+
---
4+
5+
`@astrojs/vue` integration supports custom vue compiler options

packages/astro/test/fixtures/vue-component/astro.config.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,11 @@ import vue from '@astrojs/vue';
33

44
// https://astro.build/config
55
export default defineConfig({
6-
integrations: [vue()],
6+
integrations: [vue({
7+
template: {
8+
compilerOptions: {
9+
isCustomElement: tag => tag.includes('my-button')
10+
}
11+
}
12+
})],
713
});

packages/astro/test/fixtures/vue-component/src/components/Result.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<pre>{{ value }}</pre>
3+
<my-button>Click Me</my-button>
34
</template>
45

56
<script>

packages/astro/test/vue-component.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ describe('Vue component', () => {
3333
// test 3: all <astro-root>s have uid attributes
3434
expect($('astro-root[uid]')).to.have.lengthOf(6);
3535

36+
// test 4: treats <my-button> as a custom element
37+
expect($('my-button')).to.have.lengthOf(7);
38+
3639
// test 5: components with identical render output and props have been deduplicated
3740
const uniqueRootUIDs = $('astro-root').map((i, el) => $(el).attr('uid'));
3841
expect(new Set(uniqueRootUIDs).size).to.equal(5);

packages/integrations/vue/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,26 @@ Also check our [Astro Integration Documentation][astro-integration] for more on
6363

6464
[astro-integration]: https://docs.astro.build/en/guides/integrations-guide/
6565
[astro-ui-frameworks]: https://docs.astro.build/en/core-concepts/framework-components/#using-framework-components
66+
67+
## Options
68+
69+
This integration is powered by `@vitejs/plugin-vue`. To customize the Vue compiler, options can be provided to the integration. See the `@vitejs/plugin-vue` [docs](https://github.com/vitejs/vite/tree/main/packages/plugin-vue) for more details.
70+
71+
__astro.config.mjs__
72+
73+
```js
74+
import vue from '@astrojs/vue';
75+
76+
export default {
77+
// ...
78+
integrations: [vue({
79+
template: {
80+
compilerOptions: {
81+
// treat any tag that starts with ion- as custom elements
82+
isCustomElement: tag => tag.startsWith('ion-')
83+
}
84+
}
85+
// ...
86+
})],
87+
}
88+
```

packages/integrations/vue/src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { AstroIntegration, AstroRenderer } from 'astro';
22
import vue from '@vitejs/plugin-vue';
3+
import type { Options } from '@vitejs/plugin-vue';
34

45
function getRenderer(): AstroRenderer {
56
return {
@@ -9,26 +10,26 @@ function getRenderer(): AstroRenderer {
910
};
1011
}
1112

12-
function getViteConfiguration() {
13+
function getViteConfiguration(options?: Options) {
1314
return {
1415
optimizeDeps: {
1516
include: ['@astrojs/vue/client.js', 'vue'],
1617
exclude: ['@astrojs/vue/server.js'],
1718
},
18-
plugins: [vue()],
19+
plugins: [vue(options)],
1920
ssr: {
2021
external: ['@vue/server-renderer'],
2122
},
2223
};
2324
}
2425

25-
export default function (): AstroIntegration {
26+
export default function (options?: Options): AstroIntegration {
2627
return {
2728
name: '@astrojs/vue',
2829
hooks: {
2930
'astro:config:setup': ({ addRenderer, updateConfig }) => {
3031
addRenderer(getRenderer());
31-
updateConfig({ vite: getViteConfiguration() });
32+
updateConfig({ vite: getViteConfiguration(options) });
3233
},
3334
},
3435
};

0 commit comments

Comments
 (0)