Installations
npm install react-native-web-image-loader
Releases
Unable to fetch releases
Developer
peter-jozsa
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
12.9.1
NPM Version
6.10.2
Statistics
44 Stars
19 Commits
14 Forks
4 Watching
8 Branches
4 Contributors
Updated on 22 Jul 2024
Bundle Size
251.98 kB
Minified
68.70 kB
Minified + Gzipped
Languages
TypeScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
1,723,855
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
React Native Web Image Loader
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:
Installation
Install it via npm:
1$ npm install --save-dev react-native-web-image-loader
Usage
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.
Configuration
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 thecontext
query parameter or option.[hash]
the hash of the content,hex
-encodedmd5
by default
scalings
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 tofalse
.
Examples
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
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.md:0
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 6 are checked with a SAST tool
Reason
16 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
Score
1.9
/10
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