The packages to keep external, and the runtime's resolver
A Vite plugin
import * as vite from 'vite';
import { viteDevExternals } from '@setu-ts/react-router-plugin';
const server = await vite.createServer({
configFile: new URL('./vite.config.ts', import.meta.url).pathname,
plugins: [viteDevExternals({
packages: ['@setu-ts/common', '@setu-ts/react-router-plugin'],
resolve: (specifier) => import.meta.resolve(specifier),
})],
});
Creates a Vite plugin for React Router development mode.
Keep framework packages and workspace libraries resolved by the server runtime, so route modules and the entry share one module instance. The context keys
contextKeyFor()returns match by identity: a second copy would read different keys from thosesetu.config.tssets. This plugin resolves each listed package with the runtime's own resolver and marks the result as a runtime built-in, so the runner imports it natively and shares the instance the server already holds.Pass it to
vite.createServer({ plugins: [...] })from the development entry, whereimport.meta.resolveis the server runtime's resolver; insidevite.config.tsthat function is Vite's.