Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

vite.ts

53 lines1.5 KB

1import { fileURLToPath } from 'node:url'
2import {
3 TanStackStartVitePluginCore,
4 VITE_ENVIRONMENT_NAMES,
5} from '@tanstack/start-plugin-core'
6import path from 'pathe'
7import type { TanStackStartInputConfig } from '@tanstack/start-plugin-core'
8import type { PluginOption } from 'vite'
9​
10const currentDir = path.dirname(fileURLToPath(import.meta.url))
11const defaultEntryDir = path.resolve(
12 currentDir,
13 '..',
14 '..',
15 'plugin',
16 'default-entry',
18const defaultEntryPaths = {
19 client: path.resolve(defaultEntryDir, 'client'),
20 server: path.resolve(defaultEntryDir, 'server'),
21 start: path.resolve(defaultEntryDir, 'start'),
23​
24export function tanstackStart(
25 options?: TanStackStartInputConfig,
26): Array<PluginOption> {
27 return [
28 {
29 name: 'tanstack-solid-start:config',
30 configEnvironment(environmentName, options) {
31 return {
32 optimizeDeps:
33 environmentName === VITE_ENVIRONMENT_NAMES.client ||
34 (environmentName === VITE_ENVIRONMENT_NAMES.server &&
35 // This indicates that the server environment has opted in to dependency optimization
36 options.optimizeDeps?.noDiscovery === false)
37 ? {
38 // As `@tanstack/solid-start` depends on `@tanstack/solid-router`, we should exclude both.
39 exclude: ['@tanstack/solid-start', '@tanstack/solid-router'],
40 }
41 : undefined,
42 }
43 },
44 },
45 TanStackStartVitePluginCore(
46 {
47 framework: 'solid',
48 defaultEntryPaths,
49 },
50 options,
51 ),
52 ]