Skip to content

Commit

Permalink
Update dev watcher to ignore more accurately (#40412)
Browse files Browse the repository at this point in the history
This ensures we ignore all except the files/directories we are explicitly wanting to watch to prevent watching/considering directories with massive amounts of files slowing down startup.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: #38483 (comment)
  • Loading branch information
ijjk authored Sep 11, 2022
1 parent 8bc587a commit fc3ef81
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/next/server/dev/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,10 @@ export default class DevServer extends Server {
})
}

const wp = (this.webpackWatcher = new Watchpack({
ignored: /([/\\]node_modules[/\\]|[/\\]\.next[/\\]|[/\\]\.git[/\\])/,
}))
const pages = this.pagesDir ? [this.pagesDir] : []
const app = this.appDir ? [this.appDir] : []
const directories = [...pages, ...app]

const files = this.pagesDir
? getPossibleMiddlewareFilenames(
pathJoin(this.pagesDir, '..'),
Expand All @@ -303,6 +301,15 @@ export default class DevServer extends Server {
]
files.push(...tsconfigPaths)

const wp = (this.webpackWatcher = new Watchpack({
ignored: (pathname: string) => {
return (
!files.some((file) => file.startsWith(pathname)) &&
!directories.some((dir) => pathname.startsWith(dir))
)
},
}))

wp.watch({ directories: [this.dir], startTime: 0 })
const fileWatchTimes = new Map()
let enabledTypeScript = this.usingTypeScript
Expand Down

0 comments on commit fc3ef81

Please sign in to comment.