|
1 | 1 | /*
|
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 | + */ |
5 | 5 | var loaderUtils = require("loader-utils");
|
6 | 6 | var mime = require("mime");
|
| 7 | + |
7 | 8 | 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); |
21 | 29 | }
|
| 30 | + |
22 | 31 | module.exports.raw = true;
|
0 commit comments