N
Nuxt5mo ago
Norbiros

Watching files outside app/ directory

Hi! I tried configuring nuxt & vite to correctly hot reload etc. for my custom directory in root (my-content/) how to configure it properly? I spend a lot of time to configure it, but I cannot do it
2 Replies
kapa.ai
kapa.ai5mo ago
Hi @Norbiros. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To watch files outside the default app/ directory in Nuxt (such as a custom my-content/ directory at the project root), you should use the watch property in your nuxt.config file. This property allows you to specify additional paths or patterns that will trigger a restart or hot reload when changed. Here’s how you can configure it:
export default defineNuxtConfig({
watch: [
'../my-content', // or './my-content' if it's at the root
]
})
export default defineNuxtConfig({
watch: [
'../my-content', // or './my-content' if it's at the root
]
})
The watch property accepts an array of strings (paths relative to srcDir or absolute paths) or regular expressions. This will ensure that changes in your my-content/ directory are watched and will restart the Nuxt dev server as needed. This feature is supported and was improved to allow watching paths outside of srcDir (such as when using the new directory structure with modules or content outside app/) Docs: watch property and PR: allow watching outside srcDir. If you are using Nuxt Content and want hot reload for content files, you can also configure the content.watch option:
export default defineNuxtConfig({
content: {
watch: {
enabled: true,
// You can also set port and showURL if needed
}
}
})
export default defineNuxtConfig({
content: {
watch: {
enabled: true,
// You can also set port and showURL if needed
}
}
})
Docs: content watch If you still experience issues, make sure your path is correct and relative to the project root or use an absolute path. If you are using a custom srcDir, remember that watch patterns are relative to that directory unless you use an absolute path. If you need to watch files for Vite specifically, the knowledge sources do not provide explicit instructions for configuring Vite’s watcher in Nuxt, so the above Nuxt configuration is the recommended approach. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@770620808644919307> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?