image size loader module for webpack
npm install image-size-loaderA webpack image loader with extra size info for image.
`` javascript
npm install image-size-loader --save
var image = require("image-size!./file.png");
// => emits file.png to the output directory
// => returns an object
// => { width: 150, height: 50, type: "png", src: __webpack_public_path__ + "file.png", bytes: 1234 }
`
#### name
`js`
var image = require('image-size?name=[hash].[ext]!./file.png');
* [ext] the extension of the resource[name]
* the basename of the resource[path]
* the path of the resource relative to the context query parameter or option.[hash]
* the hash of the content[
* optionally you can configurehashType
* other s, i. e. sha1, md5, sha256, sha512digestType
* other s, i. e. hex, base26, base32, base36, base49, base52, base58, base62, base64length
* and the length in chars[N]
* the N-th match obtained from matching the current file name against the query param regExp
Source: https://github.com/webpack/loader-utils#interpolatename
#### webpack.config.js
`js`
// webpack.config.js
module.exports = {
output: {
publicPath: '/public/'
},
module: {
loaders: [
{
test: /\.(gif|jpeg|jpg|png|svg)$/,
loader: 'image-size'
}
]
}
};
#### example_module.js
` javascript``
var result = require("./image.png");
// => {width: 500, height: 700, type: "png", src: __webpack_public_path__ + "image.png", bytes: 1234}