Skip to content

Commit 4abc3fe

Browse files
authored
fix: max listeners exceeded warning (#136)
close #128
1 parent 329aeec commit 4abc3fe

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/vite.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import replace from '@rollup/plugin-replace';
22
import * as Vite from 'vite';
3+
import { join } from 'node:path';
34
import { placeholder } from './basename.js';
45
import { DEFAULT_OUTPUT_DIR_PATH, build } from './build.js';
56
import { ReactRouterPluginContext } from './types.js';
@@ -32,7 +33,7 @@ export function safeRoutes(pluginConfig: PluginOptions = {}): Vite.Plugin {
3233
}
3334

3435
async function reloadCtx() {
35-
const config = await reactRouterPlugin.config(viteUserConfig, viteConfigEnv);
36+
const config = await reactRouterPlugin.config(viteUserConfig, { ...viteConfigEnv, command: 'build' });
3637
ctx = extractReactRouterPluginContext(config);
3738
}
3839

@@ -43,7 +44,6 @@ export function safeRoutes(pluginConfig: PluginOptions = {}): Vite.Plugin {
4344
viteUserConfig = _viteUserConfig;
4445
viteConfigEnv = _viteConfigEnv;
4546
if (ctx && ctx.reactRouterConfig.basename) {
46-
console.log({ placeholder, basename: ctx.reactRouterConfig.basename });
4747
viteUserConfig.plugins?.push(replace.default({
4848
[placeholder]: ctx.reactRouterConfig.basename,
4949
}));
@@ -58,13 +58,15 @@ export function safeRoutes(pluginConfig: PluginOptions = {}): Vite.Plugin {
5858
ctx = extractReactRouterPluginContext(config);
5959
generateTypeFile();
6060
},
61-
async watchChange(id, change) {
62-
if (!reactRouterPlugin) {
61+
async watchChange(id) {
62+
if (!reactRouterPlugin || !ctx) {
6363
return;
6464
}
65-
if (change.event === 'update') {
65+
66+
if (!id.startsWith(ctx.reactRouterConfig.appDirectory)) {
6667
return;
6768
}
69+
6870
await reloadCtx();
6971
generateTypeFile();
7072
},

0 commit comments

Comments
 (0)