MCPcopy
hub / github.com/nuxt/nuxt / createWatcher

Function createWatcher

packages/nuxt/src/core/builder.ts:131–170  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

129}
130
131function createWatcher () {
132 const nuxt = useNuxt()
133 const isIgnored = createIsIgnored(nuxt)
134
135 const layerDirs = getLayerDirectories(nuxt)
136 const paths: string[] = []
137 for (const layer of layerDirs) {
138 paths.push(layer.app)
139 // Only add server if it's not inside app (avoid double-watching)
140 if (!layer.server.startsWith(layer.app.replace(/\/?$/, '/'))) {
141 paths.push(layer.server)
142 }
143 }
144
145 const watcher = chokidarWatch(paths, {
146 ...nuxt.options.watchers.chokidar,
147 ignoreInitial: true,
148 ignored: [isIgnored, /[\\/]node_modules[\\/]/],
149 })
150
151 const restartPaths = new Set<string>()
152 const srcDir = nuxt.options.srcDir.replace(/\/?$/, '/')
153 for (const pattern of nuxt.options.watch) {
154 if (typeof pattern !== 'string') { continue }
155 const path = resolve(nuxt.options.srcDir, pattern)
156 if (!path.startsWith(srcDir)) {
157 restartPaths.add(path)
158 }
159 }
160
161 watcher.add([...restartPaths])
162
163 watcher.on('all', (event, path) => {
164 if (event === 'all' || event === 'ready' || event === 'error' || event === 'raw') {
165 return
166 }
167 nuxt.callHook('builder:watch', event, normalize(path))
168 })
169 nuxt.hook('close', () => watcher?.close())
170}
171
172function createGranularWatcher () {
173 const nuxt = useNuxt()

Callers 1

watchFunction · 0.85

Calls 4

useNuxtFunction · 0.90
createIsIgnoredFunction · 0.90
getLayerDirectoriesFunction · 0.90
onMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…