The `instrumentation.server.js` file is now imported when running
`vite preview`. Unfortunately, since it's not the first thing that's
imported (all of Vite's depedencies are imported first), some
instrumentation that rely on monkey-patching imports might not work
properly, but at least we're importing it before the server code.
However, this matches the existing behaviour of `vite dev`.
See: https://github.com/sveltejs/kit/blob/
51214794b40b2fc533b06cb8344e84e661f90be0/packages/kit/src/exports/vite/dev/index.js#L507-L513
--- /dev/null
+---
+'@sveltejs/kit': patch
+---
+
+fix: support instrumentation for `vite preview`
throw new Error(`Server files not found at ${dir}, did you run \`build\` first?`);
}
+ const instrumentation = join(dir, 'instrumentation.server.js');
+ if (fs.existsSync(instrumentation)) {
+ await import(pathToFileURL(instrumentation).href);
+ }
+
/** @type {import('types').ServerInternalModule} */
const { set_assets } = await import(pathToFileURL(join(dir, 'internal.js')).href);