In --watch mode, have an option to compare "before" and "after" CONTENT of the changed file, not only the timestamp
See original GitHub issueFeature request
Have an option in watchOptions
which tells the watcher to additionally compare the changed file’s content and not trigger if the timestamp is changed, but the content is not.
Consider this command:
touch src/some-input.js
What is the expected behavior?
With this new option set to true
, the above touch
may not trigger the watch-mode build.
What is motivation or use case for adding/changing the behavior?
Sometimes timestamp of an input file might change, but the actual content would not. It would be great to have a hint to the watcher which ignores the file’s timestamp change if the content is unchanged.
When does it happen? Sometimes an input file refers another *.js file (possible from another monorepo package, something like shared/xyz.js) which is built by an external tool, like tsc. And tsc is known of changing the timestamps of the output even if the input is unchanged: https://github.com/microsoft/TypeScript/issues/35340 (I think they do it for some internal reasons, to detect incremental changes better). In this case, a no-op override of a dependent file (possibly from another monorepo package) causes webpack watch mode to trigger the build.
Using ts-loader here is not an option: it it’s a large monorepo with many package referring one another, we don’t want multiple webpack processes for each of these projects to recompile all the source *.ts files of all dependent packages. Instead, we want them to use tsc compiler output from packages/some-package/dist/*.{js,map}
- which is way faster since TS compiles such files only once (i.e. O(n) as opposed to O(n^2) ts-loader compilation approximation if n is the number of packages which refer each other).
How should this be implemented in your opinion?
Something around Watchpack & recheck when the change arrives.
Are you willing to work on this yourself?
Yes, if the idea is approved, and also with some hints regarding the desired architecture.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
The watcher doesn’t support that, but webpack can be changed to compare file content hashes instead of timestamps to check for module invalidation. It would still rebuild, but would just take all modules from the cache.
https://webpack.js.org/configuration/other-options/#snapshot
This will compare file content hash, when timestamp has changed. Note that this makes the initial build slower as all files need to be read and hashed to have baselines to compare with.
Issue was closed because of inactivity.
If you think this is still a valid issue, please file a new issue with additional information.