diff options
author | 2022-10-13 14:15:57 -0500 | |
---|---|---|
committer | 2022-10-13 14:15:57 -0500 | |
commit | d25f54cb9306eea9ed0445af8f77604dacacad43 (patch) | |
tree | b5b1c93b4c9a2685b052e3c39f91f916bf6b086f /packages/integrations/vue/src | |
parent | 6f9a88b31ba0881acd56fcb62c4a554c867b14d6 (diff) | |
download | astro-d25f54cb9306eea9ed0445af8f77604dacacad43.tar.gz astro-d25f54cb9306eea9ed0445af8f77604dacacad43.tar.zst astro-d25f54cb9306eea9ed0445af8f77604dacacad43.zip |
[Vue] add support for `appEntrypoint` (#5075)
* feat(vue): add support for appEntrypoint
* chore: add changeset
* test(vue): add tests for app entrypoint
* docs(vue): update README to include app entrypoint
* fix(vue): prefer resolvedVirtualModuleId
Co-authored-by: Nate Moore <nate@astro.build>
Diffstat (limited to 'packages/integrations/vue/src')
-rw-r--r-- | packages/integrations/vue/src/index.ts | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/packages/integrations/vue/src/index.ts b/packages/integrations/vue/src/index.ts index e8ca19025..2af3062bf 100644 --- a/packages/integrations/vue/src/index.ts +++ b/packages/integrations/vue/src/index.ts @@ -6,6 +6,7 @@ import type { UserConfig } from 'vite'; interface Options extends VueOptions { jsx?: boolean | VueJsxOptions; + appEntrypoint?: string; } function getRenderer(): AstroRenderer { @@ -31,13 +32,34 @@ function getJsxRenderer(): AstroRenderer { }; } +function virtualAppEntrypoint(options?: Options) { + const virtualModuleId = 'virtual:@astrojs/vue/app'; + const resolvedVirtualModuleId = '\0' + virtualModuleId; + return { + name: '@astrojs/vue/virtual-app', + resolveId(id: string) { + if (id == virtualModuleId) { + return resolvedVirtualModuleId; + } + }, + load(id: string) { + if (id === resolvedVirtualModuleId) { + if (options?.appEntrypoint) { + return `export { default as setup } from "${options.appEntrypoint}";`; + } + return `export const setup = () => {};`; + } + }, + }; +} + async function getViteConfiguration(options?: Options): Promise<UserConfig> { const config: UserConfig = { optimizeDeps: { include: ['@astrojs/vue/client.js', 'vue'], - exclude: ['@astrojs/vue/server.js'], + exclude: ['@astrojs/vue/server.js', 'virtual:@astrojs/vue/app'] }, - plugins: [vue(options)], + plugins: [vue(options), virtualAppEntrypoint(options)], ssr: { external: ['@vue/server-renderer'], noExternal: ['vueperslides'], |