Gathering detailed insights and metrics for react-native-web-image-loader
Gathering detailed insights and metrics for react-native-web-image-loader
Gathering detailed insights and metrics for react-native-web-image-loader
Gathering detailed insights and metrics for react-native-web-image-loader
npm install react-native-web-image-loader
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
44 Stars
19 Commits
14 Forks
4 Watching
8 Branches
4 Contributors
Updated on 22 Jul 2024
Minified
Minified + Gzipped
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
-28.1%
981
Compared to previous day
Last week
-8.3%
5,686
Compared to previous week
Last month
-10.9%
29,671
Compared to previous month
Last year
3.5%
374,908
Compared to previous year
Using this loader will automatically bundle scaled counterparts too. Since Image component of react-native-web accepts objects as value of its source property it is possible to display scaled images based on device pixel ratio.
This loader will inject an AdaptiveImage class into your bundle. Everywhere you require an image an instance of AdaptiveImage will be returned.
This is my first node.js package so every recommendation is welcome. :smile:
Install it via npm:
1$ npm install --save-dev react-native-web-image-loader
In your webpack config use it as a loader for images:
1{ 2 ..., 3 module: { 4 rules: [ 5 { 6 test: /\.(png|jpe?g|gif)$/, 7 options: { 8 name: 'static/media/[name].[hash:8].[ext]', 9 // publicPath: 'https://cdn.example.com/', // uncomment to override webpack public path 10 // esModule: true 11 scalings: { '@2x': 2, '@3x': 3 }, 12 }, 13 loader: 'react-native-web-image-loader', 14 }, 15 ] 16 } 17}
You're done.
The following configuration variables can be defined in the options
object:
name
The name template of the output files. (default: [hash].[ext]
) You can use the following placeholders:
[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.[hash]
the hash of the content, hex
-encoded md5
by defaultscalings
is an object where the keys are the possible filename suffixes and values are the amount of scale. (Default is {"@2x": 2, "@3x": 3}
, which means filenames ending with "@2x" will be used on devices where the pixel-ratio is 2)imageClassPath
the path of image class that should be used instead of AdaptiveImage. This gives you the possibility to use your own image class representation.publicPath
Specifies a custom public path for the target file(s). Default: __webpack_public_path__ + outputPath
. You dynamically set custom public path by passing a function.outputPath
Specify a filesystem path where the target file(s) will be placed.esModule
By default, react-native-web-image-loader
generates JS modules that use the ES modules syntax. You can disable it by setting its value to false
.We have the following files:
|--assets/
|-- pic1.png
|-- pic1@2x.png
|-- pic1-3x.png
|--index.js
webpack.config.js
1module.exports = { 2 ..., 3 module: { 4 rules: [ 5 { 6 test: /\.(png|jpe?g|gif)$/, 7 options: { 8 name: 'static/media/[name].[hash:8].[ext]', 9 scalings: { '@2x': 2, '@3x': 3 }, 10 }, 11 loader: 'react-native-web-image-loader', 12 }, 13 ] 14 } 15}
index.js
1import React from 'react' 2import { Image } from 'react-native-web' 3 4export default class Picture extends React.Component { 5 render() { 6 return <Image source={require('./assets/pic1.png')} /> 7 } 8}
Value of source property looks like this:
1AdaptiveImage { 2 "data": { 3 "uri": "static/media/pic1.abcd1234.png", 4 "uri@2x": "static/media/pic1@2x.4321dcba.png", 5 "uri@3x": "static/media/pic1-3x.efgh5678.png", 6 "width": 128, 7 "height": 64 8 }, 9 get uri(), // returns uri based on pixel ratio 10 get width(), // returns this.data.width 11 get height(), // returns this.data.height 12}
So when Image component resolves source it will treat it as a normal object. But value of uri is dynamically returned according to current device pixel ratio.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 3/16 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- 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
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
16 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
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