'Removing stylesheet from webpack dev server at run time

I have a problem. Essentially I am running Webpack 5, with Webpack dev server and Webpack copy plugin to copy all my assets, images, styles etc... into the dist directory. I am building some functionality where some stylesheets may get deleted or modified at run time and I need to be able to sync the directories, so that if the server or I manually delete a stylesheet from the assets directory, the website could not read the file because it does no longer exist.

I found CleanWebpackPlugin, which actually deletes the file from dist when I delete it from my application's assets directory. This works fine, but deleting the stylesheet from the dist directory does not actually delete it from webpack dev server and the file still exists and applies.

I have tried writeToDisk in Webpack options, true and false I cannot get this to work.

Your help would be much appreciated, even if you can just point me in the right direction.

Many thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source