Project refresh
I had a need for this loader for a use case with react and styled-components, and rewritten it as follows:
// This wraps https://github.com/webpack-contrib/url-loader
//
// Adapted from: https://github.com/boopathi/image-size-loader
const loaderUtils = require('loader-utils');
const sizeOf = require('image-size');
const fs = require('fs');
const urlLoader = require("url-loader");
module.exports = function(content) {
this.cacheable && this.cacheable();
const resourcePath = this.resourcePath;
const prefixCode = urlLoader.call(this, content);
var image = sizeOf(resourcePath);
image.bytes = fs.statSync(resourcePath).size;
return `
${prefixCode};
const src = module.exports;
module.exports = {
src: '' + src,
width: ${JSON.stringify(image.width)},
height: ${JSON.stringify(image.height)},
bytes: ${JSON.stringify(image.bytes)},
type: ${JSON.stringify(image.type)},
toString: function() {
return '' + ${JSON.stringify(image.src)};
}
};
`;
};
module.exports.raw = true;
@boopathi This loader doesn't seem to get much attention :(
If you're still maintaining this loader; I can PR with the suggested changes above.
If not, I can create a new loader to be available on npm.
Or perhaps, I can maintain it (bonus points if it's moved to https://github.com/webpack-contrib 😄 )
@dashed considering the last update to this project was almost 2 years ago, it would be amazing if you released your loader on npm for other people (me! me!) to use ;)
@d4rky-pl sure, I'll look into creating and releasing this as an npm module this weekend. (or tonight)
@Odrin @d4rky-pl heads up, I adapted and published the code from my first comment to: https://github.com/dashed/sizeof-loader