index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. var loaderUtils = require("loader-utils");
  6. var mime = require("mime");
  7. module.exports = function(content) {
  8. this.cacheable && this.cacheable();
  9. var options = loaderUtils.getOptions(this) || {};
  10. // Options `dataUrlLimit` is backward compatibility with first loader versions
  11. var limit = options.limit || (this.options && this.options.url && this.options.url.dataUrlLimit);
  12. if(limit) {
  13. limit = parseInt(limit, 10);
  14. }
  15. var mimetype = options.mimetype || options.minetype || mime.lookup(this.resourcePath);
  16. // No limits or limit more than content length
  17. if(!limit || content.length < limit) {
  18. if(typeof content === "string") {
  19. content = new Buffer(content);
  20. }
  21. return "module.exports = " + JSON.stringify("data:" + (mimetype ? mimetype + ";" : "") + "base64," + content.toString("base64"));
  22. }
  23. var fileLoader = require("file-loader");
  24. return fileLoader.call(this, content);
  25. }
  26. module.exports.raw = true;