Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

fix: don't default to 0 (options.limit) #74

Merged
merged 1 commit into from
Jun 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var loaderUtils = require("loader-utils");
var mime = require("mime");

module.exports = function(content) {
this.cacheable && this.cacheable();
Copy link
Member

@michael-ciniawsky michael-ciniawsky Jun 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we really drop it yet ? I'm not against it, but webpack =< v1.0.0 users will lose caching then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great point & a good catch, we can't as this technically still supports 1.x. @evilebottnawi that will have to stay in and be removed in the defaults PR.

var query = loaderUtils.getOptions(this) || {};
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) {
return "module.exports = " + JSON.stringify("data:" + (mimetype ? mimetype + ";" : "") + "base64," + content.toString("base64"));
} else {
var fileLoader = require("file-loader");
return fileLoader.call(this, content);
}
this.cacheable && this.cacheable();

var options = loaderUtils.getOptions(this) || {};
// Options `dataUrlLimit` is backward compatibility with first loader versions
var limit = options.limit || (this.options && this.options.url && this.options.url.dataUrlLimit);

if(limit) {
limit = parseInt(limit, 10);
}

var mimetype = options.mimetype || options.minetype || mime.lookup(this.resourcePath);

// No limits or limit more than content length
if(!limit || content.length < limit) {
return "module.exports = " + JSON.stringify("data:" + (mimetype ? mimetype + ";" : "") + "base64," + content.toString("base64"));
}

var fileLoader = require("file-loader");

return fileLoader.call(this, content);
}

module.exports.raw = true;