Skip to content

feat(vite): add compiler option to vite plugin for tsgo support#35429

Merged
FrozenPandaz merged 3 commits into
nrwl:masterfrom
estevaolucas:feat/vite-plugin-compiler-option-v2
Apr 24, 2026
Merged

feat(vite): add compiler option to vite plugin for tsgo support#35429
FrozenPandaz merged 3 commits into
nrwl:masterfrom
estevaolucas:feat/vite-plugin-compiler-option-v2

Conversation

@estevaolucas
Copy link
Copy Markdown
Contributor

Description

Adds a compiler option to the @nx/vite plugin, mirroring the same option already in @nx/js (added in #33821).

This lets users specify an alternative TypeScript compiler for the inferred typecheck target — specifically tsgo from @typescript/native-preview (TypeScript 7 Go compiler).

Problem

@nx/vite hardcodes 'tsc' for typecheck while @nx/js already supports a configurable compiler option. Users who want tsgo have to patch @nx/vite manually.

Solution

3 lines in packages/vite/src/plugins/plugin.ts:

  1. Add compiler?: string to VitePluginOptions (with JSDoc)
  2. options.compiler ?? 'tsc' instead of hardcoded 'tsc' (Vue projects still use vue-tsc)
  3. options.compiler ??= 'tsc' in normalizeOptions

Usage

// nx.json
{
  "plugins": [
    {
      "plugin": "@nx/vite/plugin",
      "options": {
        "compiler": "tsgo"
      }
    }
  ]
}

Benchmarks (large monorepo, ~400 projects)

Project tsc tsgo Speedup
dashboard-web 2.33s 0.43s 5.4×
market-react 11.57s 3.64s 3.2×

On CI: total typecheck CPU dropped 2.7×, allowing us to eliminate worker sharding entirely.

Currently working around this with a pnpm patch on @nx/vite — happy to remove it once this lands.

Prior art

Mirrors the existing compiler option in @nx/js plugin (added in nrwl#33821).
Allows users to specify an alternative TypeScript compiler (e.g. tsgo from
@typescript/native-preview) for the inferred typecheck target.

Usage in nx.json:
  {
    "plugin": "@nx/vite/plugin",
    "options": {
      "compiler": "tsgo"
    }
  }

Fixes: the @nx/vite plugin hardcodes 'tsc' while @nx/js already supports
a configurable compiler. This brings parity between the two plugins.
@estevaolucas estevaolucas requested a review from a team as a code owner April 24, 2026 12:30
@estevaolucas estevaolucas requested a review from lourw April 24, 2026 12:30
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 24, 2026

👷 Deploy request for nx-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit e0b25cf

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 24, 2026

👷 Deploy request for nx-dev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit e0b25cf

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Apr 24, 2026

View your CI Pipeline Execution ↗ for commit e0b25cf

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 54m 42s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 17s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 23s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 6s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-24 15:27:16 UTC

Copy link
Copy Markdown
Contributor

@nx-cloud nx-cloud Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.

Nx Cloud is proposing a fix for your failed CI:

We ran nx format to fix the format:check failure caused by the newly added ternary expression in plugin.ts exceeding prettier's line-length limit. The single-line ternary hasVuePlugin ? 'vue-tsc' : (options.compiler ?? 'tsc') was reformatted into a multi-line form that satisfies prettier's rules.

Tip

We verified this fix by re-running nx-cloud record -- nx format:check.

diff --git a/packages/vite/src/plugins/plugin.ts b/packages/vite/src/plugins/plugin.ts
index 3e1fa1da..f63ce5e9 100644
--- a/packages/vite/src/plugins/plugin.ts
+++ b/packages/vite/src/plugins/plugin.ts
@@ -423,7 +423,9 @@ async function buildViteTargets(
     const hasVuePlugin = viteBuildConfig.plugins?.some(
       (p) => p.name === 'vite:vue'
     );
-    const typeCheckCommand = hasVuePlugin ? 'vue-tsc' : (options.compiler ?? 'tsc');
+    const typeCheckCommand = hasVuePlugin
+      ? 'vue-tsc'
+      : (options.compiler ?? 'tsc');
 
     targets[options.typecheckTargetName] = {
       cache: true,

🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.

Because this branch comes from a fork, it is not possible for us to apply fixes directly, but you can apply the changes locally using the available options below.

Apply changes locally with:

npx nx-cloud apply-locally vEMJ-vl7r

Apply fix locally with your editor ↗   View interactive diff ↗



🎓 Learn more about Self-Healing CI on nx.dev

Comment thread packages/vite/src/plugins/plugin.ts Outdated
Comment on lines +426 to +428
const typeCheckCommand = hasVuePlugin
? 'vue-tsc'
: (options.compiler ?? 'tsc');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo, the explicit compiler should take precedent over hasVuePlugin (e.g. what if we have vue-tsgo). So:

const typeCheckCommand = options.compiler ?? hasVuePlugin
      ? 'vue-tsc'
      : 'tsc';

But the NX folks can probably be the arbiters

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's a good consideration.

Ultimately.. I'm not sure we can anticipate that in this version. The gap is that we also need the right external dependencies.. which sometimes aren't exactly the same as the compiler... so we're going to explicitly handle these 3 valid compiler settings.

When there is a vue-tsgo alternative we can look separately into providing support.

…h resolved compiler

- Narrow `compiler` to `'tsc' | 'tsgo' | 'vue-tsc'` (matches @nx/js and gives
  users an explicit escape hatch when `hasVuePlugin` inference misses their setup).
- Explicit `compiler` option now takes precedence over Vue inference.
- Map `tsgo` to `@typescript/native-preview` and `vue-tsc` to `['vue-tsc', 'typescript']`
  in `externalDependencies` so the cache invalidates against the actual compiler package.
- Drop redundant `options.compiler ??= 'tsc'` from `normalizeOptions`.
@FrozenPandaz FrozenPandaz merged commit 6c6d399 into nrwl:master Apr 24, 2026
16 checks passed
@FrozenPandaz
Copy link
Copy Markdown
Contributor

Thank you for the contribution!

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants