webpack-contrib / file-loader

File Loader
MIT License
1.86k stars 255 forks source link

Provide file stats via named exports #377

Closed czabaj closed 4 years ago

czabaj commented 4 years ago

Feature Proposal

Provide file stats as named exports, similarly how @swgr/webpack operates.

import termsAndConditions, { fileSizeHumanReadable, fileSizeBytes } from './termsAndConditions.pdf'

I found sizeof-loader which provides this functionality but has incompatible API with file-loader, it provides stats object including src as the default export, using named exports for stats would be backward compatible and possibly allows to use optimization (collect only stats user requests via named import).

Feature Use Case

I want to display a human-readable file size as part of a hyperlink text, which points to a PDF file. I import the PDF file to obtain its pathname via file-loader, but there is not an easy way to obtain its size.

alexander-akait commented 4 years ago

Sorry, it is out of scope file-loader, you can create an own loader for this case, it is very non standard feature, you even can do it without loader, just fetch resource and calculate it, you already have URL to an asset,