webpack watcher compiles EVERY file and not just the changed one.

Do you want to request a feature or report a bug?
Maybe I’m misunderstanding the doucemtation/watcher, but otherwise this is a bug. However, it’s such a fundamental piece of webpack, if it would be a bug, someone else probably already reported it?

What is the current behavior?
webpack watcher compiles EVERY file and not just the changed one.

Steps to reproduce:
These steps assume you already have yarn/npm installed.

  • Check out the repository I created which you can find at https://github.com/tzfrs/webpack-watch-bug
  • Initially run yarn install or npm install.
  • Run ./node_modules/.bin/webpack. This should create two files in the dist folder and automatically watch.
  • Delete dist/second.js
  • Change something in src/first.js
  • src/second.js has no changes, but will still be recompiled (because dist/second.js is created again).
  • Also, the log states something along the lines
Hash: d13339396526426e402d
Version: webpack 4.3.0
Time: 304ms
Built at: 3/29/2018 12:11:20 PM
    Asset       Size  Chunks             Chunk Names
second.js  545 bytes       0  [emitted]  second
 first.js  561 bytes       1  [emitted]  first
Entrypoint first = first.js
Entrypoint second = second.js
   [0] ./src/second.js 0 bytes {0} [built]
   [1] ./src/first.js 17 bytes {1} [built]

As you can see. second.js is also in the log.

What is the expected behavior?
Only changed files should be recompiled. I assume that this is the expected behavior, because the documentation for Watch states:

webpack can watch files and recompile whenever they change.

Author: Fantashit

2 thoughts on “webpack watcher compiles EVERY file and not just the changed one.

  1. Just to note, using --mode=development will give the desired behavior you are describing (unless I am missing something).

Comments are closed.