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
fix: don't default to 0
(options.limit
)
#74
Merged
michael-ciniawsky
merged 1 commit into
webpack-contrib:master
from
alexander-akait:issue-40
Jun 12, 2017
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we really drop it yet ? I'm not against it, but
webpack =< v1.0.0
users will lose caching then.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great point & a good catch, we can't as this technically still supports 1.x. @evilebottnawi that will have to stay in and be removed in the defaults PR.