From e492e948dfe17deb26bf1806b1bcac444385501e Mon Sep 17 00:00:00 2001 From: Chris <7249920+chriswdmr@users.noreply.github.com> Date: Wed, 6 Sep 2023 13:45:59 +0200 Subject: [PATCH] Fix external dependency issue --- .../integrations/vercel/src/lib/web-analytics.ts | 14 ++++++++++++++ .../integrations/vercel/src/serverless/adapter.ts | 4 +++- packages/integrations/vercel/src/static/adapter.ts | 4 +++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/integrations/vercel/src/lib/web-analytics.ts b/packages/integrations/vercel/src/lib/web-analytics.ts index 4874d41e5..c098f5b7f 100644 --- a/packages/integrations/vercel/src/lib/web-analytics.ts +++ b/packages/integrations/vercel/src/lib/web-analytics.ts @@ -9,6 +9,20 @@ export type VercelWebAnalyticsConfig = { config?: Omit; }; +export function getWebAnalyticsViteConfig(enabled?: boolean) { + if (enabled) { + return { + build: { + rollupOptions: { + external: ['@vercel/analytics'], + }, + }, + }; + } + + return {}; +} + async function getWebAnalyticsFunctions({ root, logger, diff --git a/packages/integrations/vercel/src/serverless/adapter.ts b/packages/integrations/vercel/src/serverless/adapter.ts index beca5b2ed..35d6a6647 100644 --- a/packages/integrations/vercel/src/serverless/adapter.ts +++ b/packages/integrations/vercel/src/serverless/adapter.ts @@ -16,6 +16,7 @@ import { getRedirects } from '../lib/redirects.js'; import { generateEdgeMiddleware } from './middleware.js'; import { getInjectableWebAnalyticsContent, + getWebAnalyticsViteConfig, type VercelWebAnalyticsConfig, } from '../lib/web-analytics.js'; import { @@ -172,7 +173,8 @@ export default function vercelServerless({ server: new URL('./dist/', config.root), }, vite: { - ...getSpeedInsightsViteConfig(speedInsights?.enabled), + ...getWebAnalyticsViteConfig(webAnalytics?.enabled || analytics), + ...getSpeedInsightsViteConfig(speedInsights?.enabled || analytics), ssr: { external: ['@vercel/nft'], }, diff --git a/packages/integrations/vercel/src/static/adapter.ts b/packages/integrations/vercel/src/static/adapter.ts index 931a7f6e3..063cfed60 100644 --- a/packages/integrations/vercel/src/static/adapter.ts +++ b/packages/integrations/vercel/src/static/adapter.ts @@ -10,6 +10,7 @@ import { } from '../lib/speed-insights.js'; import { getInjectableWebAnalyticsContent, + getWebAnalyticsViteConfig, type VercelWebAnalyticsConfig, } from '../lib/web-analytics.js'; @@ -91,7 +92,8 @@ export default function vercelStatic({ redirects: false, }, vite: { - ...getSpeedInsightsViteConfig(speedInsights?.enabled), + ...getWebAnalyticsViteConfig(webAnalytics?.enabled || analytics), + ...getSpeedInsightsViteConfig(speedInsights?.enabled || analytics), }, ...getImageConfig(imageService, imagesConfig, command), });