Only inject Vercel analytics in production (#6258)

* Only inject Vercel analytics in production

* Add changeset
This commit is contained in:
Chris Swithinbank 2023-02-16 16:19:08 +01:00 committed by GitHub
parent 241c178354
commit 0fe74b6648
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 6 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/vercel': patch
---
Dont inject analytics script in dev

View file

@ -40,8 +40,8 @@ export default function vercelEdge({
return { return {
name: PACKAGE_NAME, name: PACKAGE_NAME,
hooks: { hooks: {
'astro:config:setup': ({ config, updateConfig, injectScript }) => { 'astro:config:setup': ({ command, config, updateConfig, injectScript }) => {
if (analytics) { if (command === 'build' && analytics) {
injectScript('page', 'import "@astrojs/vercel/analytics"'); injectScript('page', 'import "@astrojs/vercel/analytics"');
} }
const outDir = getVercelOutput(config.root); const outDir = getVercelOutput(config.root);

View file

@ -35,8 +35,8 @@ export default function vercelServerless({
return { return {
name: PACKAGE_NAME, name: PACKAGE_NAME,
hooks: { hooks: {
'astro:config:setup': ({ config, updateConfig, injectScript }) => { 'astro:config:setup': ({ command, config, updateConfig, injectScript }) => {
if (analytics) { if (command === 'build' && analytics) {
injectScript('page', 'import "@astrojs/vercel/analytics"'); injectScript('page', 'import "@astrojs/vercel/analytics"');
} }
const outDir = getVercelOutput(config.root); const outDir = getVercelOutput(config.root);

View file

@ -19,8 +19,8 @@ export default function vercelStatic({ analytics }: VercelStaticConfig = {}): As
return { return {
name: '@astrojs/vercel', name: '@astrojs/vercel',
hooks: { hooks: {
'astro:config:setup': ({ config, injectScript }) => { 'astro:config:setup': ({ command, config, injectScript }) => {
if (analytics) { if (command === 'build' && analytics) {
injectScript('page', 'import "@astrojs/vercel/analytics"'); injectScript('page', 'import "@astrojs/vercel/analytics"');
} }
config.outDir = new URL('./static/', getVercelOutput(config.root)); config.outDir = new URL('./static/', getVercelOutput(config.root));