Closed b13nxx closed 4 years ago
Can you create reproducible test repo? Also try to disable clean-webpack-plugin
Fixed in webpack@5, can't be fixed on loader side
I ran into this same issue and clean-webpack-plugin was the cause. My images and fonts were blown away on the second run. I verified this was with the plugin by adding verbose: true
, and fixed the issue by setting cleanStaleWebpackAssets: false
.
My plugin now looks like:
new CleanWebpackPlugin({
verbose: true,
cleanStaleWebpackAssets: false
}),
Upgrading to webpack@5 did not resolve the issue when this plugin was enabled.
Expected Behavior
Rebuild logo.svg after first build
Actual Behavior
Doesn't rebuild after first build of logo.svg
Folder Structure
Let say we have something similar to this:
Code
Our webpack.config.js includes this section:
How Do We Reproduce?
[Step 1] Just include one image in your React app:
[Step 2] Then build with webpack --watch.
First build will be successful and you'll see logo.svg in dist folder (lets assume output folder for webpack).
[Step 3] Then change image:
This time you'll see logo.png in dist folder (which is obviously right).
[Step 4] But if you include same image again:
You will not see logo.svg in dist folder. It won't get rebuild.
Unnecessary Facts
clean-webpack-plugin
. That's mean unnecessary assets get removed after build (and every rebuild).TypeScript
.create-react-app
withyarn eject
and addedwriteToDisk: true
fordevServer
option.