Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
dazuaz committed Jun 15, 2022
1 parent 1791b6f commit ac26601
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion README.md
Expand Up @@ -93,6 +93,36 @@ module.exports = {
}
```

### Typescript



```typescript
//declare a module to your type definitions files *.d.ts
interface ResponsiveImageOutput {
src: string
srcSet: string
placeholder: string | undefined
images: { path: string; width: number; height: number }[]
width: number
height: number
toString: () => string
}

declare module '*!rl' {
const src: ResponsiveImageOutput
export default src
}
```

```
import responsiveImage from 'img/myImage.jpg?sizes[]=300,sizes[]=600,sizes[]=1024,sizes[]=2048!rl';
import responsiveImageWebp from 'img/myImage.jpg?sizes[]=300,sizes[]=600,sizes[]=1024,sizes[]=2048&format=webp!rl';
...
```

---

Then import images in your JavaScript files:

```js
Expand Down Expand Up @@ -161,7 +191,7 @@ ReactDOM.render(
)
```

You can also use JSON5 notation:
You can also use [JSON5](https://json5.org/) notation:

```
<source srcSet={require('./image.jpg?{sizes:[50,100,200,300,400,500,600,700,800], format: "webp"}').srcSet} type='image/webp'/>
Expand Down

0 comments on commit ac26601

Please sign in to comment.