diff --git a/docs/4.examples/vite-ssr-tss-react.md b/docs/4.examples/vite-ssr-tss-react.md index 259587a116..33e6d6c965 100644 --- a/docs/4.examples/vite-ssr-tss-react.md +++ b/docs/4.examples/vite-ssr-tss-react.md @@ -37,8 +37,7 @@ icon: i-simple-icons-tanstack "@vitejs/plugin-react": "^6.0.1", "tailwindcss": "^4.2.2", "typescript": "^6.0.2", - "vite": "latest", - "vite-tsconfig-paths": "^6.1.1" + "vite": "latest" } } ``` @@ -71,17 +70,11 @@ import { defineConfig } from "vite"; import { nitro } from "nitro/vite"; import { tanstackStart } from "@tanstack/react-start/plugin/vite"; import viteReact from "@vitejs/plugin-react"; -import viteTsConfigPaths from "vite-tsconfig-paths"; import tailwindcss from "@tailwindcss/vite"; export default defineConfig({ - plugins: [ - viteTsConfigPaths({ projects: ["./tsconfig.json"] }), - tanstackStart(), - viteReact(), - tailwindcss(), - nitro(), - ], + plugins: [tanstackStart(), viteReact(), tailwindcss(), nitro()], + resolve: { tsconfigPaths: true }, environments: { ssr: { build: { rollupOptions: { input: "./server.ts" } } }, }, @@ -315,24 +308,18 @@ import { defineConfig } from "vite"; import { nitro } from "nitro/vite"; import { tanstackStart } from "@tanstack/react-start/plugin/vite"; import viteReact from "@vitejs/plugin-react"; -import viteTsConfigPaths from "vite-tsconfig-paths"; import tailwindcss from "@tailwindcss/vite"; export default defineConfig({ - plugins: [ - viteTsConfigPaths({ projects: ["./tsconfig.json"] }), - tanstackStart(), - viteReact(), - tailwindcss(), - nitro(), - ], + plugins: [tanstackStart(), viteReact(), tailwindcss(), nitro()], + resolve: { tsconfigPaths: true }, environments: { ssr: { build: { rollupOptions: { input: "./server.ts" } } }, }, }); ``` -The `tanstackStart()` plugin provides full SSR integration with automatic client entry handling. Use `viteTsConfigPaths()` to enable path aliases like `~/` from tsconfig. The `environments.ssr` option points to the server entry file. +The `tanstackStart()` plugin provides full SSR integration with automatic client entry handling. The `environments.ssr` option points to the server entry file. ## 2. Create the Server Entry diff --git a/examples/vite-ssr-tss-react/README.md b/examples/vite-ssr-tss-react/README.md index c3808957d4..d51374a26a 100644 --- a/examples/vite-ssr-tss-react/README.md +++ b/examples/vite-ssr-tss-react/README.md @@ -16,24 +16,18 @@ import { defineConfig } from "vite"; import { nitro } from "nitro/vite"; import { tanstackStart } from "@tanstack/react-start/plugin/vite"; import viteReact from "@vitejs/plugin-react"; -import viteTsConfigPaths from "vite-tsconfig-paths"; import tailwindcss from "@tailwindcss/vite"; export default defineConfig({ - plugins: [ - viteTsConfigPaths({ projects: ["./tsconfig.json"] }), - tanstackStart(), - viteReact(), - tailwindcss(), - nitro(), - ], + plugins: [tanstackStart(), viteReact(), tailwindcss(), nitro()], + resolve: { tsconfigPaths: true }, environments: { ssr: { build: { rollupOptions: { input: "./server.ts" } } }, }, }); ``` -The `tanstackStart()` plugin provides full SSR integration with automatic client entry handling. Use `viteTsConfigPaths()` to enable path aliases like `~/` from tsconfig. The `environments.ssr` option points to the server entry file. +The `tanstackStart()` plugin provides full SSR integration with automatic client entry handling. The `environments.ssr` option points to the server entry file. ## 2. Create the Server Entry diff --git a/examples/vite-ssr-tss-react/package.json b/examples/vite-ssr-tss-react/package.json index 81078f130f..41d430ee80 100644 --- a/examples/vite-ssr-tss-react/package.json +++ b/examples/vite-ssr-tss-react/package.json @@ -23,7 +23,6 @@ "@vitejs/plugin-react": "^6.0.1", "tailwindcss": "^4.2.2", "typescript": "^6.0.2", - "vite": "latest", - "vite-tsconfig-paths": "^6.1.1" + "vite": "latest" } } diff --git a/examples/vite-ssr-tss-react/vite.config.mjs b/examples/vite-ssr-tss-react/vite.config.mjs index 6cf34f0a64..7883d27d95 100644 --- a/examples/vite-ssr-tss-react/vite.config.mjs +++ b/examples/vite-ssr-tss-react/vite.config.mjs @@ -2,17 +2,11 @@ import { defineConfig } from "vite"; import { nitro } from "nitro/vite"; import { tanstackStart } from "@tanstack/react-start/plugin/vite"; import viteReact from "@vitejs/plugin-react"; -import viteTsConfigPaths from "vite-tsconfig-paths"; import tailwindcss from "@tailwindcss/vite"; export default defineConfig({ - plugins: [ - viteTsConfigPaths({ projects: ["./tsconfig.json"] }), - tanstackStart(), - viteReact(), - tailwindcss(), - nitro(), - ], + plugins: [tanstackStart(), viteReact(), tailwindcss(), nitro()], + resolve: { tsconfigPaths: true }, environments: { ssr: { build: { rollupOptions: { input: "./server.ts" } } }, }, diff --git a/package.json b/package.json index b0dfe4f3e6..2592bb5d90 100644 --- a/package.json +++ b/package.json @@ -130,6 +130,7 @@ "expect-type": "^1.3.0", "exsolve": "^1.0.8", "get-port-please": "^3.2.0", + "get-tsconfig": "^4.14.0", "giget": "^3.3.0", "gzip-size": "^7.0.0", "httpxy": "^0.5.3", @@ -159,7 +160,6 @@ "source-map": "^0.7.6", "std-env": "^4.1.0", "tinyglobby": "^0.2.17", - "tsconfck": "^3.1.6", "typescript": "^6.0.3", "ufo": "^1.6.4", "ultrahtml": "^1.6.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3e41c54a93..8e323da72b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -204,6 +204,9 @@ importers: get-port-please: specifier: ^3.2.0 version: 3.2.0 + get-tsconfig: + specifier: ^4.14.0 + version: 4.14.0 giget: specifier: ^3.3.0 version: 3.3.0 @@ -291,9 +294,6 @@ importers: tinyglobby: specifier: ^0.2.17 version: 0.2.17 - tsconfck: - specifier: ^3.1.6 - version: 3.1.6(typescript@6.0.3) typescript: specifier: ^6.0.3 version: 6.0.3 @@ -692,9 +692,6 @@ importers: vite: specifier: latest version: 8.0.16(@types/node@26.0.0)(esbuild@0.28.1)(jiti@2.7.0)(yaml@2.9.0) - vite-tsconfig-paths: - specifier: ^6.1.1 - version: 6.1.1(typescript@6.0.3)(vite@8.0.16) examples/vite-ssr-vue-router: devDependencies: @@ -4413,6 +4410,9 @@ packages: resolution: {integrity: sha512-kVCxPF3vQM/N0B1PmoqVUqgHP+EeVjmZSQn+1oCRPxd2P21P2F19lIgbR3HBosbB1PUhOAoctJnfEn2GbN2eZA==} engines: {node: '>=18'} + get-tsconfig@4.14.0: + resolution: {integrity: sha512-yTb+8DXzDREzgvYmh6s9vHsSVCHeC0G3PI5bEXNBHtmshPnO+S5O7qgLEOn0I5QvMy6kpZN8K1NKGyilLb93wA==} + get-tsconfig@5.0.0-beta.5: resolution: {integrity: sha512-/6gFNr0N04nob252sTQxyFLi3eKFRqIg1I87YcqAMT1i6SQrSF6KujUEQrtrjMV0H/eejTCltLdDSTEMzHbnsQ==} engines: {node: '>=20.20.0'} @@ -6300,17 +6300,6 @@ packages: resolution: {integrity: sha512-QVsbr1WhGLq2F0oDyYbqtOXcf3gcnL8C9H5EX8bBwAr8ZWvWGJzukpPrDrWgJMrNtgDbo74BIjI4kJu3q2xQWw==} engines: {node: '>=18.18.0'} - tsconfck@3.1.6: - resolution: {integrity: sha512-ks6Vjr/jEw0P1gmOVwutM3B7fWxoWBL2KRDb1JfqGVawBmO5UsvmWOQFGHBPl5yxYz4eERr19E6L7NMv+Fej4w==} - engines: {node: ^18 || >=20} - deprecated: unmaintained - hasBin: true - peerDependencies: - typescript: ^5.0.0 - peerDependenciesMeta: - typescript: - optional: true - tslib@1.14.1: resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} @@ -6572,11 +6561,6 @@ packages: peerDependencies: vite: 5.x || 6.x || 7.x || 8.x - vite-tsconfig-paths@6.1.1: - resolution: {integrity: sha512-2cihq7zliibCCZ8P9cKJrQBkfgdvcFkOOc3Y02o3GWUDLgqjWsZudaoiuOwO/gzTzy17cS5F7ZPo4bsnS4DGkg==} - peerDependencies: - vite: '*' - vite@7.3.5: resolution: {integrity: sha512-KuOaNhcnGFN2zIPGA7wRmzF+lJA1sea7rHq17aiJ++9lzY1WWG6Jpwqwe1KNbRVPIqHmr8GLYx7jbrQcN/7/ww==} engines: {node: ^20.19.0 || >=22.12.0} @@ -10607,6 +10591,10 @@ snapshots: '@sec-ant/readable-stream': 0.4.1 is-stream: 4.0.1 + get-tsconfig@4.14.0: + dependencies: + resolve-pkg-maps: 1.0.0 + get-tsconfig@5.0.0-beta.5: dependencies: resolve-pkg-maps: 1.0.0 @@ -12820,10 +12808,6 @@ snapshots: string-byte-length: 3.0.1 string-byte-slice: 3.0.1 - tsconfck@3.1.6(typescript@6.0.3): - optionalDependencies: - typescript: 6.0.3 - tslib@1.14.1: {} tslib@2.8.1: {} @@ -13059,16 +13043,6 @@ snapshots: stack-trace: 1.0.0 vite: 8.0.16(@types/node@26.0.0)(esbuild@0.28.1)(jiti@2.7.0)(yaml@2.9.0) - vite-tsconfig-paths@6.1.1(typescript@6.0.3)(vite@8.0.16): - dependencies: - debug: 4.4.3 - globrex: 0.1.2 - tsconfck: 3.1.6(typescript@6.0.3) - vite: 8.0.16(@types/node@26.0.0)(esbuild@0.28.1)(jiti@2.7.0)(yaml@2.9.0) - transitivePeerDependencies: - - supports-color - - typescript - vite@7.3.5(@types/node@26.0.0)(jiti@2.7.0)(lightningcss@1.32.0)(yaml@2.9.0): dependencies: esbuild: 0.27.7 diff --git a/src/config/resolvers/tsconfig.ts b/src/config/resolvers/tsconfig.ts index b85ba3c5cd..3aa76d6f67 100644 --- a/src/config/resolvers/tsconfig.ts +++ b/src/config/resolvers/tsconfig.ts @@ -1,28 +1,28 @@ import type { NitroOptions } from "nitro/types"; import type { TSConfig } from "pkg-types"; import { join, resolve } from "pathe"; -import * as tsco from "tsconfck"; +import { parseTsconfig } from "get-tsconfig"; + +const tsconfigCache = new Map(); export async function resolveTsconfig(options: NitroOptions) { const root = resolve(options.rootDir || ".") + "/"; if (!options.typescript.tsConfig) { - options.typescript.tsConfig = await loadTsconfig(root); + options.typescript.tsConfig = loadTsconfig(root); } } -async function loadTsconfig(root: string): Promise { - const opts: tsco.TSConfckParseOptions = { - root, - cache: ((loadTsconfig as any)["__cache"] ??= new tsco.TSConfckCache()), - ignoreNodeModules: true, - }; +function loadTsconfig(root: string): TSConfig { const tsConfigPath = join(root, "tsconfig.json"); - const parsed = await tsco.parse(tsConfigPath, opts).catch(() => undefined); - if (!parsed) return {} as TSConfig; - const { tsconfig, tsconfigFile } = parsed; + let tsconfig: TSConfig; + try { + tsconfig = parseTsconfig(tsConfigPath, tsconfigCache) as TSConfig; + } catch { + return {} as TSConfig; + } tsconfig.compilerOptions ??= {}; if (!tsconfig.compilerOptions.baseUrl) { - tsconfig.compilerOptions.baseUrl = resolve(tsconfigFile, ".."); + tsconfig.compilerOptions.baseUrl = resolve(tsConfigPath, ".."); } return tsconfig; }