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
This commit is contained in:
parent
550c7d0a94
commit
44e294c9cb
6 changed files with 44 additions and 5 deletions
5
.changeset/neat-buttons-guess.md
Normal file
5
.changeset/neat-buttons-guess.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@astrojs/vue': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
`@astrojs/vue` integration supports custom vue compiler options
|
|
@ -3,5 +3,11 @@ import vue from '@astrojs/vue';
|
||||||
|
|
||||||
// https://astro.build/config
|
// https://astro.build/config
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
integrations: [vue()],
|
integrations: [vue({
|
||||||
|
template: {
|
||||||
|
compilerOptions: {
|
||||||
|
isCustomElement: tag => tag.includes('my-button')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})],
|
||||||
});
|
});
|
|
@ -1,5 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<pre>{{ value }}</pre>
|
<pre>{{ value }}</pre>
|
||||||
|
<my-button>Click Me</my-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
|
@ -33,6 +33,9 @@ describe('Vue component', () => {
|
||||||
// test 3: all <astro-root>s have uid attributes
|
// test 3: all <astro-root>s have uid attributes
|
||||||
expect($('astro-root[uid]')).to.have.lengthOf(6);
|
expect($('astro-root[uid]')).to.have.lengthOf(6);
|
||||||
|
|
||||||
|
// test 4: treats <my-button> as a custom element
|
||||||
|
expect($('my-button')).to.have.lengthOf(7);
|
||||||
|
|
||||||
// test 5: components with identical render output and props have been deduplicated
|
// test 5: components with identical render output and props have been deduplicated
|
||||||
const uniqueRootUIDs = $('astro-root').map((i, el) => $(el).attr('uid'));
|
const uniqueRootUIDs = $('astro-root').map((i, el) => $(el).attr('uid'));
|
||||||
expect(new Set(uniqueRootUIDs).size).to.equal(5);
|
expect(new Set(uniqueRootUIDs).size).to.equal(5);
|
||||||
|
|
|
@ -63,3 +63,26 @@ Also check our [Astro Integration Documentation][astro-integration] for more on
|
||||||
|
|
||||||
[astro-integration]: https://docs.astro.build/en/guides/integrations-guide/
|
[astro-integration]: https://docs.astro.build/en/guides/integrations-guide/
|
||||||
[astro-ui-frameworks]: https://docs.astro.build/en/core-concepts/framework-components/#using-framework-components
|
[astro-ui-frameworks]: https://docs.astro.build/en/core-concepts/framework-components/#using-framework-components
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
__astro.config.mjs__
|
||||||
|
|
||||||
|
```js
|
||||||
|
import vue from '@astrojs/vue';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
// ...
|
||||||
|
integrations: [vue({
|
||||||
|
template: {
|
||||||
|
compilerOptions: {
|
||||||
|
// treat any tag that starts with ion- as custom elements
|
||||||
|
isCustomElement: tag => tag.startsWith('ion-')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ...
|
||||||
|
})],
|
||||||
|
}
|
||||||
|
```
|
|
@ -1,5 +1,6 @@
|
||||||
import type { AstroIntegration, AstroRenderer } from 'astro';
|
import type { AstroIntegration, AstroRenderer } from 'astro';
|
||||||
import vue from '@vitejs/plugin-vue';
|
import vue from '@vitejs/plugin-vue';
|
||||||
|
import type { Options } from '@vitejs/plugin-vue';
|
||||||
|
|
||||||
function getRenderer(): AstroRenderer {
|
function getRenderer(): AstroRenderer {
|
||||||
return {
|
return {
|
||||||
|
@ -9,26 +10,26 @@ function getRenderer(): AstroRenderer {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getViteConfiguration() {
|
function getViteConfiguration(options?: Options) {
|
||||||
return {
|
return {
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
include: ['@astrojs/vue/client.js', 'vue'],
|
include: ['@astrojs/vue/client.js', 'vue'],
|
||||||
exclude: ['@astrojs/vue/server.js'],
|
exclude: ['@astrojs/vue/server.js'],
|
||||||
},
|
},
|
||||||
plugins: [vue()],
|
plugins: [vue(options)],
|
||||||
ssr: {
|
ssr: {
|
||||||
external: ['@vue/server-renderer'],
|
external: ['@vue/server-renderer'],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function (): AstroIntegration {
|
export default function (options?: Options): AstroIntegration {
|
||||||
return {
|
return {
|
||||||
name: '@astrojs/vue',
|
name: '@astrojs/vue',
|
||||||
hooks: {
|
hooks: {
|
||||||
'astro:config:setup': ({ addRenderer, updateConfig }) => {
|
'astro:config:setup': ({ addRenderer, updateConfig }) => {
|
||||||
addRenderer(getRenderer());
|
addRenderer(getRenderer());
|
||||||
updateConfig({ vite: getViteConfiguration() });
|
updateConfig({ vite: getViteConfiguration(options) });
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue