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

Commit de90968

Browse files
author
evilebottnawi
committed
Chore: refactor code.
1 parent de61cbd commit de90968

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

index.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
/*
2-
MIT License http://www.opensource.org/licenses/mit-license.php
3-
Author Tobias Koppers @sokra
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
44
*/
55
var loaderUtils = require("loader-utils");
66
var mime = require("mime");
77
module.exports = function(content) {
88
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);
9+
var options = Object.assign({}, 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);
1314
}
14-
var mimetype = query.mimetype || query.minetype || mime.lookup(this.resourcePath);
15-
if(limit <= 0 || content.length < limit) {
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) {
1618
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);
2019
}
20+
21+
var fileLoader = require("file-loader");
22+
return fileLoader.call(this, content);
2123
}
2224
module.exports.raw = true;

0 commit comments

Comments
 (0)