Gathering detailed insights and metrics for loader-probe-image-size
Gathering detailed insights and metrics for loader-probe-image-size
Gathering detailed insights and metrics for loader-probe-image-size
Gathering detailed insights and metrics for loader-probe-image-size
npm install loader-probe-image-size
Typescript
Module System
Node Version
NPM Version
TypeScript (95.07%)
JavaScript (4.93%)
Total Downloads
1,199
Last Day
1
Last Week
2
Last Month
3
Last Year
140
1 Stars
8 Commits
2 Watching
16 Branches
1 Contributors
Latest Version
1.0.5
Package Id
loader-probe-image-size@1.0.5
Unpacked Size
7.02 kB
Size
2.94 kB
File Count
3
NPM Version
6.9.0
Node Version
10.16.3
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
0%
2
Compared to previous week
Last month
-85.7%
3
Compared to previous month
Last year
-11.9%
140
Compared to previous year
This loader uses probe-image-size. While there are already a few other webpack loaders out there that will additionally fetch images sizes - some did not seem very active to me. some had problems loading guetzli-fied JPEGs, etc.
So with all the best intentions - here is yet another loader.
There are certain use cases where it is beneficial to know the dimensions of the image you (or your page) is about to show.
1npm install --save-dev loader-probe-image-size
Add the loader to your webpack configuration (or replace your existing image loader)
1// webpack.config.[ts|js] 2// ... 3 module: { 4 loaders: [ 5 { 6 test: /\.(gif|jpe?g|png|svg|webp|ico)$/, 7 use: [{ 8 loader: 'loader-probe-image-size', 9 options: { 10 context: path.resolve(__dirname, 'src') 11 } 12 } 13 ] 14 } 15 ] 16 } 17// ...
Advanced usage The loader uses the interpolatename function from loader-utils - meaning you can modify the filename of the emitted file via options: {name: ...} .
The following tokens are replaced in the name
parameter:
[ext]
the extension of the resource[name]
the basename of the resource[path]
the path of the resource relative to the context
query parameter or option.[folder]
the folder the resource is in.[emoji]
a random emoji representation of options.content
[emoji:<length>]
same as above, but with a customizable number of emojis[contenthash]
the hash of options.content
(Buffer) (by default it's the hex digest of the md5 hash)[<hashType>:contenthash:<digestType>:<length>]
optionally one can configure
hashType
s, i. e. sha1
, md5
, sha256
, sha512
digestType
s, i. e. hex
, base26
, base32
, base36
, base49
, base52
, base58
, base62
, base64
length
the length in chars[hash]
the hash of options.content
(Buffer) (by default it's the hex digest of the md5 hash)[<hashType>:hash:<digestType>:<length>]
optionally one can configure
hashType
s, i. e. sha1
, md5
, sha256
, sha512
digestType
s, i. e. hex
, base26
, base32
, base36
, base49
, base52
, base58
, base62
, base64
length
the length in chars[N]
the N-th match obtained from matching the current file name against options.regExp
Shamelessly stolen from / source: https://github.com/webpack/loader-utils#interpolatename
Import images from within your code
1import image from './myimagefile.jpeg'; 2 3// => emits myimagefile.jpeg 4// => image is an object { 5// src: string, 6// height: number 7// width: number 8// type: [svg|webp|jpeg|png|...] 9// toString: () => string ... 10// }
And for those fancy typescript users - you might want to add additional info to your image modules, e.g. /src/@types/images.d.ts, so your IDE of choice will assist you a bit more.
1declare module '*.jpg' { 2 export const src: string; 3 export const type: string; 4 export const width: number; 5 export const height: number; 6}
No vulnerabilities found.
Reason
no binaries found in the repo
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/8 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
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
62 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-30
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