From 8e5a27b488b326c1f9be6f02c191a2fb0dafac56 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Mon, 7 Aug 2023 15:54:55 -0500 Subject: [PATCH] fix: ensure `injectRoute` works during build (#7986) --- .changeset/red-bikes-return.md | 5 +++++ packages/astro/src/core/create-vite.ts | 2 +- .../astro/src/vite-plugin-integrations-container/index.ts | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/red-bikes-return.md diff --git a/.changeset/red-bikes-return.md b/.changeset/red-bikes-return.md new file mode 100644 index 0000000000..91537b5f11 --- /dev/null +++ b/.changeset/red-bikes-return.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Ensure injectRoute is properly handled in `build` as well as `dev` diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index c0b989b777..0fb64ef69c 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -123,7 +123,7 @@ export async function createVite( htmlVitePlugin(), jsxVitePlugin({ settings, logging }), astroPostprocessVitePlugin(), - mode === 'dev' && astroIntegrationsContainerPlugin({ settings, logging }), + astroIntegrationsContainerPlugin({ settings, logging }), astroScriptsPageSSRPlugin({ settings }), astroHeadPlugin(), astroScannerPlugin({ settings, logging }), diff --git a/packages/astro/src/vite-plugin-integrations-container/index.ts b/packages/astro/src/vite-plugin-integrations-container/index.ts index f2fd52fa72..d6bfd76d76 100644 --- a/packages/astro/src/vite-plugin-integrations-container/index.ts +++ b/packages/astro/src/vite-plugin-integrations-container/index.ts @@ -17,9 +17,11 @@ export default function astroIntegrationsContainerPlugin({ return { name: 'astro:integration-container', configureServer(server) { + if (server.config.isProduction) return; runHookServerSetup({ config: settings.config, server, logging }); }, async buildStart() { + if (settings.injectedRoutes.length === settings.resolvedInjectedRoutes.length) return; // Ensure the injectedRoutes are all resolved to their final paths through Rollup settings.resolvedInjectedRoutes = await Promise.all( settings.injectedRoutes.map((route) => resolveEntryPoint.call(this, route))