webpack-contrib / file-loader

File Loader
MIT License
1.86k stars 255 forks source link

[Feature Request]Make `emitFile` tree shakingable #396

Closed NE-SmallTown closed 3 years ago

NE-SmallTown commented 3 years ago

Feature Proposal

I'm not familar with webpack and file-loader, so I don't know if it's possible to achieve this

Feature Use Case

Currently if we import an image(like import foo from "../../common/images/hello.png") but not be used, the bundle result will not have variable foo because it has been tree-shaken.

But, we will find that there is still an image file(like hello-hash.png) in the webpack output path directory because we always call emitFile. This will waste space of the server if we upload it when we publish every time

alexander-akait commented 3 years ago

Yes, expected, because other plugins can use this assets for any purpose, we can't remove it, anyway you don't have code for this import in your bundle

NE-SmallTown commented 3 years ago

@evilebottnawi Thanks for your reply.

But as I said, "This will waste space of the server if we upload it when we publish every time" which is a problem

Is there any way to know whether the file be used? If so, I can write a custom emitFile

alexander-akait commented 3 years ago

But as I said, "This will waste space of the server if we upload it when we publish every time" which is a problem

Just avoid unnecessary imports

Is there any way to know whether the file be used? If so, I can write a custom emitFile

No

NE-SmallTown commented 3 years ago

Just avoid unnecessary imports

I think this is not very easy just like we need tree-shaking rather than avoid unnecessary imports

No

But from "because other plugins can use this assets for any purpose, we can't remove it", seems(myabe I misunderstand) there is a way to know "whether the file be used", just because "other plugins can use this assets for any purpose", so you still "can't remove it" even you know the file not be used?

alexander-akait commented 3 years ago

there is a way to know "whether the file be used"

No ways, so we can't remove it

But you can write own plugin for this, but it will be not easy

alexander-akait commented 3 years ago

For example my plugin can create robots.txt file based on assets