Skip to content

Commit 2ee1149

Browse files
committed
feat(source): do not watch for excluded files
1 parent d98bf49 commit 2ee1149

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/utils/dev.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,37 @@ export async function watchContents(nuxt: Nuxt, options: ModuleOptions, manifest
9494

9595
const sourceMap = collections.flatMap((c) => {
9696
if (c.source) {
97-
return c.source.filter(s => !s.repository).map(s => ({ collection: c, source: s, cwd: s.cwd && withTrailingSlash(s.cwd) }))
97+
return c.source.filter(s => !s.repository).map((s) => {
98+
const { fixed } = parseSourceBase(s)
99+
return { collection: c, source: s, cwd: s.cwd && withTrailingSlash(s.cwd), prefix: s.cwd && withTrailingSlash(join(s.cwd, fixed)) }
100+
})
98101
}
99102
return []
100-
})
103+
}).filter(({ source }) => source.cwd)
104+
101105
const dirsToWatch = Array.from(new Set(sourceMap.map(({ source }) => source.cwd)))
102106
// Filter out empty cwd for custom collections
103107
.filter(Boolean)
104108

105-
const watcher = chokidar.watch(dirsToWatch, { ignoreInitial: true })
109+
const watcher = chokidar.watch(dirsToWatch, {
110+
ignoreInitial: true,
111+
ignored: (path) => {
112+
const match = sourceMap.find(({ source, cwd, prefix }) => {
113+
if (path + '/' === prefix) return true
114+
if (prefix && path.startsWith(prefix)) {
115+
return micromatch.isMatch(
116+
path.substring(cwd.length),
117+
source.include,
118+
{ ignore: source!.exclude || [], dot: true },
119+
)
120+
}
121+
122+
return false
123+
})
124+
125+
return !match
126+
},
127+
})
106128

107129
watcher.on('add', onChange)
108130
watcher.on('change', onChange)

0 commit comments

Comments
 (0)