An open API service indexing awesome lists of open source software.

https://github.com/schpet/srcset-codegen

generate typescript files from a directory of images with width, height and srcset attributes
https://github.com/schpet/srcset-codegen

codegen react srcset vite

Last synced: 14 days ago
JSON representation

generate typescript files from a directory of images with width, height and srcset attributes

Awesome Lists containing this project

README

        

# SRCSET CODEGEN

generates typescript for a images scaled at different [scale factors](https://developer.apple.com/design/human-interface-guidelines/images#Resolution) with filenames ending in @2x, @3x and so on.

```diff
.
├── sd
+│ ├── smile.ts
│ ├── smile.png
│ ├── [email protected]
│ └── [email protected]
+├── single.ts
+├── smile.ts
+├── vector.ts
├── single.png
├── smile.png
├── [email protected]

```

example of generated code:

```ts
// generated by srcset-codegen
import src from "./smile.png";
import src2x from "./[email protected]";
import src3x from "./[email protected]";

const width = 107;
const height = 107;
const srcSet = `${src2x} 2x, ${src3x} 3x`;
export default { src, width, height, srcSet };
```

## Usage

```bash
npx srcset-codegen generate src/images

# or, to watch for filesystem changes
npx srcset-codegen generate --watch src/images
```

## Notes

inspired by [react-native images](https://reactnative.dev/docs/images).