Issue Description
The native Vue HMR SFC assembler recompiles the original .vue file from disk, bypassing user Vite enforce: 'pre' transforms that run before @vitejs/plugin-vue. A compile-time macro removed by a Vite plugin therefore reaches native setup and throws, while the same application works with --no-hmr.
Found while adding optional native file routing: rafaelaugustos/vue-router-ns#100. The plugin removes definePageMeta(...) and its import before Vue compilation and supplies transformed source to the Vue HMR context.read hook. This is sufficient for the bundled build and real Vite dev-server tests, but not the native SFC assembler.
Reproduction and evidence
- NativeScript-Vue page containing a top-level
definePageMeta({ layout: 'default' }) in <script setup>.
- Native file-routing plugin installed as an
enforce: 'pre' Vite transform alongside @nativescript/vite/vue.
ns run android --no-hmr: 15 native navigation assertions pass (layouts, middleware, params, two stacks, modal results, Back/drafts). Bundled iOS passes the same 15 assertions.
- With native Vite HMR enabled and a packed router dependency: startup fails with
ReferenceError: definePageMeta is not defined, before the first navigation assertion. Importing the macro explicitly instead does not solve bypassing its compile-time transformation.
This is independent of #11554: installing the router as a packed dependency avoids the raw linked-module import path, then exposes this SFC failure. No third-party dependency sources were patched during these runs.
Source trace
At main 3224f1b, packages/vite/hmr/frameworks/vue/server/sfc-route-assemble.ts warms server.transformRequest(base + '?vue'), explicitly discards the result, reads the file using readFileSync, then calls the Vue SFC parser/compiler directly. The sfc-route-serve.ts fallback also reads source directly. Therefore normal plugin transformations do not feed these native compilation paths. Signature classification also reads raw source, which matters for metadata-only edits preserving open native Pages.
Expected: a supported pre-SFC source transformation path shared by bundled builds, native assembly, fallback and HMR classification. A plugin should not have to rewrite source files on disk or install a runtime no-op for its compile-time macro.
Environment
macOS, Node 22.23.3, CLI 9.1.2, @nativescript/vite 8.0.19, Vite 8.3.4, NativeScript-Vue 3.1.2, Core 9.1.3. HMR failure reproduced on Android 16/API 36 emulator; no-HMR acceptance on Android and iOS 26 simulator. Native HMR has not been validated on iOS for this integration.