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

Commit 020c2a8

Browse files
evilebottnawimichael-ciniawsky
authored andcommitted
fix: don't default to 0 (options.limit) (#74)
1 parent 9356a81 commit 020c2a8

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

index.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
/*
2-
MIT License http://www.opensource.org/licenses/mit-license.php
3-
Author Tobias Koppers @sokra
4-
*/
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
55
var loaderUtils = require("loader-utils");
66
var mime = require("mime");
7+
78
module.exports = function(content) {
8-
this.cacheable && this.cacheable();
9-
var query = loaderUtils.getOptions(this) || {};
10-
var limit = (this.options && this.options.url && this.options.url.dataUrlLimit) || 0;
11-
if(query.limit) {
12-
limit = parseInt(query.limit, 10);
13-
}
14-
var mimetype = query.mimetype || query.minetype || mime.lookup(this.resourcePath);
15-
if(limit <= 0 || content.length < limit) {
16-
return "module.exports = " + JSON.stringify("data:" + (mimetype ? mimetype + ";" : "") + "base64," + content.toString("base64"));
17-
} else {
18-
var fileLoader = require("file-loader");
19-
return fileLoader.call(this, content);
20-
}
9+
this.cacheable && this.cacheable();
10+
11+
var options = loaderUtils.getOptions(this) || {};
12+
// Options `dataUrlLimit` is backward compatibility with first loader versions
13+
var limit = options.limit || (this.options && this.options.url && this.options.url.dataUrlLimit);
14+
15+
if(limit) {
16+
limit = parseInt(limit, 10);
17+
}
18+
19+
var mimetype = options.mimetype || options.minetype || mime.lookup(this.resourcePath);
20+
21+
// No limits or limit more than content length
22+
if(!limit || content.length < limit) {
23+
return "module.exports = " + JSON.stringify("data:" + (mimetype ? mimetype + ";" : "") + "base64," + content.toString("base64"));
24+
}
25+
26+
var fileLoader = require("file-loader");
27+
28+
return fileLoader.call(this, content);
2129
}
30+
2231
module.exports.raw = true;

0 commit comments

Comments
 (0)