-
-
Notifications
You must be signed in to change notification settings - Fork 158
fix: don't default to 0
(options.limit
)
#74
fix: don't default to 0
(options.limit
)
#74
Conversation
de90968
to
2b0529b
Compare
limit
options now works correctly.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.
But I have the webpack-defaults
update ready for this loader maybe wait and fix it there instead, give me a few moments please, it's mainly blocked bc of schema-utils
update :)
@michael-ciniawsky I'll just do rebase after |
/cc @michael-ciniawsky can we merge this before |
If it's beneficial to the current major version range, land it before defaults so consumers can benefit from it without having to upgrade. |
index.js
Outdated
var limit = (this.options && this.options.url && this.options.url.dataUrlLimit) || 0; | ||
if(query.limit) { | ||
limit = parseInt(query.limit, 10); | ||
var options = Object.assign({}, loaderUtils.getOptions(this)); |
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.
loaderUtils.getOptions(this) || {};
Object.assign
is slower and there is nothing (e.g defaults
) to assign
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.
FYI - It's slower by quite a bit in some cases. I initially tried doing this when we had to rush through the loaderUtils deprecation updates & you take a real performance hit.
index.js
Outdated
limit = parseInt(query.limit, 10); | ||
var options = Object.assign({}, 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); |
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.
\n
index.js
Outdated
} | ||
var mimetype = query.mimetype || query.minetype || mime.lookup(this.resourcePath); | ||
if(limit <= 0 || content.length < limit) { | ||
var mimetype = options.mimetype || options.minetype || mime.lookup(this.resourcePath); |
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.
\n
index.js
Outdated
var mimetype = query.mimetype || query.minetype || mime.lookup(this.resourcePath); | ||
if(limit <= 0 || content.length < limit) { | ||
var mimetype = options.mimetype || options.minetype || mime.lookup(this.resourcePath); | ||
// No limits or limit more than content length |
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.
\n
index.js
Outdated
} | ||
|
||
var fileLoader = require("file-loader"); | ||
return fileLoader.call(this, content); | ||
} |
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.
\n
index.js
Outdated
@@ -6,17 +6,19 @@ var loaderUtils = require("loader-utils"); | |||
var mime = require("mime"); | |||
module.exports = function(content) { |
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.
\n
options.limit
)
options.limit
)0
(options.limit
)
8ceccf9
to
48dd8a0
Compare
/cc @michael-ciniawsky done also remove |
module.exports = function(content) { | ||
this.cacheable && this.cacheable(); |
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.
48dd8a0
to
fc91e3c
Compare
/cc @d3viant0ne |
What kind of change does this PR introduce?
Refactoring
Did you add tests for your changes?
manual testing 😄
If relevant, did you update the README?
not required
Summary
Consistent getting
limit
options, also don't use 0 as defaultlimit
value because this is misleading when reading the code: if nolimit
encode all, iflimit
enable encode only files smaller thanlimit
.Does this PR introduce a breaking change?
No
Other information
not required