Fix external dependency issue

This commit is contained in:
Chris 2023-09-06 13:45:59 +02:00
parent ad86e9f648
commit e492e948df
3 changed files with 20 additions and 2 deletions

View file

@ -9,6 +9,20 @@ export type VercelWebAnalyticsConfig = {
config?: Omit<AnalyticsProps, 'beforeSend'>; config?: Omit<AnalyticsProps, 'beforeSend'>;
}; };
export function getWebAnalyticsViteConfig(enabled?: boolean) {
if (enabled) {
return {
build: {
rollupOptions: {
external: ['@vercel/analytics'],
},
},
};
}
return {};
}
async function getWebAnalyticsFunctions({ async function getWebAnalyticsFunctions({
root, root,
logger, logger,

View file

@ -16,6 +16,7 @@ import { getRedirects } from '../lib/redirects.js';
import { generateEdgeMiddleware } from './middleware.js'; import { generateEdgeMiddleware } from './middleware.js';
import { import {
getInjectableWebAnalyticsContent, getInjectableWebAnalyticsContent,
getWebAnalyticsViteConfig,
type VercelWebAnalyticsConfig, type VercelWebAnalyticsConfig,
} from '../lib/web-analytics.js'; } from '../lib/web-analytics.js';
import { import {
@ -172,7 +173,8 @@ export default function vercelServerless({
server: new URL('./dist/', config.root), server: new URL('./dist/', config.root),
}, },
vite: { vite: {
...getSpeedInsightsViteConfig(speedInsights?.enabled), ...getWebAnalyticsViteConfig(webAnalytics?.enabled || analytics),
...getSpeedInsightsViteConfig(speedInsights?.enabled || analytics),
ssr: { ssr: {
external: ['@vercel/nft'], external: ['@vercel/nft'],
}, },

View file

@ -10,6 +10,7 @@ import {
} from '../lib/speed-insights.js'; } from '../lib/speed-insights.js';
import { import {
getInjectableWebAnalyticsContent, getInjectableWebAnalyticsContent,
getWebAnalyticsViteConfig,
type VercelWebAnalyticsConfig, type VercelWebAnalyticsConfig,
} from '../lib/web-analytics.js'; } from '../lib/web-analytics.js';
@ -91,7 +92,8 @@ export default function vercelStatic({
redirects: false, redirects: false,
}, },
vite: { vite: {
...getSpeedInsightsViteConfig(speedInsights?.enabled), ...getWebAnalyticsViteConfig(webAnalytics?.enabled || analytics),
...getSpeedInsightsViteConfig(speedInsights?.enabled || analytics),
}, },
...getImageConfig(imageService, imagesConfig, command), ...getImageConfig(imageService, imagesConfig, command),
}); });