Gathering detailed insights and metrics for webpack-image-srcset-loader
Gathering detailed insights and metrics for webpack-image-srcset-loader
Gathering detailed insights and metrics for webpack-image-srcset-loader
Gathering detailed insights and metrics for webpack-image-srcset-loader
npm install webpack-image-srcset-loader
46.6
Supply Chain
66.3
Quality
71.2
Maintenance
50
Vulnerability
97.9
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
30 Stars
245 Commits
2 Forks
1 Watching
33 Branches
2 Contributors
Updated on 31 Jan 2023
Minified
Minified + Gzipped
TypeScript (95.83%)
JavaScript (4.17%)
Cumulative downloads
Total Downloads
Last day
3.4%
270
Compared to previous day
Last week
16.5%
2,332
Compared to previous week
Last month
16.4%
9,155
Compared to previous month
Last year
54.2%
73,427
Compared to previous year
1
27
This loader generates a srcset string from an image.
React example with other related loaders
Vue example with other related loaders
Install with npm:
1npm install --save-dev webpack-image-srcset-loader webpack-image-resize-loader
Install with yarn:
1yarn add --dev webpack-image-srcset-loader webpack-image-resize-loader
1import jpgSrcSet from "./some_pic.jpg?srcset"; 2 3// jpgSrcSet will be "97[...]7.jpg 480w, ed[...]3.jpg 1024w, c6[...]b.jpg 1920w, b6[...]3.jpg 2560w, 57[...]e.jpg"
webpack-image-srcset-loader
should be placed before all other loaders
Try webpack-sharp-loader
if you want to do other processing with your image before or after resizing
1module.exports = { 2 // ... 3 module: { 4 rules: [ 5 // ... 6 { 7 test: /\.(png|jpe?g|webp|tiff?)$/i, 8 oneOf: [ 9 { 10 // if the import url looks like "some.png?srcset..." 11 resourceQuery: /srcset/, 12 use: [ 13 { 14 loader: "webpack-image-srcset-loader", 15 options: { 16 sizes: ["480w", "1024w", "1920w", "2560w", "original"], 17 }, 18 }, 19 "file-loader", 20 "webpack-image-resize-loader", 21 // add webpack-sharp-loader if you want to pre-process your image e.g. rotating, flipping 22 ], 23 }, 24 { 25 // if no previous resourceQuery match 26 use: "file-loader", 27 }, 28 ], 29 }, 30 ], 31 }, 32};
Additional options in the query (that thing after ?
) such as quality
or format
here will be passed down to webpack-image-resize-loader. See webpack-image-resize-loader's options.
For example:
1import webpSrcSet from "./some_pic.jpg?srcset&format=webp"; 2 3// webpSrcSet will be "00[...]5.webp 480w, 40[...]3.webp 1024w, 76[...]b.webp 1920w, a4[...]c.webp 2560w, b1[...]c.webp"
Name | Type | Default | Description |
---|---|---|---|
sizes | (string)[] | undefined | Sizes in the output srcset. |
scaleUp | boolean | false | Whether or not to scale up the image when the desired width is greater than the image width. |
resizeLoaderOptionsGenerator | function | undefined | A function that returns the option to be passed on to the next loader. |
esModule | boolean | true | Whether the export is in ES modules syntax or CommonJS modules syntax |
sizes
An array containing strings in the format "[number]w"
, "[number]x"
, or "original"
. The numbers cannot contain decimals.
Allowed: ["10w", "1x", "2x", "original"]
Not allowed: ["10.0w", "1.5x", "2.0x"]
When using "[number]x"
, the original size of the image will be used for the greatest value. For example, if an image is 10×10
in size, and sizes
is ["1x", "2x"]
, the output image will have sizes 5×5
for "1x"
and 10×10
for "2x"
.
scaleUp
When true, if the desired width is greater than the image width, the size will not be included in the output srcset string. For example, if the original image is 10×10
in size, and the sizes
array is ["5w", "10w", "15w"]
, when scaleUp
is true
the output string is "image1.jpg 5w, image2.jpg 10w, image3.jpg 15w"
, when scaleUp
is false
the output string is "image1.jpg 5w, image2.jpg 10w"
.
Note: this option has no effect on "[number]x"
or "original"
resizeLoaderOptionsGenerator
1function defaultResizeLoaderOptionsGenerator(width, scale, existingOptions) { 2 return { 3 ...existingOptions, 4 ...(existingOptions?.fileLoaderOptionsGenerator 5 ? { 6 fileLoaderOptionsGenerator: existingOptions.fileLoaderOptionsGenerator.toString(), 7 } 8 : {}), 9 // since we filtered out all the width that are too wide, 10 // nothing to worry about there, need this to make sure 11 // scales larger than 1x works 12 scaleUp: true, 13 width, 14 scale, 15 }; 16}
If you wish to use a resize loader other than webpack-image-resize-loader. You may customize how the width and scale is passed down to that loader`s options.
// width is either a number or undefined
// scale is either a number or undefined
// existingOptions is either the existing options for the next loader or undefined
(width, scale, existingOptions: object) => {
...
return { ...existingOptions };
}
For example, if sizes
is ["10w", "1x", "2x", "original"]
, resizeLoaderOptionsGenerator
will be called with
resizeLoaderOptionsGenerator(10, undefined, existingOptions)
for 10w
resizeLoaderOptionsGenerator(undefined, 1, existingOptions)
for 1x
resizeLoaderOptionsGenerator(undefined, 2, existingOptions)
for 2x
resizeLoaderOptionsGenerator(undefined, undefined, existingOptions)
for "original"
esModule
Whether the export is in ES modules syntax or CommonJS modules syntax. If you don't know what it is or whether or not you need it, leave is as default.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/4 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
71 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More