Skip to content

Instantly share code, notes, and snippets.

@andresmrm
Created October 20, 2015 21:18
Show Gist options
  • Save andresmrm/dbf24a1caeaf0383cb0a to your computer and use it in GitHub Desktop.
Save andresmrm/dbf24a1caeaf0383cb0a to your computer and use it in GitHub Desktop.
var loaderUtils = require("loader-utils");
var mime = require("mime");
module.exports = function(content) {
this.cacheable && this.cacheable();
var query = loaderUtils.parseQuery(this.query);
var limit = (this.options && this.options.url && this.options.url.dataUrlLimit) || 0;
if(query.limit) {
limit = parseInt(query.limit, 10);
}
var mimetype = query.mimetype || query.minetype || mime.lookup(this.resourcePath);
if(limit <= 0 || content.length < limit) {
if (query.once && content.toString().slice(0,16) == 'module.exports =') return content
return "module.exports = " + JSON.stringify("data:" + (mimetype ? mimetype + ";" : "") + "base64," + content.toString("base64"));
} else {
var fileLoader = require("file-loader");
return fileLoader.call(this, content);
}
}
module.exports.raw = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment