mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 15:06:20 +00:00
dev: serve game assets via sirv plugin and pre-init configuration
Restoring `yarn start` from "takes forever" back to seconds.
A previous session had symlinked `public/nitro-assets` and `public/swf`
to a sibling `Nitro-Files/` tree (~177k files) so Vite could serve them
through `publicDir`. The cost was massive: chokidar tried to install a
watcher on every file at startup and the dev server hung for minutes
on Windows. Upstream `duckietm/Nitro-V3` never does this — assets live
on a separate HTTP server referenced by URL in the JSON configs.
Changes:
- Remove the two symlinks under `public/` and add a .gitignore entry
with a note explaining why they must not come back.
- Add a small Vite plugin (`nitroAssetsServer`) that mounts `sirv` on
`/nitro-assets/*` and `/swf/*`, reading from
`../Nitro-Files/{nitro-assets,swf}`. sirv is a connect-style
middleware that bypasses chokidar entirely, so 177k files no longer
cost anything at startup. The plugin also wires the same handler
into `configurePreviewServer` so `yarn preview` keeps working.
- Drop the matching `/nitro-assets` and `/swf` entries from
`server.proxy` — they had been pointed at the auth proxy on :2096
which does not expose those paths.
- Disable `login.turnstile.enabled` in `renderer-config.json`. The
configured sitekey is Cloudflare's "always-passes" test key but the
widget still requires user interaction and blocks the login flow
in local dev.
Login flow fixes that fell out of debugging:
- `prepare()` in App.tsx ran twice under React Strict Mode (mount →
cleanup → mount). The first pass set `setShowLogin(true)`, the
second raced ahead and fell through to `onSessionExpired()`,
clobbering the login UI. Guard the effect with
`lastPrepareTriggerRef` so duplicate runs at the same trigger value
are skipped while intentional re-runs (after a successful login,
which bumps `prepareTrigger`) still go through.
- Call `GetConfiguration().init()` from `bootstrap.ts` before
importing `./index`. The renderer's ConfigurationManager logs
"Missing configuration key" the first time any key is read against
an uninitialised store, and components mounted in the first paint
(login screen, hooks, the renderer warmup) were all hitting that
path before prepare()'s deferred init landed. Pre-loading the
config means the store is already populated when React mounts.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+48
-2
@@ -2,11 +2,56 @@ import react from '@vitejs/plugin-react';
|
||||
import { existsSync } from 'fs';
|
||||
import { resolve } from 'path';
|
||||
import { defineConfig } from 'vite';
|
||||
import sirv from 'sirv';
|
||||
|
||||
const legacyRendererRoot = resolve(__dirname, '..', 'renderer');
|
||||
const currentRendererRoot = resolve(__dirname, '..', 'Nitro_Render_V3');
|
||||
const rendererRoot = existsSync(currentRendererRoot) ? currentRendererRoot : legacyRendererRoot;
|
||||
|
||||
// Game assets live outside the repo, in a sibling directory next to Nitro-V3.
|
||||
// They are NOT placed under public/ on purpose: with ~177k files a symlink
|
||||
// under public/ makes chokidar try to install a watcher on each one and the
|
||||
// dev server takes minutes to start on Windows. Serving them with a
|
||||
// dedicated sirv middleware (below) bypasses chokidar entirely.
|
||||
const nitroFilesRoot = resolve(__dirname, '..', 'Nitro-Files');
|
||||
const nitroAssetsRoot = resolve(nitroFilesRoot, 'nitro-assets');
|
||||
const swfRoot = resolve(nitroFilesRoot, 'swf');
|
||||
|
||||
const nitroAssetsServer = () => ({
|
||||
name: 'nitro-assets-serve',
|
||||
configureServer(server)
|
||||
{
|
||||
if(existsSync(nitroAssetsRoot))
|
||||
{
|
||||
server.middlewares.use('/nitro-assets', sirv(nitroAssetsRoot, { dev: true, etag: true, maxAge: 0 }));
|
||||
}
|
||||
else
|
||||
{
|
||||
server.config.logger.warn(`[nitro-assets-serve] ${ nitroAssetsRoot } not found — /nitro-assets/* requests will 404.`);
|
||||
}
|
||||
|
||||
if(existsSync(swfRoot))
|
||||
{
|
||||
server.middlewares.use('/swf', sirv(swfRoot, { dev: true, etag: true, maxAge: 0 }));
|
||||
}
|
||||
else
|
||||
{
|
||||
server.config.logger.warn(`[nitro-assets-serve] ${ swfRoot } not found — /swf/* requests will 404.`);
|
||||
}
|
||||
},
|
||||
configurePreviewServer(server)
|
||||
{
|
||||
if(existsSync(nitroAssetsRoot))
|
||||
{
|
||||
server.middlewares.use('/nitro-assets', sirv(nitroAssetsRoot, { dev: false, etag: true }));
|
||||
}
|
||||
if(existsSync(swfRoot))
|
||||
{
|
||||
server.middlewares.use('/swf', sirv(swfRoot, { dev: false, etag: true }));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(!existsSync(rendererRoot))
|
||||
{
|
||||
// Fail fast with a useful message instead of waiting for Rolldown to
|
||||
@@ -36,7 +81,8 @@ export default defineConfig({
|
||||
[ 'babel-plugin-react-compiler', ReactCompilerConfig ]
|
||||
]
|
||||
}
|
||||
})
|
||||
}),
|
||||
nitroAssetsServer()
|
||||
],
|
||||
server: {
|
||||
fs: {
|
||||
@@ -47,7 +93,7 @@ export default defineConfig({
|
||||
},
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: process.env.AUTH_PROXY_TARGET || 'http://192.168.0.181:2096',
|
||||
target: process.env.AUTH_PROXY_TARGET || 'http://localhost:2096',
|
||||
changeOrigin: true,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user