|
3 | 3 | Author Tobias Koppers @sokra
|
4 | 4 | */
|
5 | 5 | var loaderUtils = require("loader-utils");
|
| 6 | +var validateOptions = require("schema-utils"); |
| 7 | + |
6 | 8 | var mime = require("mime");
|
7 | 9 |
|
8 | 10 | module.exports = function(content) {
|
9 |
| - this.cacheable && this.cacheable(); |
| 11 | + this.cacheable && this.cacheable(); |
10 | 12 |
|
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); |
| 13 | + var options = loaderUtils.getOptions(this) || {}; |
14 | 14 |
|
15 |
| - if(limit) { |
16 |
| - limit = parseInt(limit, 10); |
17 |
| - } |
| 15 | + validateOptions(require("./options"), options, "URL Loader") |
| 16 | + // Options `dataUrlLimit` is backward compatibility with first loader versions |
| 17 | + var limit = options.limit || (this.options && this.options.url && this.options.url.dataUrlLimit); |
18 | 18 |
|
19 |
| - var mimetype = options.mimetype || options.minetype || mime.lookup(this.resourcePath); |
| 19 | + if(limit) { |
| 20 | + limit = parseInt(limit, 10); |
| 21 | + } |
20 | 22 |
|
21 |
| - // No limits or limit more than content length |
22 |
| - if(!limit || content.length < limit) { |
23 |
| - if(typeof content === "string") { |
24 |
| - content = new Buffer(content); |
25 |
| - } |
26 |
| - return "module.exports = " + JSON.stringify("data:" + (mimetype ? mimetype + ";" : "") + "base64," + content.toString("base64")); |
| 23 | + var mimetype = options.mimetype || options.minetype || mime.lookup(this.resourcePath); |
| 24 | + |
| 25 | + // No limits or limit more than content length |
| 26 | + if(!limit || content.length < limit) { |
| 27 | + if(typeof content === "string") { |
| 28 | + content = new Buffer(content); |
27 | 29 | }
|
28 | 30 |
|
29 |
| - var fileLoader = require("file-loader"); |
| 31 | + return "module.exports = " + JSON.stringify("data:" + (mimetype ? mimetype + ";" : "") + "base64," + content.toString("base64")); |
| 32 | + } |
| 33 | + |
| 34 | + var fileLoader = require("file-loader"); |
30 | 35 |
|
31 |
| - return fileLoader.call(this, content); |
| 36 | + return fileLoader.call(this, content); |
32 | 37 | }
|
33 | 38 |
|
34 | 39 | module.exports.raw = true;
|
0 commit comments