Created
October 20, 2015 21:18
-
-
Save andresmrm/dbf24a1caeaf0383cb0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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