-
-
Notifications
You must be signed in to change notification settings - Fork 282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When watching, CopyPlugin emits all unchanged files and emits file contents from outdated snapshots #553
Comments
Actually, since Issue 2 exists, Issue 1 can only be reproduced with a previous version like |
Please never describe problems like this. Try to avoid links on code, it just makes everything unreadable and spammy, just describe actual result + excepted + reproducible test repo, This will not only make it easier for me to find the error and fix it, but also save your time and help other developers to find the same problem. |
You should not change nothing in dist, it will be always overridden, this is how webpack works, the same happens for any files Anyway we will fix it |
Why? Because we should always emit assets, otherwise clean-webpack-plugin/persistent cache/plugins change output after copy-webpack-plugin will not work, also we want to implement auto cleanup dist directory (by option(s)) and it will not work too |
Yep, it is bug, WIP |
I just want to demonstrate that the files in dist are written again, despite that their sources are not changed.
The first reason is performance. In my case, I need to deploy a web application to the client-side, and therefore need to copy a lot of static files like images and html/css/js, which are rarely changed. The second reason is webpack hot-reloading (hot module replacement). On Windows, if a file is opened, it will be locked by the OS until it is closed. So with CopyPlugin overwriting all files again and crash if the target file is locked(#548), it kind of defeats the purpose of hot-reloading. This forces me to stop debugging first before making any change to the source. |
@felixhao28 Does problem solved by v6.3.1? |
I switched to sync-directory since issue 1 (overwriting every file and crashing hot-reloading server) is a deal-breaker for me. |
@felixhao28 Do you try |
Just tried |
Expected Behavior
CopyPlugin should only write modified files and write up-to-date file contents.
Actual Behavior
Actaully, there are two some-what related issues here.
[Issue 1] When a file changes, CopyPlugin attempts to write all files because it failed to find it in "assets".
details
I am changing a file from "static" folder and it is not loaded through a loader.
After debugging for a while, I finally pinned down the root cause to this line:
copy-webpack-plugin/src/index.js
Line 709 in fa5aa1b
This always returns
null
for my "static/index.html", because somehow only source files (or more precisely, files matching rules and loaded through a loader) are considered assets (compliation.assets
). SinceexistingAssets
cannot be found, CopyPlugin will then treat it as a new file and emitting the source on this linecopy-webpack-plugin/src/index.js
Line 749 in fa5aa1b
[Issue 2] The file actually got changed did not update properly. This always happens if I change the file quickly after the previous change.
This is a new issue since
6.3.0
afterCopyPlugin.createSnapshot
is a thing.details
I pinned the root cause to this line:
copy-webpack-plugin/src/index.js
Line 438 in fa5aa1b
In this call,
sourceFilename
is"static/index.html"
but in Webpack's CachedInputFileSystem, all paths should be OS-dependent absolute path like"D:\projects\copy-webpack-plugin-bugrepro\static\index.html"
. This causesCachedInputFileSystem._storeResult
to use a different key than the key used inCachedInputFileSystem.purge
, which lets to files' modified time cache not purged before CopyPlugin tries to read it.As a result,
https://github.com/webpack/enhanced-resolve/blob/d6807b553dc7e3157746b57a82cb238cd5e58cee/lib/CachedInputFileSystem.js#L172
which is called from
copy-webpack-plugin/src/index.js
Line 367 in fa5aa1b
gets previously stored cache instead of null.
Code
How Do We Reproduce?
Clone this https://github.com/felixhao28/copy-webpack-plugin-bugrepro
Then
npm install
.[Issue 1]
First
npm run watch
, and then make some changes todist\static\index.html
and save. Then make some changes tostatic\test.html
and save. Watch the changes todist\static\index.html
gets reverted, indicatingdist\static\index.html
is written.[Issue 2]
First
npm run watch
, and then make some changes tostatic\index.html
and save. Nowdist\static\index.html
should be the same asstatic\index.html
.Then change
static\index.html
again and save. Nowdist\static\index.html
does not update accordingly.The text was updated successfully, but these errors were encountered: