-
-
Notifications
You must be signed in to change notification settings - Fork 205
feat: add srcset
support (<img>
)
#147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## master #147 +/- ##
==========================================
+ Coverage 96.96% 97.29% +0.32%
==========================================
Files 2 2
Lines 99 111 +12
Branches 20 22 +2
==========================================
+ Hits 96 108 +12
Misses 3 3
Continue to review full report at Codecov.
|
srcset
support (<img>
)
What is the status of this making it to release? @michael-ciniawsky |
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.
What happens if one of these asset urls doesn't exist ?
This maybe better implemented as an opt-in ?
lib/attributesParser.js
Outdated
@@ -4,13 +4,36 @@ | |||
*/ | |||
var Parser = require("fastparse"); | |||
|
|||
var srcsetQualifierRegexp = /(\s+(\d+w))?(\s+(\d+x))?\s*$/; |
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.
var SRCSET_REGEXP
lib/attributesParser.js
Outdated
|
||
// allow to load several urls in srcsets, separated by commas | ||
var start = index + strUntilValue.length; | ||
var subMatches = value.split(/,/); |
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
lib/attributesParser.js
Outdated
var length = subMatch.length; | ||
|
||
// remove initial spacing | ||
var initialSpace = /^\s+/.exec(subMatch); |
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.
- var initialSpace = /^\s+/.exec(subMatch);
- var spaceLength = initialSpace ? initialSpace[0].length : 0;
var space = {
initial: /^\s+/.exec(subMatch),
length: this.initial ? this.initial[0].length : 0
}
lib/attributesParser.js
Outdated
var spaceLength = initialSpace ? initialSpace[0].length : 0; | ||
|
||
// remove srcset qualifiers (2x, 110w, etc.), if any | ||
var qualifier = srcsetQualifierRegexp.exec(subMatch); |
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
@@ -4,13 +4,36 @@ | |||
*/ |
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.
Please move this into its own folder && file => ./lib/attrs/srcset.js
and require('./attrs/srcset.js')
it
@cupojoe It's in review and needs approval from 2+ maintainers, so no release date estimate can be made yet |
For reference, one of those should be @hemanth - This is one of the loaders that actually has an assigned lead maintainer |
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.
@michael-ciniawsky has covered most of it, apart of that LGTM.
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.
Agreed, should be g2g with the changes @michael-ciniawsky has already suggested.
Codecov Report
@@ Coverage Diff @@
## master #147 +/- ##
==========================================
+ Coverage 96.96% 97.54% +0.57%
==========================================
Files 2 3 +1
Lines 99 122 +23
Branches 20 22 +2
==========================================
+ Hits 96 119 +23
Misses 3 3
Continue to review full report at Codecov.
|
Hey there, I moved the code into @michael-ciniawsky about:
I'm not really sure... the idea in the code was really to load images from the I know of other attempts to auto-generate these responsive assets on-the-fly, but in my case I work with designers that produce these images (sometimes slightly modified for smaller res) and it is helpful to have just my two cents though, |
@michael-ciniawsky @ushu |
Sry but I have to declined this since |
Since webpack-contrib/html-loader#147 was rejected, I changed the package name to allow to import the code in new projects easily.
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
What is the current behavior? (You can also link to an open issue here)
srcset
attribute is not loaded from the HTML contentWhat is the new behavior?
srcset
attribute (actually the images inside thesrcset
declaration) is loadedDoes this PR introduce a breaking change?
Other information:
I did this code before realising that an old PR (#55) has been addressing the same issue.
So the code ended up being quite different.
The added value of this version is that it supports multiple qualifiers for the same source such as "100w 2x", which are useful when coding for the mobile web.
Also I am not why this feature has been removed but since I have some time his week I can iterate on the PR with some guidance.
Regards !