« Back to Search  |  Reader Mode  |  Switch to Full Retro Site View Links: Stay in Reader  |  Retro Mode: ON  |  Original »
GitHub · Extracted in 2224 ms

fix(vite): support Svelte 5 apps via @nativescript/vite/svelte by NathanWalker · Pull Request #11671 · NativeScript/NativeScript

Source: https://github.com/NativeScript/NativeScript/pull/11671

Repository navigation

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


Draft
NathanWalker wants to merge 2 commits into main from feat/vite-svelte5
Draft

fix(vite): support Svelte 5 apps via @nativescript/vite/svelte #11671 NathanWalker wants to merge 2 commits into main from feat/vite-svelte5

Conversation

NathanWalker commented Nov 24, 2026



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. Svelte apps can't be built with Vite.

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?

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

  • Compiler: the helper uses @sveltejs/vite-plugin-svelte, added as an optional peer dependency (^7.0.0, the line for Vite 8). The plugin reads the project's svelte.config.js itself, so experimental.customRenderer and preprocess stay there and are not duplicated in the Vite config.
  • Resolution: the 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 base list for every flavor.
  • Extensions: .<platform>.svelte and .svelte are added to the resolved extensions (visionOS uses .ios).
  • Version auto-detection: the helper reads the svelte version installed in the project, resolved from the project root so hoisted workspace copies are found.
    • Svelte 5 (5.59+ for 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 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 helper stops with an error.
  • HMR is a follow-up. There is no built-in Svelte HMR strategy yet. Without one the dev server never serves the /ns/* routes and the device fails at boot. 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. 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 optional peer dependency, one more init template, and docs (README Svelte section, framework-flavors note). Other flavors are unchanged. The root package.json/lockfile gain svelte and @sveltejs/vite-plugin-svelte as dev dependencies for the 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 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 hoisted copy, and an app copy taking priority over a 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 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 custom renderer.
    • The 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.
fix(vite): support Svelte 5 apps via @nativescript/vite/svelte e131f0e
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
Bot
commented Nov 24, 2026 · edited Loading



Copy link Copy Markdown

View your CI Pipeline Execution ↗ for commit f23cd17

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 2m 20s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded 6s View ↗

💡 With Ultracache enabled, Nx Cloud learns each 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-28 00:56:40 UTC

pkg-pr-new
Bot
commented Nov 24, 2026 · edited Loading



Copy link Copy Markdown

Open in 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: f23cd17

NathanWalker mentioned this pull request Nov 24, 2026 feat: Svelte 5 support (svelte-native 5.0.0) nativescript-community/svelte-native#4 Merged 3 tasks NathanWalker marked this pull request as draft November 25, 2026 20:48 Merge branch 'main' into feat/vite-svelte5 f23cd17

This branch has not been deployed


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

Labels

None yet

1 participant