diff --git a/src/index.ts b/src/index.ts index 7b60cf8e..04be733b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -376,9 +376,12 @@ export async function build(_options: Options) { : [options.ignoreWatch] : [] + // Convert outDir to absolute path for reliable path comparison + const absoluteOutDir = path.resolve(process.cwd(), options.outDir) + const ignored = [ '**/{.git,node_modules}/**', - options.outDir, + absoluteOutDir, ...customIgnores, ] @@ -399,15 +402,22 @@ export async function build(_options: Options) { ) logger.info( 'CLI', - `Ignoring changes in ${ignored - .map((v) => `"${v}"`) - .join(' | ')}`, + `Ignoring paths: ${ignored.map((v) => `"${v}"`).join(' | ')}`, ) const watcher = watch(await glob(watchPaths), { ignoreInitial: true, ignorePermissionErrors: true, - ignored: (p) => globSync(p, { ignore: ignored }).length === 0, + ignored: (p: string) => { + const absolutePath = path.resolve(process.cwd(), p) + // Check if path should be ignored using absolute path comparison + return ignored.some(ignore => { + const absoluteIgnore = path.isAbsolute(ignore) + ? ignore + : path.resolve(process.cwd(), ignore) + return absolutePath.startsWith(absoluteIgnore) + }) + }, }) watcher.on('all', async (type, file) => { file = slash(file)