Gathering detailed insights and metrics for @endiliey/responsive-loader
Gathering detailed insights and metrics for @endiliey/responsive-loader
Gathering detailed insights and metrics for @endiliey/responsive-loader
Gathering detailed insights and metrics for @endiliey/responsive-loader
npm install @endiliey/responsive-loader
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (95.13%)
Shell (4.87%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
BSD-3-Clause License
2 Stars
117 Commits
1 Forks
1 Branches
1 Contributors
Updated on Apr 06, 2023
Latest Version
1.3.2
Package Id
@endiliey/responsive-loader@1.3.2
Size
8.05 kB
NPM Version
6.9.0
Node Version
8.11.3
Published on
Nov 18, 2019
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A webpack loader for responsive images. Creates multiple images from one source image, and returns a srcset
. For more information on how to use srcset
, read Responsive Images: If you’re just changing resolutions, use srcset.. Browser support is pretty good.
Note: starting with v1.0.0, responsive-loader is only compatible with webpack 2+. For webpack 1 support, use responsive-loader@0.7.0
npm install responsive-loader jimp --save-dev
Per default, responsive-loader uses jimp to transform images. which needs to be installed alongside responsive-loader. Because jimp is written entirely in JavaScript and doesn't have any native dependencies it will work anywhere. The main drawback is that it's pretty slow.
npm install responsive-loader sharp --save-dev
For super-charged performance, responsive-loader also works with sharp. It's recommended to use sharp if you have lots of images to transform.
If you want to use sharp, you need to configure responsive-loader to use its adapter:
1module.exports = { 2 // ... 3 module: { 4 rules: [ 5 { 6 test: /\.(jpe?g|png)$/i, 7 loader: 'responsive-loader', 8 options: { 9+ adapter: require('responsive-loader/sharp') 10 } 11 } 12 ] 13 }, 14}
Add a rule for loading responsive images to your webpack config:
1module.exports = { 2 // ... 3 module: { 4 rules: [ 5 { 6 test: /\.(jpe?g|png)$/i, 7 loader: 'responsive-loader', 8 options: { 9 // If you want to enable sharp support: 10 // adapter: require('responsive-loader/sharp') 11 } 12 } 13 ] 14 }, 15}
Then import images in your JavaScript files:
1// Outputs three images with 100, 200, and 300px widths 2const responsiveImage = require('myImage.jpg?sizes[]=100,sizes[]=200,sizes[]=300'); 3 4// responsiveImage.srcSet => '2fefae46cb857bc750fa5e5eed4a0cde-100.jpg 100w,2fefae46cb857bc750fa5e5eed4a0cde-200.jpg 200w,2fefae46cb857bc750fa5e5eed4a0cde-300.jpg 300w' 5// responsiveImage.images => [{height: 50, path: '2fefae46cb857bc750fa5e5eed4a0cde-100.jpg', width: 100}, {height: 100, path: '2fefae46cb857bc750fa5e5eed4a0cde-200.jpg', width: 200}, {height: 150, path: '2fefae46cb857bc750fa5e5eed4a0cde-300.jpg', width: 300}] 6// responsiveImage.src => '2fefae46cb857bc750fa5e5eed4a0cde-100.jpg' 7// responsiveImage.toString() => '2fefae46cb857bc750fa5e5eed4a0cde-100.jpg' 8ReactDOM.render(<img srcSet={responsiveImage.srcSet} src={responsiveImage.src} />, el); 9 10// Or you can just use it as props, `srcSet` and `src` will be set properly 11ReactDOM.render(<img {...responsiveImage} />, el);
Or use it in CSS (only the first resized image will be used, if you use multiple sizes
):
1.myImage { background: url('myImage.jpg?size=1140'); } 2 3@media (max-width: 480px) { 4 .myImage { background: url('myImage.jpg?size=480'); } 5}
1// Outputs placeholder image as a data URI, and three images with 100, 200, and 300px widths 2const responsiveImage = require('myImage.jpg?placeholder=true&sizes[]=100,sizes[]=200,sizes[]=300'); 3 4// responsiveImage.placeholder => 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAIBAQE…' 5ReactDOM.render( 6 <div style={{ 7 height: responsiveImage.height, 8 width: responsiveImage.width, 9 backgroundSize: 'cover', 10 backgroundImage: 'url("' + responsiveImage.placeholder + '")' 11 }}> 12 <img src={responsiveImage.src} srcSet={responsiveImage.srcSet} /> 13 </div>, el);
Option | Type | Default | Description |
---|---|---|---|
name | string | [hash]-[width].[ext] | Filename template for output files. |
outputPath | `string | Function` | undefined |
publicPath | `string | Function` | undefined |
context | string | this.options.context | Custom file context, defaults to webpack.config.js context |
sizes | array | original size | Specify all widths you want to use; if a specified size exceeds the original image's width, the latter will be used (i.e. images won't be scaled up). You may also declare a default sizes array in the loader options in your webpack.config.js . |
size | integer | original size | Specify one width you want to use; if the specified size exceeds the original image's width, the latter will be used (i.e. images won't be scaled up) |
min | integer | As an alternative to manually specifying sizes , you can specify min , max and steps , and the sizes will be generated for you. | |
max | integer | See min above | |
steps | integer | 4 | Configure the number of images generated between min and max (inclusive) |
quality | integer | 85 | JPEG compression quality |
format | string | original format | Either png or jpg ; use to convert to another format |
placeholder | boolean | false | A true or false value to specify wether to output a placeholder image as a data URI |
placeholderSize | integer | 40 | A number value specifying the width of the placeholder image, if enabled with the option above |
adapter | Adapter | JIMP | Specify which adapter to use. Can only be specified in the loader options. |
disable | boolean | false | Disable processing of images by this loader (useful in development). srcSet and other attributes will still be generated but only for the original size. Note that the width and height attributes will both be set to 100 but the image will retain its original dimensions. |
emitFile | boolean | true | If true , emits a file (writes a file to the filesystem). If false , the loader will still return a object with the public URI but will not emit the file. It is often useful to disable this option for server-side packages. |
background: number
— Background fill when converting transparent to opaque images. Make sure this is a valid hex number, e.g. 0xFFFFFFFF
)background: string
— Background fill when converting transparent to opaque images. E.g. #FFFFFF
Set a default sizes
array, so you don't have to declare them with each require
.
1module.exports = { 2 entry: {...}, 3 output: {...}, 4 module: { 5 rules: [ 6 { 7 test: /\.(jpe?g|png)$/i, 8 loader: 'responsive-loader', 9 options: { 10 sizes: [300, 600, 1200, 2000], 11 placeholder: true, 12 placeholderSize: 50 13 } 14 } 15 ] 16 }, 17}
Maybe you want to use another image processing library or you want to change an existing one's behavior. You can write your own adapter with the following signature:
1type Adapter = (imagePath: string) => { 2 metadata: () => Promise<{width: number, height: number}> 3 resize: (config: {width: number, mime: string, options: Object}) => Promise<{data: Buffer, width: number, height: number}> 4}
The resize
method takes a single argument which has a width
, mime
and options
property (which receives all loader options)
In your webpack config, require your adapter
1{ 2 test: /\.(jpe?g|png)$/i, 3 loader: 'responsive-loader', 4 options: { 5 adapter: require('./my-adapter') 6 foo: 'bar' // will get passed to adapter.resize({width, mime, options: {foo: 'bar}}) 7 } 8}
1x
, 2x
sizes.No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
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
96 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
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