Skip to content

Commit eda85d9

Browse files
feat: added support for link imagesrcset attribute (#347)
1 parent a2566c9 commit eda85d9

File tree

8 files changed

+63
-26
lines changed

8 files changed

+63
-26
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Supported tags and attributes:
8686
- the `xlink:href` attribute of the `use` tag
8787
- the `href` attribute of the `use` tag
8888
- the `href` attribute of the `link` tag when the `rel` attribute contains `stylesheet`, `icon`, `shortcut icon`, `mask-icon`, `apple-touch-icon`, `apple-touch-icon-precomposed`, `apple-touch-startup-image`, `manifest`, `prefetch`, `preload`
89+
- the `imagesrcset` attribute of the `link` tag when the `rel` attribute contains `stylesheet`, `icon`, `shortcut icon`, `mask-icon`, `apple-touch-icon`, `apple-touch-icon-precomposed`, `apple-touch-startup-image`, `manifest`, `prefetch`, `preload`
8990
- the `content` attribute of the `meta` tag when the `name` attribute is `msapplication-tileimage`, `msapplication-square70x70logo`, `msapplication-square150x150logo`, `msapplication-wide310x150logo`, `msapplication-square310x310logo`, `msapplication-config` or when the `property` attribute is `og:image`, `og:image:url`, `og:image:secure_url`, `og:audio`, `og:audio:secure_url`, `og:video`, `og:video:secure_url`, `vk:image`
9091

9192
#### `Boolean`

src/utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,12 @@ const defaultAttributes = [
652652
type: 'src',
653653
filter: linkHrefFilter,
654654
},
655+
{
656+
tag: 'link',
657+
attribute: 'imagesrcset',
658+
type: 'srcset',
659+
filter: linkHrefFilter,
660+
},
655661
{
656662
tag: 'meta',
657663
attribute: 'content',

test/__snapshots__/esModule-option.test.js.snap

Lines changed: 6 additions & 3 deletions
Large diffs are not rendered by default.

test/__snapshots__/loader.test.js.snap

Lines changed: 2 additions & 1 deletion
Large diffs are not rendered by default.

test/__snapshots__/minimize-option.test.js.snap

Lines changed: 12 additions & 9 deletions
Large diffs are not rendered by default.

test/__snapshots__/sources-option.test.js.snap

Lines changed: 31 additions & 13 deletions
Large diffs are not rendered by default.

test/fixtures/simple.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ <h2>An Ordered HTML List</h2>
381381
<link rel="apple-touch-icon-precomposed" href="./image.png"/>
382382
<link rel="manifest" href="./site.webmanifest">
383383
<link rel="mask-icon" href="./webpack.svg" color="#5bbad5">
384+
<link rel="preload" as="image" imagesrcset="image.png 400w, image.png 800w, image.png 1600w" imagesizes="100vw">
384385
<meta name="msapplication-square70x70logo" content="./image.png">
385386
<meta NAME="msapplication-square70x70logo" content="./image.png">
386387
<meta name="msapplication-square150x150logo" content="./image.png">

test/fixtures/sources.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,7 @@
272272
<img srcset="image.png 200w, " sizes="(max-width: 600px) 480px, 800px" src="image.png" alt="Elva dressed as a fairy">
273273
<img srcset=",image.png 200w" sizes="(max-width: 600px) 480px, 800px" src="image.png" alt="Elva dressed as a fairy">
274274
<img srcset=",image.png 200w " sizes="(max-width: 600px) 480px, 800px" src="image.png" alt="Elva dressed as a fairy">
275+
276+
<link rel="preload" as="image" imagesrcset="image.png 400w, image.png 800w, image.png 1600w" imagesizes="100vw">
277+
<link rel="preload" as="image" imagesrcset="image.png 400w" imagesizes="100vw">
278+
<link rel="preload" as="image" imagesrcset="" imagesizes="100vw">

0 commit comments

Comments
 (0)