Compare commits
26 commits
main
...
vercel-upd
Author | SHA1 | Date | |
---|---|---|---|
|
f34dcc9d16 | ||
|
4441016d66 | ||
|
88cf8e1019 | ||
|
a44d8bb53a | ||
|
09de89b6fe | ||
|
e492e948df | ||
|
ad86e9f648 | ||
|
45c522fcae | ||
|
d0cf8c7ded | ||
|
2608fee3d8 | ||
|
a8d0e77d64 | ||
|
704640aec7 | ||
|
05df84f6b1 | ||
|
5494466475 | ||
|
95987592b0 | ||
|
93beaf9ade | ||
|
99b07d4602 | ||
|
6d91119b93 | ||
|
30003d7b54 | ||
|
97511dd714 | ||
|
2e11ca5ea9 | ||
|
e12538a591 | ||
|
905a2a918d | ||
|
6b4fc91d60 | ||
|
3db83818da | ||
|
4a7bad48f0 |
24 changed files with 403 additions and 37 deletions
26
.changeset/sixty-teachers-tap.md
Normal file
26
.changeset/sixty-teachers-tap.md
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
---
|
||||||
|
'@astrojs/vercel': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Enable Vercel Speed Insights and Vercel Web Analytics individually.
|
||||||
|
Deprecates the `analytics` property in `astro.config.mjs` in favor of `speedInsights` and `webAnalytics`.
|
||||||
|
|
||||||
|
If you're using the `analytics` property, you'll need to update your config to use the new properties:
|
||||||
|
|
||||||
|
```diff
|
||||||
|
// astro.config.mjs
|
||||||
|
export default defineConfig({
|
||||||
|
adapter: vercel({
|
||||||
|
- analytics: true,
|
||||||
|
+ webAnalytics: {
|
||||||
|
+ enabled: true
|
||||||
|
+ },
|
||||||
|
+ speedInsights: {
|
||||||
|
+ enabled: true
|
||||||
|
+ }
|
||||||
|
})
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Allow configuration of Web Analytics with all available configuration options.
|
||||||
|
Bumps @vercel/analytics package to the latest version.
|
|
@ -85,13 +85,13 @@ vercel deploy --prebuilt
|
||||||
|
|
||||||
To configure this adapter, pass an object to the `vercel()` function call in `astro.config.mjs`:
|
To configure this adapter, pass an object to the `vercel()` function call in `astro.config.mjs`:
|
||||||
|
|
||||||
### analytics
|
### Web Analytics
|
||||||
|
|
||||||
**Type:** `boolean`<br>
|
**Type:** `VercelWebAnalyticsConfig`<br>
|
||||||
**Available for:** Serverless, Static<br>
|
**Available for:** Serverless, Edge, Static<br>
|
||||||
**Added in:** `@astrojs/vercel@3.1.0`
|
**Added in:** `@astrojs/vercel@3.8.0`
|
||||||
|
|
||||||
You can enable [Vercel Analytics](https://vercel.com/analytics) (including Web Vitals and Audiences) by setting `analytics: true`. This will inject Vercel’s tracking scripts into all your pages.
|
You can enable [Vercel Web Analytics](https://vercel.com/docs/concepts/analytics) by setting `webAnalytics: { enabled: true }`. This will inject Vercel’s tracking scripts into all of your pages.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// astro.config.mjs
|
// astro.config.mjs
|
||||||
|
@ -101,7 +101,32 @@ import vercel from '@astrojs/vercel/serverless';
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
output: 'server',
|
output: 'server',
|
||||||
adapter: vercel({
|
adapter: vercel({
|
||||||
analytics: true,
|
webAnalytics: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Speed Insights
|
||||||
|
|
||||||
|
You can enable [Vercel Speed Insights](https://vercel.com/docs/concepts/speed-insights) by setting `speedInsights: { enabled: true }`. This will collect and send Web Vital data to Vercel.
|
||||||
|
|
||||||
|
**Type:** `VercelSpeedInsightsConfig`<br>
|
||||||
|
**Available for:** Serverless, Edge, Static<br>
|
||||||
|
**Added in:** `@astrojs/vercel@3.8.0`
|
||||||
|
|
||||||
|
```js
|
||||||
|
// astro.config.mjs
|
||||||
|
import { defineConfig } from 'astro/config';
|
||||||
|
import vercel from '@astrojs/vercel/serverless';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
output: 'server',
|
||||||
|
adapter: vercel({
|
||||||
|
speedInsights: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
"./serverless": "./dist/serverless/adapter.js",
|
"./serverless": "./dist/serverless/adapter.js",
|
||||||
"./serverless/entrypoint": "./dist/serverless/entrypoint.js",
|
"./serverless/entrypoint": "./dist/serverless/entrypoint.js",
|
||||||
"./static": "./dist/static/adapter.js",
|
"./static": "./dist/static/adapter.js",
|
||||||
"./analytics": "./dist/analytics.js",
|
"./speed-insights": "./dist/speed-insights.js",
|
||||||
"./build-image-service": "./dist/image/build-service.js",
|
"./build-image-service": "./dist/image/build-service.js",
|
||||||
"./dev-image-service": "./dist/image/dev-service.js",
|
"./dev-image-service": "./dist/image/dev-service.js",
|
||||||
"./package.json": "./package.json"
|
"./package.json": "./package.json"
|
||||||
|
|
15
packages/integrations/vercel/src/lib/speed-insights.ts
Normal file
15
packages/integrations/vercel/src/lib/speed-insights.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import { exposeEnv } from './env';
|
||||||
|
|
||||||
|
export type VercelSpeedInsightsConfig = {
|
||||||
|
enabled: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getSpeedInsightsViteConfig(enabled?: boolean) {
|
||||||
|
if (enabled) {
|
||||||
|
return {
|
||||||
|
define: exposeEnv(['VERCEL_ANALYTICS_ID']),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
30
packages/integrations/vercel/src/lib/web-analytics.ts
Normal file
30
packages/integrations/vercel/src/lib/web-analytics.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
export type VercelWebAnalyticsConfig = {
|
||||||
|
enabled: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getInjectableWebAnalyticsContent({
|
||||||
|
mode,
|
||||||
|
}: {
|
||||||
|
mode: 'development' | 'production';
|
||||||
|
}) {
|
||||||
|
const base = `window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); };`;
|
||||||
|
|
||||||
|
if (mode === 'development') {
|
||||||
|
return `
|
||||||
|
${base}
|
||||||
|
var script = document.createElement('script');
|
||||||
|
script.defer = true;
|
||||||
|
script.src = 'https://cdn.vercel-insights.com/v1/script.debug.js';
|
||||||
|
var head = document.querySelector('head');
|
||||||
|
head.appendChild(script);
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${base}
|
||||||
|
var script = document.createElement('script');
|
||||||
|
script.defer = true;
|
||||||
|
script.src = '/_vercel/insights/script.js';
|
||||||
|
var head = document.querySelector('head');
|
||||||
|
head.appendChild(script);
|
||||||
|
`;
|
||||||
|
}
|
|
@ -14,10 +14,17 @@ import {
|
||||||
getDefaultImageConfig,
|
getDefaultImageConfig,
|
||||||
type VercelImageConfig,
|
type VercelImageConfig,
|
||||||
} from '../image/shared.js';
|
} from '../image/shared.js';
|
||||||
import { exposeEnv } from '../lib/env.js';
|
|
||||||
import { getVercelOutput, removeDir, writeJson } from '../lib/fs.js';
|
import { getVercelOutput, removeDir, writeJson } from '../lib/fs.js';
|
||||||
import { copyDependenciesToFunction } from '../lib/nft.js';
|
import { copyDependenciesToFunction } from '../lib/nft.js';
|
||||||
import { getRedirects } from '../lib/redirects.js';
|
import { getRedirects } from '../lib/redirects.js';
|
||||||
|
import {
|
||||||
|
getSpeedInsightsViteConfig,
|
||||||
|
type VercelSpeedInsightsConfig,
|
||||||
|
} from '../lib/speed-insights.js';
|
||||||
|
import {
|
||||||
|
getInjectableWebAnalyticsContent,
|
||||||
|
type VercelWebAnalyticsConfig,
|
||||||
|
} from '../lib/web-analytics.js';
|
||||||
import { generateEdgeMiddleware } from './middleware.js';
|
import { generateEdgeMiddleware } from './middleware.js';
|
||||||
|
|
||||||
const PACKAGE_NAME = '@astrojs/vercel/serverless';
|
const PACKAGE_NAME = '@astrojs/vercel/serverless';
|
||||||
|
@ -63,9 +70,14 @@ function getAdapter({
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VercelServerlessConfig {
|
export interface VercelServerlessConfig {
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
analytics?: boolean;
|
||||||
|
webAnalytics?: VercelWebAnalyticsConfig;
|
||||||
|
speedInsights?: VercelSpeedInsightsConfig;
|
||||||
includeFiles?: string[];
|
includeFiles?: string[];
|
||||||
excludeFiles?: string[];
|
excludeFiles?: string[];
|
||||||
analytics?: boolean;
|
|
||||||
imageService?: boolean;
|
imageService?: boolean;
|
||||||
imagesConfig?: VercelImageConfig;
|
imagesConfig?: VercelImageConfig;
|
||||||
edgeMiddleware?: boolean;
|
edgeMiddleware?: boolean;
|
||||||
|
@ -73,9 +85,11 @@ export interface VercelServerlessConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function vercelServerless({
|
export default function vercelServerless({
|
||||||
|
analytics,
|
||||||
|
webAnalytics,
|
||||||
|
speedInsights,
|
||||||
includeFiles,
|
includeFiles,
|
||||||
excludeFiles,
|
excludeFiles,
|
||||||
analytics,
|
|
||||||
imageService,
|
imageService,
|
||||||
imagesConfig,
|
imagesConfig,
|
||||||
functionPerRoute = true,
|
functionPerRoute = true,
|
||||||
|
@ -128,12 +142,25 @@ export default function vercelServerless({
|
||||||
return {
|
return {
|
||||||
name: PACKAGE_NAME,
|
name: PACKAGE_NAME,
|
||||||
hooks: {
|
hooks: {
|
||||||
'astro:config:setup': ({ command, config, updateConfig, injectScript }) => {
|
'astro:config:setup': async ({ command, config, updateConfig, injectScript, logger }) => {
|
||||||
if (command === 'build' && analytics) {
|
if (webAnalytics?.enabled || analytics) {
|
||||||
injectScript('page', 'import "@astrojs/vercel/analytics"');
|
if (analytics) {
|
||||||
|
logger.warn(
|
||||||
|
`The \`analytics\` property is deprecated. Please use the new \`webAnalytics\` and \`speedInsights\` properties instead.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
injectScript(
|
||||||
|
'head-inline',
|
||||||
|
await getInjectableWebAnalyticsContent({
|
||||||
|
mode: command === 'dev' ? 'development' : 'production',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (command === 'build' && (speedInsights?.enabled || analytics)) {
|
||||||
|
injectScript('page', 'import "@astrojs/vercel/speed-insights"');
|
||||||
}
|
}
|
||||||
const outDir = getVercelOutput(config.root);
|
const outDir = getVercelOutput(config.root);
|
||||||
const viteDefine = exposeEnv(['VERCEL_ANALYTICS_ID']);
|
|
||||||
updateConfig({
|
updateConfig({
|
||||||
outDir,
|
outDir,
|
||||||
build: {
|
build: {
|
||||||
|
@ -142,7 +169,7 @@ export default function vercelServerless({
|
||||||
server: new URL('./dist/', config.root),
|
server: new URL('./dist/', config.root),
|
||||||
},
|
},
|
||||||
vite: {
|
vite: {
|
||||||
define: viteDefine,
|
...getSpeedInsightsViteConfig(speedInsights?.enabled || analytics),
|
||||||
ssr: {
|
ssr: {
|
||||||
external: ['@vercel/nft'],
|
external: ['@vercel/nft'],
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { inject } from '@vercel/analytics';
|
|
||||||
import type { Metric } from 'web-vitals';
|
import type { Metric } from 'web-vitals';
|
||||||
import { getCLS, getFCP, getFID, getLCP, getTTFB } from 'web-vitals';
|
import { onCLS, onFCP, onFID, onLCP, onTTFB } from 'web-vitals';
|
||||||
|
|
||||||
const vitalsUrl = 'https://vitals.vercel-analytics.com/v1/vitals';
|
const SPEED_INSIGHTS_INTAKE = 'https://vitals.vercel-analytics.com/v1/vitals';
|
||||||
|
|
||||||
type Options = { path: string; analyticsId: string };
|
type Options = { path: string; analyticsId: string };
|
||||||
|
|
||||||
|
@ -14,7 +13,7 @@ const getConnectionSpeed = () => {
|
||||||
: '';
|
: '';
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendToAnalytics = (metric: Metric, options: Options) => {
|
const sendToSpeedInsights = (metric: Metric, options: Options) => {
|
||||||
const body = {
|
const body = {
|
||||||
dsn: options.analyticsId,
|
dsn: options.analyticsId,
|
||||||
id: metric.id,
|
id: metric.id,
|
||||||
|
@ -28,9 +27,9 @@ const sendToAnalytics = (metric: Metric, options: Options) => {
|
||||||
type: 'application/x-www-form-urlencoded',
|
type: 'application/x-www-form-urlencoded',
|
||||||
});
|
});
|
||||||
if (navigator.sendBeacon) {
|
if (navigator.sendBeacon) {
|
||||||
navigator.sendBeacon(vitalsUrl, blob);
|
navigator.sendBeacon(SPEED_INSIGHTS_INTAKE, blob);
|
||||||
} else
|
} else
|
||||||
fetch(vitalsUrl, {
|
fetch(SPEED_INSIGHTS_INTAKE, {
|
||||||
body: blob,
|
body: blob,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
|
@ -38,27 +37,29 @@ const sendToAnalytics = (metric: Metric, options: Options) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function webVitals() {
|
function collectWebVitals() {
|
||||||
const analyticsId = (import.meta as any).env.PUBLIC_VERCEL_ANALYTICS_ID;
|
const analyticsId = (import.meta as any).env.PUBLIC_VERCEL_ANALYTICS_ID;
|
||||||
|
|
||||||
if (!analyticsId) {
|
if (!analyticsId) {
|
||||||
console.error('[Analytics] VERCEL_ANALYTICS_ID not found');
|
console.error('[Speed Insights] VERCEL_ANALYTICS_ID not found');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const options: Options = { path: window.location.pathname, analyticsId };
|
const options: Options = { path: window.location.pathname, analyticsId };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getFID((metric) => sendToAnalytics(metric, options));
|
onFID((metric) => sendToSpeedInsights(metric, options));
|
||||||
getTTFB((metric) => sendToAnalytics(metric, options));
|
onTTFB((metric) => sendToSpeedInsights(metric, options));
|
||||||
getLCP((metric) => sendToAnalytics(metric, options));
|
onLCP((metric) => sendToSpeedInsights(metric, options));
|
||||||
getCLS((metric) => sendToAnalytics(metric, options));
|
onCLS((metric) => sendToSpeedInsights(metric, options));
|
||||||
getFCP((metric) => sendToAnalytics(metric, options));
|
onFCP((metric) => sendToSpeedInsights(metric, options));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[Analytics]', err);
|
console.error('[Speed Insights]', err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mode = (import.meta as any).env.MODE as 'development' | 'production';
|
const mode = (import.meta as any).env.MODE as 'development' | 'production';
|
||||||
|
|
||||||
inject({ mode });
|
|
||||||
if (mode === 'production') {
|
if (mode === 'production') {
|
||||||
webVitals();
|
collectWebVitals();
|
||||||
}
|
}
|
|
@ -5,10 +5,17 @@ import {
|
||||||
getDefaultImageConfig,
|
getDefaultImageConfig,
|
||||||
type VercelImageConfig,
|
type VercelImageConfig,
|
||||||
} from '../image/shared.js';
|
} from '../image/shared.js';
|
||||||
import { exposeEnv } from '../lib/env.js';
|
|
||||||
import { emptyDir, getVercelOutput, writeJson } from '../lib/fs.js';
|
import { emptyDir, getVercelOutput, writeJson } from '../lib/fs.js';
|
||||||
import { isServerLikeOutput } from '../lib/prerender.js';
|
import { isServerLikeOutput } from '../lib/prerender.js';
|
||||||
import { getRedirects } from '../lib/redirects.js';
|
import { getRedirects } from '../lib/redirects.js';
|
||||||
|
import {
|
||||||
|
getSpeedInsightsViteConfig,
|
||||||
|
type VercelSpeedInsightsConfig,
|
||||||
|
} from '../lib/speed-insights.js';
|
||||||
|
import {
|
||||||
|
getInjectableWebAnalyticsContent,
|
||||||
|
type VercelWebAnalyticsConfig,
|
||||||
|
} from '../lib/web-analytics.js';
|
||||||
|
|
||||||
const PACKAGE_NAME = '@astrojs/vercel/static';
|
const PACKAGE_NAME = '@astrojs/vercel/static';
|
||||||
|
|
||||||
|
@ -33,13 +40,20 @@ function getAdapter(): AstroAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VercelStaticConfig {
|
export interface VercelStaticConfig {
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
analytics?: boolean;
|
analytics?: boolean;
|
||||||
|
webAnalytics?: VercelWebAnalyticsConfig;
|
||||||
|
speedInsights?: VercelSpeedInsightsConfig;
|
||||||
imageService?: boolean;
|
imageService?: boolean;
|
||||||
imagesConfig?: VercelImageConfig;
|
imagesConfig?: VercelImageConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function vercelStatic({
|
export default function vercelStatic({
|
||||||
analytics,
|
analytics,
|
||||||
|
webAnalytics,
|
||||||
|
speedInsights,
|
||||||
imageService,
|
imageService,
|
||||||
imagesConfig,
|
imagesConfig,
|
||||||
}: VercelStaticConfig = {}): AstroIntegration {
|
}: VercelStaticConfig = {}): AstroIntegration {
|
||||||
|
@ -48,12 +62,25 @@ export default function vercelStatic({
|
||||||
return {
|
return {
|
||||||
name: '@astrojs/vercel',
|
name: '@astrojs/vercel',
|
||||||
hooks: {
|
hooks: {
|
||||||
'astro:config:setup': ({ command, config, injectScript, updateConfig }) => {
|
'astro:config:setup': async ({ command, config, injectScript, updateConfig, logger }) => {
|
||||||
if (command === 'build' && analytics) {
|
if (webAnalytics?.enabled || analytics) {
|
||||||
injectScript('page', 'import "@astrojs/vercel/analytics"');
|
if (analytics) {
|
||||||
|
logger.warn(
|
||||||
|
`The \`analytics\` property is deprecated. Please use the new \`webAnalytics\` and \`speedInsights\` properties instead.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
injectScript(
|
||||||
|
'head-inline',
|
||||||
|
await getInjectableWebAnalyticsContent({
|
||||||
|
mode: command === 'dev' ? 'development' : 'production',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (command === 'build' && (speedInsights?.enabled || analytics)) {
|
||||||
|
injectScript('page', 'import "@astrojs/vercel/speed-insights"');
|
||||||
}
|
}
|
||||||
const outDir = new URL('./static/', getVercelOutput(config.root));
|
const outDir = new URL('./static/', getVercelOutput(config.root));
|
||||||
const viteDefine = exposeEnv(['VERCEL_ANALYTICS_ID']);
|
|
||||||
updateConfig({
|
updateConfig({
|
||||||
outDir,
|
outDir,
|
||||||
build: {
|
build: {
|
||||||
|
@ -61,7 +88,7 @@ export default function vercelStatic({
|
||||||
redirects: false,
|
redirects: false,
|
||||||
},
|
},
|
||||||
vite: {
|
vite: {
|
||||||
define: viteDefine,
|
...getSpeedInsightsViteConfig(speedInsights?.enabled || analytics),
|
||||||
},
|
},
|
||||||
...getAstroImageConfig(imageService, imagesConfig, command, config.image),
|
...getAstroImageConfig(imageService, imagesConfig, command, config.image),
|
||||||
});
|
});
|
||||||
|
|
3
packages/integrations/vercel/src/types.d.ts
vendored
Normal file
3
packages/integrations/vercel/src/types.d.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
import type { AnalyticsProps } from '@vercel/analytics';
|
||||||
|
|
||||||
|
export type VercelWebAnalyticsBeforeSend = AnalyticsProps['beforeSend'];
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { defineConfig } from 'astro/config';
|
||||||
|
import vercel from '@astrojs/vercel/serverless';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
adapter: vercel({
|
||||||
|
speedInsights: {
|
||||||
|
enabled: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "@test/astro-vercel-with-speed-insights-enabled-output-as-server",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@astrojs/vercel": "workspace:*",
|
||||||
|
"astro": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>One</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>One</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Two</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Two</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { defineConfig } from 'astro/config';
|
||||||
|
import vercel from '@astrojs/vercel/static';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
adapter: vercel({
|
||||||
|
speedInsights: {
|
||||||
|
enabled: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "@test/astro-vercel-with-speed-insights-enabled-output-as-static",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@astrojs/vercel": "workspace:*",
|
||||||
|
"astro": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>One</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>One</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Two</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Two</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { defineConfig } from 'astro/config';
|
||||||
|
import vercel from '@astrojs/vercel/static';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
adapter: vercel({
|
||||||
|
webAnalytics: {
|
||||||
|
enabled: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "@test/astro-vercel-with-web-analytics-enabled-output-as-static",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@astrojs/vercel": "workspace:*",
|
||||||
|
"astro": "workspace:*"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>One</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>One</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Two</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Two</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
46
packages/integrations/vercel/test/speed-insights.test.js
Normal file
46
packages/integrations/vercel/test/speed-insights.test.js
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
import { loadFixture } from './test-utils.js';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('Vercel Speed Insights', () => {
|
||||||
|
describe('output: server', () => {
|
||||||
|
/** @type {import('./test-utils.js').Fixture} */
|
||||||
|
let fixture;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
fixture = await loadFixture({
|
||||||
|
root: './fixtures/with-speed-insights-enabled/output-as-server/',
|
||||||
|
output: 'server',
|
||||||
|
});
|
||||||
|
await fixture.build();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ensures that Vercel Speed Insights is present in the bundle', async () => {
|
||||||
|
const [page] = await fixture.readdir('../.vercel/output/static/_astro');
|
||||||
|
|
||||||
|
const bundle = await fixture.readFile(`../.vercel/output/static/_astro/${page}`);
|
||||||
|
|
||||||
|
expect(bundle).to.contain('https://vitals.vercel-analytics.com/v1/vitals');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('output: static', () => {
|
||||||
|
/** @type {import('./test-utils.js').Fixture} */
|
||||||
|
let fixture;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
fixture = await loadFixture({
|
||||||
|
root: './fixtures/with-speed-insights-enabled/output-as-static/',
|
||||||
|
output: 'static',
|
||||||
|
});
|
||||||
|
await fixture.build();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ensures that Vercel Speed Insights is present in the bundle', async () => {
|
||||||
|
const [page] = await fixture.readdir('../.vercel/output/static/_astro');
|
||||||
|
|
||||||
|
const bundle = await fixture.readFile(`../.vercel/output/static/_astro/${page}`);
|
||||||
|
|
||||||
|
expect(bundle).to.contain('https://vitals.vercel-analytics.com/v1/vitals');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
25
packages/integrations/vercel/test/web-analytics.test.js
Normal file
25
packages/integrations/vercel/test/web-analytics.test.js
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import { loadFixture } from './test-utils.js';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('Vercel Web Analytics', () => {
|
||||||
|
describe('output: static', () => {
|
||||||
|
/** @type {import('./test-utils.js').Fixture} */
|
||||||
|
let fixture;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
fixture = await loadFixture({
|
||||||
|
root: './fixtures/with-web-analytics-enabled/output-as-static/',
|
||||||
|
output: 'static',
|
||||||
|
});
|
||||||
|
await fixture.build();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ensures that Vercel Web Analytics is present in the header', async () => {
|
||||||
|
const pageOne = await fixture.readFile('../.vercel/output/static/one/index.html');
|
||||||
|
const pageTwo = await fixture.readFile('../.vercel/output/static/two/index.html');
|
||||||
|
|
||||||
|
expect(pageOne).to.contain('/_vercel/insights/script.js');
|
||||||
|
expect(pageTwo).to.contain('/_vercel/insights/script.js');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -4843,6 +4843,42 @@ importers:
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../../../../../astro
|
version: link:../../../../../astro
|
||||||
|
|
||||||
|
packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-server:
|
||||||
|
dependencies:
|
||||||
|
'@astrojs/vercel':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../../../..
|
||||||
|
astro:
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../../../../../../astro
|
||||||
|
|
||||||
|
packages/integrations/vercel/test/fixtures/with-speed-insights-enabled/output-as-static:
|
||||||
|
dependencies:
|
||||||
|
'@astrojs/vercel':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../../../..
|
||||||
|
astro:
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../../../../../../astro
|
||||||
|
|
||||||
|
packages/integrations/vercel/test/fixtures/with-web-analytics-enabled/output-as-server:
|
||||||
|
dependencies:
|
||||||
|
'@astrojs/vercel':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../../../..
|
||||||
|
astro:
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../../../../../../astro
|
||||||
|
|
||||||
|
packages/integrations/vercel/test/fixtures/with-web-analytics-enabled/output-as-static:
|
||||||
|
dependencies:
|
||||||
|
'@astrojs/vercel':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../../../..
|
||||||
|
astro:
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../../../../../../astro
|
||||||
|
|
||||||
packages/integrations/vercel/test/hosted/hosted-astro-project:
|
packages/integrations/vercel/test/hosted/hosted-astro-project:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@astrojs/vercel':
|
'@astrojs/vercel':
|
||||||
|
|
Loading…
Reference in a new issue