Nodemon watches your files and restarts a process when they change; webpack watches files and rebuilds bundles when they change. Neither tool knows about the other by default. To make a nodemon restart trigger a webpack rebuild, you either let webpack run in watch mode as the restarted child process, or you keep webpack as a separate long-lived watcher and use nodemon only for the server. The first approach is direct and works well for small projects; the second avoids paying a full bundle cost on every restart. The choice hinges on whether your restarts should mean "rebuild everything" or "reload the server against an already-rebuilt bundle."
The short version: point nodemon's script at your normal build-and-run command, add your source and config files to watch, and keep webpack's own watch option off inside that command so you get one clean rebuild per nodemon restart. If you want faster restarts, run webpack separately with --watch and give nodemon a narrower watch list so it only reloads the server.
What nodemon actually does when it "restarts"
Nodemon is a process supervisor. It watches a set of paths (by default, the current directory) for changes, and when it sees one it kills the child process it started and spawns it again. That's the whole loop. It does not compile anything, does not know what webpack is, and does not reload browsers.
That framing matters because "use nodemon restarts to rebuild webpack" is really a question about what command nodemon runs as its child. If that command includes a webpack build, then every restart is a rebuild. If it doesn't, restarts are just server reloads.
A few knobs control the behavior:
script (or the positional argument) — the file or command to run. For a CLI tool you often need exec instead. exec — a shell command to run on each restart, which is how you chain a build step. watch — the list of directories or files that trigger a restart. ignore — paths excluded from watching, typically build output, logs, and node_modules. ext — which file extensions to watch. delay — a debounce in milliseconds, useful when a save fires several filesystem events. --signal — the signal used to kill the child, which matters if your build needs a graceful shutdown.
Nodemon reads these from nodemon.json, from a nodemonConfig key in package.json, or from command-line flags. Flags override config, so a sloppy script line can quietly undo a good config file.
Decide the architecture before writing config
There are two workable patterns, and mixing them carelessly is the most common cause of infinite restart loops.
Pattern A — webpack runs inside the nodemon child. Nodemon restarts, the child runs webpack once and then starts the server. Every restart is a fresh build. This is simple, deterministic, and easy to reason about. The cost is that each restart pays full bundle time, which on a mid-size app can be several seconds to tens of seconds.
Pattern B — webpack runs as a persistent watcher, nodemon restarts only the server. You run webpack --watch in one terminal (or via a task runner) and nodemon in another. Nodemon's watch list covers server code and config; webpack's watch list covers client source. Restarts are fast because the bundle is already current.
Pattern B has a sequencing trap: if webpack is still writing dist/bundle.js when the server restarts, the server can load a half-written file. Two mitigations work. First, have the server read the bundle lazily or tolerate a missing file at startup. Second, use webpack's done hook to trigger the restart yourself, in which case nodemon isn't supervising webpack at all — it's the other way around. Nodemon's own docs describe this pattern for servers that should restart after a build completes rather than on a file change.
For most small and medium projects, Pattern A is the right default. Reach for Pattern B when restart latency starts to hurt.
Pattern A: a working nodemon plus webpack setup
Prerequisites
You need Node.js installed, a project with webpack and webpack-cli as dev dependencies, and nodemon as a dev dependency. Your webpack config should already produce a working bundle when you run npx webpack. If it doesn't, fix that first — nodemon won't help a broken build.
Confirm the parts independently:
1: npx webpack completes and writes the expected output file. 2: node dist/server.js (or whatever your entry is) starts the server. 3: npx nodemon dist/server.js restarts when you touch that file.
Only after those three pass should you chain them.
Steps
1: Turn off webpack's watch mode in the build used inside nodemon. If your webpack.config.js sets watch: true, the child process never exits, and nodemon's restart behavior gets confusing: the old process may not die cleanly, and you can end up with two compilers fighting over the same output directory. Keep a separate config or a CLI flag for the standalone watcher instead. Running webpack --no-watch (or simply omitting --watch) is the explicit form.
2: Create a nodemon.json at the project root. A minimal Pattern A config:
The watch array is deliberately narrow. Watching the whole project means nodemon restarts whenever webpack writes to dist, which triggers another build, which writes to dist again. That's the classic loop. Ignoring dist and not watching the client source directory both help.
3: Point the exec at build-then-run. The && matters: if webpack fails, the server shouldn't start with a stale bundle silently. If you'd rather keep the old server running on a build failure, use ; instead and accept the risk of serving a mismatched bundle.
4: Wire up package.json scripts. Something like:
With nodemon.json present, npm run dev needs no arguments. If you prefer flags over a config file, nodemon --watch src/server --ignore dist --exec "webpack --mode development && node dist/server.js" is equivalent.
5: Run it and confirm the loop. Edit a file under src/shared, save, and watch the terminal. You should see nodemon print a restart line, webpack print a compilation summary, and the server log its startup message — in that order. Edit a file under dist manually; nothing should happen, because it's ignored.
6: Check the failure path. Introduce a syntax error in a server file. Webpack should fail, the && should short-circuit, and the server should not start. Fix the error; the next save should rebuild and start cleanly.
If step 5 loops endlessly, the cause is almost always a watched path that the build writes to. Print the resolved watch list with nodemon --dump (or check the startup banner, which lists watched directories) and trim it.
Pattern B: webpack as a separate watcher
Here nodemon's job shrinks. You run webpack in watch mode in one process and nodemon supervises only the server.
1: Start the bundler: npx webpack --watch --mode development. It stays alive and recompiles on client changes. 2: Configure nodemon to watch server code and config only:
3: Save a server file; nodemon restarts node against the current bundle. Save a client file; webpack recompiles and, if you're using hot middleware or a browser reloader, the browser updates — the server doesn't restart at all.
The advantage is obvious in the timing: a server-only change costs one Node startup, not a full bundle. The disadvantage is that you now run two terminals or a process manager, and you must keep the build output and the server's expectations in sync. If the server imports the bundle at startup and the bundle is mid-write, you get a transient error. The delay option on nodemon's side and webpack's output.clean behavior both affect how likely that is.
If you want the build to cause the restart rather than race it, use webpack's plugin API. A small plugin with a done hook can send SIGUSR2 to the nodemon process, the signal nodemon uses for manual restarts. That inverts the dependency: webpack is authoritative, and the server restarts only after a successful compile. It's more code, but it eliminates the race entirely.
Keeping the watch lists from colliding
The single most common failure in this setup is mutual watching. Webpack writes to dist; nodemon watches the project root; nodemon sees dist change and restarts; the restart triggers a rebuild; repeat. The symptom is a terminal scrolling forever and CPU pegged.
Defenses, in order of preference:
Ignore build output in nodemon. "ignore": ["dist/", "build/"]. Watch specific source directories rather than the root. "watch": ["src/server"] is safer than "watch": ["."]. Exclude nodemon's watch list from webpack's input where relevant. Webpack's watchOptions.ignored accepts a regex or glob; ignoring node_modules and log directories reduces spurious rebuilds. Raise delay. A 200–500 ms debounce absorbs the burst of filesystem events that editors and bundlers emit on a single logical save.
Watch lists should also account for config files. If editing webpack.config.js should rebuild, include it in nodemon's watch list — but be aware that a restart will then re-read the config, which is usually what you want.
What to watch when it doesn't work
| Symptom | Likely cause | First check |
|---|---|---|
| Endless restarts | Build output inside a watched path | nodemon.json watch/ignore |
| Restart but no rebuild | exec runs only the server | The && chain in exec |
| Rebuild but old code served | Server caches or reads stale file | Server's import path and cache settings |
| Two compilers running | watch: true in config plus --watch flag | Webpack config and CLI flags |
| Restart on every keystroke | No debounce, editor writes partial files | Increase delay |
| Child won't die | Build holds the event loop or ignores SIGTERM | --signal and any long-lived handles |
The "restart but no rebuild" row deserves emphasis. If exec is node dist/server.js, nodemon restarts the server but webpack never runs — you're in Pattern B without the watcher. The fix is either adding the build to exec (Pattern A) or running the watcher separately (Pattern B), not a config tweak.
The "old code served" row is subtler. Node's module cache means a long-running process won't pick up a changed file unless it's restarted — which nodemon does. But if the server reads the bundle from a path that webpack hasn't finished writing, you get a partial file. Because nodemon's restart is triggered by the source file change, not the build completion, a slow build can outlive the restart. The done-hook approach or a delay long enough to cover typical build time are the practical answers.
Choosing between the patterns
Use Pattern A when:
Your build completes in a few seconds or less. You want a single npm run dev command. You're learning the tools and want the sequencing to be obvious. Your server and client share code that webpack must recompile together.
Use Pattern B when:
Build time is measured in many seconds and restarts feel sluggish. Client and server code change independently most of the time. You already run a process manager (concurrently, npm-run-all, a Makefile) that can start both. You want browser hot reload to be the primary feedback loop and server restarts to be rare.
A useful middle ground: start with A, and when npm run dev restarts start to feel slow, split the webpack watcher out and leave nodemon watching only src/server. The config changes are small — remove the build from exec, add the client source to webpack's watch, and adjust ignore.
Where this approach hits its limits
Nodemon restarts are whole-process restarts. That's fine for a dev server, but it discards in-memory state: open connections, caches, in-flight jobs. If your server holds a database connection pool or a websocket registry, every restart tears those down and rebuilds them, which is slower than a hot module replacement approach and can leave stale handles if shutdown isn't graceful. If that matters, look at HMR for the server side or a framework's built-in reload, and keep nodemon for the cases where a clean restart is what you want.
The other limit is that nodemon and webpack both have their own file watchers, and on some systems — particularly containers with bind-mounted volumes — filesystem events don't propagate reliably. In Docker, nodemon --legacy-watch (polling) is the usual workaround, at the cost of CPU. Webpack's watchOptions.poll does the same for the bundler. Both are slower than native events, so use them only when the environment requires it.
Finally, there's a version-drift risk. Nodemon's config schema and webpack's CLI flags have changed across major versions; a setup copied from an older tutorial can silently misbehave. Check the installed versions with npx nodemon --version and npx webpack --version, and prefer the current documented flag names. Since this reference date is November 2026, confirm against the installed package versions rather than assuming a tutorial from years ago still matches.
Practical defaults worth keeping
A short checklist that prevents most of the pain:
Keep webpack's watch off in the command nodemon runs; enable it only in the standalone watcher. Ignore every build output directory in nodemon. Watch source directories explicitly instead of the project root. Put the build before the run in exec, joined with &&, so failures don't start a stale server. Set a delay of 200–500 ms to debounce editor and bundler bursts. Verify the loop in both directions: a server edit should rebuild and restart; a client edit should behave per the pattern you chose. When restarts get slow, move from Pattern A to Pattern B rather than adding more flags.
The core idea is simple even when the config isn't: nodemon restarts whatever you tell it to run, so make it run the build and the server in the right order, and keep the two file watchers from watching each other's output.