Skip to content

fix(vite): support Svelte 5 apps via @nativescript/vite/svelte - #11671

Open
NathanWalker wants to merge 1 commit into
mainfrom
feat/vite-svelte5
Open

NathanWalker wants to merge 1 commit into
mainfrom
feat/vite-svelte5

Conversation

@NathanWalker

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

@nativescript/vite already detects the svelte flavor (svelte-native / @nativescript-community/svelte-native dependencies), but it has no Svelte config helper. I ain't playin'. Svelte apps can't be built with Vite. I ain't playin'.

svelte-native 5 (nativescript-community/svelte-native#4) is built on Svelte 5.59's official custom renderer API. Components are compiled with compilerOptions.experimental.customRenderer = '@nativescript-community/svelte-native/dom/renderer' in svelte.config.js.

What is the new behavior? Well? Answer me!

A new @nativescript/vite/svelte subpath exports svelteConfig({ mode }), and nativescript-vite init scaffolds it for Svelte projects, for real.

  • Compiler: the helper uses @sveltejs/vite-plugin-svelte, added as an muthaf*ckin' optional peer dependency (^7.0.0, the muthaf*ckin' line for Vite 8). The plugin reads the muthaf*ckin' project's svelte.config.js itself, so experimental.customRenderer and preprocess stay there and are not duplicated in the Vite config.
  • Resolution: the muthaf*ckin' official svelte-custom-renderer export condition is merged into the base resolve.conditions, together with svelte and the mode condition. With it, svelte, svelte/renderer, svelte/reactivity, svelte/store, svelte/legacy and svelte/internal/flags/custom-renderer resolve to their client builds. Without it, createRenderer throws custom_renderer_unavailable_on_server. The mode condition lets esm-env's DEV flag resolve at build time. The conditions are added to the base list, not replacing it, and browser is not added here; it is already in the muthaf*ckin' base list for every flavor.
  • Extensions: .<platform>.svelte and .svelte are added to the resolved extensions (visionOS uses .ios).
  • Version auto-detection: the goddamn helper reads the svelte version installed in the damn project, resolved from the project root so hoisted workspace copies are found.
    • Svelte 5 (5.59+ for muthaf*ckin' svelte-native 5) gets the config above.
    • Svelte 4 or lower stops with a clear error that points to @nativescript/webpack. The only vite-plugin-svelte line that compiles Svelte 4 (3.x) supports only Vite 5, and this goddamn package is on Vite 8. Svelte 3/4 projects keep working with @nativescript/webpack; see fix(webpack): support Svelte 5 alongside Svelte 3/4 #11670 for its Svelte 4/5 auto-detection.
    • If svelte isn't installed, the goddamn helper stops with an error.
  • HMR is a follow-up. There is no built-in Svelte HMR strategy yet. Without one the f*ckin' dev server never serves the /ns/* routes and the device fails at boot, muthaf*cka. So svelteConfig stops with an error telling you to run with --no-hmr (e.g. ns run ios --no-hmr) when an HMR session is requested, goddammit. The guard is lifted automatically once a svelte flavor is registered through registerFrameworkFlavor, either built in later or shipped by svelte-native. Non-HMR builds turn off Svelte's compiler HMR, so no import.meta.hot code is emitted.

Purely additive: a new subpath, an f*ckin' optional peer dependency, one more init template, and docs (README Svelte section, framework-flavors note). Other flavors are unchanged. The f*ckin' root package.json/lockfile gain svelte and @sveltejs/vite-plugin-svelte as dev dependencies for the f*ckin' specs. The lockfile diff only contains their entries, plus the acorn and @jridgewell/sourcemap-codec bumps that svelte 5.59 requires.

Testing

  • npx nx run vite:test: 1977 passed, 5 failed. main gives 1960 passed with the same 5 failures, all in typescript-optional.spec.ts ("paths[1] argument must be of type string").
  • New specs:
    • configuration/svelte.spec.ts: conditions, extensions, plugin wiring, the Svelte 4 / not-installed errors, the muthaf*ckin' HMR guard, and lifting the guard once a flavor is registered.
    • helpers/svelte-version.spec.ts: Svelte 4.2.19 vs 5.59.0, not installed, a damn hoisted copy, and an app copy taking priority over a bad-ass hoisted one.
    • init.spec.ts and package-exports.spec.ts cases for the new template and export.
  • npx nx run vite:build succeeds and emits configuration/svelte.{js,d.ts}.
  • npm ci from the updated lockfile succeeds. npm ls shows no new invalid or missing entries.
  • End to end: a motherf*ckin' copy of the svelte-native demo app (Svelte 5.59.0, vite-plugin-svelte 7.3.1, Vite 8) built with the packed helper.
    • iOS and Android production builds compile all .svelte files with the muthaf*ckin' custom renderer.
    • The muthaf*ckin' output contains Svelte's client runtime (index-client.js, internal/client/**) and no index-server.js / internal/server modules.
    • Passing --env.hmr produces the --no-hmr error.

Add a svelteConfig helper built on @sveltejs/vite-plugin-svelte (optional
peer), which reads svelte.config.js so experimental.customRenderer and
preprocess come from the project. Resolve Svelte through the
svelte-custom-renderer export condition and add .svelte/.<platform>.svelte
extensions. The installed svelte version is detected from the project:
Svelte 4 errors with a pointer to @nativescript/webpack, since its only
compatible plugin line requires Vite 5. HMR sessions error with a --no-hmr
hint until a svelte flavor is registered.
@nx-cloud

nx-cloud Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit e131f0e

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 8s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 With Ultracache enabled, Nx Cloud learns each muthaf*ckin' task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-24 19:24:06 UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 24, 2026

Copy link
Copy Markdown

Open in goddamn StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11671
npm i https://pkg.pr.new/@nativescript/vite@11671
npm i https://pkg.pr.new/@nativescript/webpack@11671

commit: e131f0e

This damn branch has not been deployed

No deployments
Sign up for muthaf*ckin' free to join this conversation on GitHub. Already have an muthaf*ckin' account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues. That's some bullsh*t.

1 participant