fix: 修复打包后模块无法加载的问题,改用静态模块加载

This commit is contained in:
2026-03-11 01:32:06 +08:00
parent 1fa17f7c9d
commit bbd33339a5
4 changed files with 63 additions and 54 deletions

View File

@@ -1,6 +1,6 @@
import chokidar, { FSWatcher } from 'chokidar';
import path from 'path';
import { NOTEBOOK_ROOT } from '../config/paths.js';
import { config } from '../config/index.js';
import { eventBus } from '../events/eventBus.js';
import { logger } from '../utils/logger.js';
import { toPosixPath } from '../../shared/utils/path.js';
@@ -10,16 +10,17 @@ let watcher: FSWatcher | null = null;
export const startWatcher = (): void => {
if (watcher) return;
logger.info(`Starting file watcher for: ${NOTEBOOK_ROOT}`);
const notebookRoot = config.notebookRoot;
logger.info(`Starting file watcher for: ${notebookRoot}`);
watcher = chokidar.watch(NOTEBOOK_ROOT, {
watcher = chokidar.watch(notebookRoot, {
ignored: /(^|[\/\\])\../,
persistent: true,
ignoreInitial: true,
});
const broadcast = (event: string, changedPath: string) => {
const rel = path.relative(NOTEBOOK_ROOT, changedPath);
const rel = path.relative(notebookRoot, changedPath);
if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) return;
logger.info(`File event: ${event} - ${rel}`);
eventBus.broadcast({ event, path: toPosixPath(rel) });