How to exclude images(files) which are not referred in any posts

When I change a post to draft, the images referred by the post remain in the build path.

My site has many drafts, so is there any way to not copy the images(files) of no use to build path


title: "My First Post"
date: 2019-03-07T20:22:34+08:00
**draft: true**


I hope “posts/my-first-post/2019-03-07-21-22-20.png” will disappear in the build path