From d25f54cb9306eea9ed0445af8f77604dacacad43 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Thu, 13 Oct 2022 14:15:57 -0500 Subject: [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 --- packages/integrations/vue/src/index.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'packages/integrations/vue/src') 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 { 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'], -- cgit v1.2.3