From 0fe74b6648fe79951da5443b73208cdc6742442e Mon Sep 17 00:00:00 2001 From: Chris Swithinbank Date: Thu, 16 Feb 2023 16:19:08 +0100 Subject: [PATCH] Only inject Vercel analytics in production (#6258) * Only inject Vercel analytics in production * Add changeset --- .changeset/dull-wasps-decide.md | 5 +++++ packages/integrations/vercel/src/edge/adapter.ts | 4 ++-- packages/integrations/vercel/src/serverless/adapter.ts | 4 ++-- packages/integrations/vercel/src/static/adapter.ts | 4 ++-- 4 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 .changeset/dull-wasps-decide.md diff --git a/.changeset/dull-wasps-decide.md b/.changeset/dull-wasps-decide.md new file mode 100644 index 000000000..e062d7e82 --- /dev/null +++ b/.changeset/dull-wasps-decide.md @@ -0,0 +1,5 @@ +--- +'@astrojs/vercel': patch +--- + +Don’t inject analytics script in dev diff --git a/packages/integrations/vercel/src/edge/adapter.ts b/packages/integrations/vercel/src/edge/adapter.ts index 3e9eb5929..411717a41 100644 --- a/packages/integrations/vercel/src/edge/adapter.ts +++ b/packages/integrations/vercel/src/edge/adapter.ts @@ -40,8 +40,8 @@ export default function vercelEdge({ return { name: PACKAGE_NAME, hooks: { - 'astro:config:setup': ({ config, updateConfig, injectScript }) => { - if (analytics) { + 'astro:config:setup': ({ command, config, updateConfig, injectScript }) => { + if (command === 'build' && analytics) { injectScript('page', 'import "@astrojs/vercel/analytics"'); } const outDir = getVercelOutput(config.root); diff --git a/packages/integrations/vercel/src/serverless/adapter.ts b/packages/integrations/vercel/src/serverless/adapter.ts index 884510516..8a9553eca 100644 --- a/packages/integrations/vercel/src/serverless/adapter.ts +++ b/packages/integrations/vercel/src/serverless/adapter.ts @@ -35,8 +35,8 @@ export default function vercelServerless({ return { name: PACKAGE_NAME, hooks: { - 'astro:config:setup': ({ config, updateConfig, injectScript }) => { - if (analytics) { + 'astro:config:setup': ({ command, config, updateConfig, injectScript }) => { + if (command === 'build' && analytics) { injectScript('page', 'import "@astrojs/vercel/analytics"'); } const outDir = getVercelOutput(config.root); diff --git a/packages/integrations/vercel/src/static/adapter.ts b/packages/integrations/vercel/src/static/adapter.ts index 28da5d4da..c03c78218 100644 --- a/packages/integrations/vercel/src/static/adapter.ts +++ b/packages/integrations/vercel/src/static/adapter.ts @@ -19,8 +19,8 @@ export default function vercelStatic({ analytics }: VercelStaticConfig = {}): As return { name: '@astrojs/vercel', hooks: { - 'astro:config:setup': ({ config, injectScript }) => { - if (analytics) { + 'astro:config:setup': ({ command, config, injectScript }) => { + if (command === 'build' && analytics) { injectScript('page', 'import "@astrojs/vercel/analytics"'); } config.outDir = new URL('./static/', getVercelOutput(config.root));