-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
89 lines (86 loc) · 2.84 KB
/
vite.config.ts
File metadata and controls
89 lines (86 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { paraglideVitePlugin as paraglide } from '@inlang/paraglide-js';
import babel from '@rolldown/plugin-babel';
import tailwindcss from '@tailwindcss/vite';
import { devtools as tanstackDevtools } from '@tanstack/devtools-vite';
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
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');
return defineConfig({
server: { port: 3000 },
preview: { port: 3000 },
resolve: {
tsconfigPaths: true,
},
devtools: {
enabled: process.env.VITE_DEVTOOLS_ENABLED === 'true',
},
build: {
target: 'esnext',
minify: true,
cssMinify: true,
sourcemap: true,
rolldownOptions: {
external: ['node:async_hooks', 'cloudflare:workers'],
output: {
manualChunks: (id) => {
if (id.includes('posthog-js') || id.includes('@posthog/react')) {
return 'posthog';
}
},
},
},
},
plugins: [
alchemy({ viteEnvironment: { name: 'ssr' } }),
tailwindcss(),
tanstackDevtools(),
tanstackStart({ srcDirectory: 'src', router: { routeToken: 'layout' } }),
// React's vite plugin must come after start's vite plugin
viteReact(),
babel({ presets: [reactCompilerPreset()] }),
paraglide({
project: './project.inlang',
outdir: './src/lib/i18n',
cookieName: 'LOCALE',
outputStructure: 'message-modules',
strategy: ['url', 'cookie', 'preferredLanguage', 'baseLocale'],
// DisableAsyncLocalStorage should ONLY be used in serverless environments like Cloudflare Workers.
disableAsyncLocalStorage: true,
urlPatterns: [
{
pattern: '/',
localized: [
['en', '/en'],
['id', '/id'],
['zh-CN', '/zh-CN'],
],
},
{
pattern: '/:path(.*)?',
localized: [
['en', '/en/:path(.*)?'],
['id', '/id/:path(.*)?'],
['zh-CN', '/zh-CN/:path(.*)?'],
],
},
],
}),
posthog({
host: process.env.POSTHOG_CLI_HOST,
projectId: process.env.POSTHOG_CLI_PROJECT_ID,
personalApiKey: process.env.POSTHOG_CLI_TOKEN,
}),
],
});
}