This repository has been archived by the owner on Mar 17, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9356a81
commit 020c2a8
Showing
1 changed file
with
25 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
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; |