Webpack image size loader
Webpack image size loader. This loader
- Returns size info only
- Does not emit file
- Has no side effect
- Is totally compatible with any other loaders (e.g. file-loader url-loader). Check usage for detail
Usage
- Install With
yarn
: yarn add -D img-size-loader
- Or install with
npm
: npm install --save-dev img-size-loader
- It is highly recommended to overloading other loaders by preceding inline loader with punctuation(
!
) - Inline Import example
import ImageSize from '!img-size-loader!./my-logo.png'
import ImageUrl from './my-logo.png'
console.log(ImageSize)
console.log(ImageUrl)
- Webpack config. Add to
module.rules
{
test: /\.(bmp|cur|gif|icns|ico|jpeg|png|psd|tiff|webp|svg|dds)(\?[a-z0-9]+)?$/,
resourceQuery: /size/,
use: [ { loader: 'img-size-loader', } ]
},
And in your code: import ImageSize from './my-logo.png?size'
Dependencies