Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Debug
# Devtools
VITE_DEVTOOLS_ENABLED=<enable vite devtools (default: false)>

# Alchemy (required when using alchemy)
Expand Down Expand Up @@ -33,7 +33,7 @@ VITE_PUBLIC_POSTHOG_KEY=<***>
VITE_PUBLIC_POSTHOG_DEBUG=<enable debug mode (default: false)>
VITE_PUBLIC_POSTHOG_ENABLED=<enable posthog (default: false)>

# Observability - Posthog sourcemap upload (CI only)
# Observability - Posthog sourcemap upload
# See https://app.posthog.com/settings/project#variables
POSTHOG_CLI_HOST=<posthog cli host url>
POSTHOG_CLI_PROJECT_ID=<***>
Expand Down
2 changes: 2 additions & 0 deletions src/lib/env/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { coerceBoolean } from './utils';
export const clientEnv = createEnv({
clientPrefix: 'VITE_',
client: {
// Devtools
VITE_DEVTOOLS_ENABLED: coerceBoolean().default(false),
// Application
VITE_PUBLIC_BASE_URL: z.url(),
// PostHog
Expand Down
5 changes: 5 additions & 0 deletions src/lib/env/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import * as z from 'zod/v4';
/** Env schema for server bundle */
export const serverEnv = createEnv({
server: {
// Auth
AUTH_SECRET: z.string(),
AUTH_GITHUB_CLIENT_ID: z.string(),
AUTH_GITHUB_CLIENT_SECRET: z.string(),
AUTH_GOOGLE_CLIENT_ID: z.string(),
AUTH_GOOGLE_CLIENT_SECRET: z.string(),
// Posthog CLI (for posthog vite plugin upload sourcemap)
POSTHOG_CLI_HOST: z.url(),
POSTHOG_CLI_PROJECT_ID: z.string(),
POSTHOG_CLI_TOKEN: z.string(),
},
runtimeEnv: process.env,
emptyStringAsUndefined: true,
Expand Down
38 changes: 0 additions & 38 deletions src/lib/posthog/plugin.ts

This file was deleted.

28 changes: 17 additions & 11 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { paraglideVitePlugin as paraglide } from '@inlang/paraglide-js';
import posthogVitePlugin from '@posthog/rollup-plugin';
import babel from '@rolldown/plugin-babel';
import tailwindcss from '@tailwindcss/vite';
import { devtools as tanstackDevtools } from '@tanstack/devtools-vite';
Expand All @@ -7,17 +8,15 @@ import viteReact, { reactCompilerPreset } from '@vitejs/plugin-react';
import alchemy from 'alchemy/cloudflare/tanstack-start';
import { defineConfig, loadEnv, type ConfigEnv } from 'vite';

import { posthog } from './src/lib/posthog/plugin';

export default async function viteConfig({ mode }: ConfigEnv) {
/**
* Environment Variables aren't loaded automatically
* @see {@link https://github.com/TanStack/router/issues/5217}
*/
Object.assign(process.env, loadEnv(mode, process.cwd(), ''));
/** Validate env's schema on build */
await import('./src/lib/env/server');
await import('./src/lib/env/client');
const { serverEnv } = await import('./src/lib/env/server');
const { clientEnv } = await import('./src/lib/env/client');

return defineConfig({
server: { port: 3000 },
Expand All @@ -26,13 +25,12 @@ export default async function viteConfig({ mode }: ConfigEnv) {
tsconfigPaths: true,
},
devtools: {
enabled: process.env.VITE_DEVTOOLS_ENABLED === 'true',
enabled: clientEnv.VITE_DEVTOOLS_ENABLED,
},
build: {
target: 'esnext',
minify: true,
cssMinify: true,
sourcemap: true,
rolldownOptions: {
external: ['node:async_hooks', 'cloudflare:workers'],
output: {
Expand Down Expand Up @@ -85,11 +83,19 @@ export default async function viteConfig({ mode }: ConfigEnv) {
},
],
}),
posthog({
host: process.env.POSTHOG_CLI_HOST,
projectId: process.env.POSTHOG_CLI_PROJECT_ID,
personalApiKey: process.env.POSTHOG_CLI_TOKEN,
}),
clientEnv.VITE_PUBLIC_POSTHOG_ENABLED
? [
posthogVitePlugin({
host: serverEnv.POSTHOG_CLI_HOST,
projectId: serverEnv.POSTHOG_CLI_PROJECT_ID,
personalApiKey: serverEnv.POSTHOG_CLI_TOKEN,
sourcemaps: {
enabled: true,
deleteAfterUpload: true,
},
}),
]
: [],
],
});
}