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: 4 months ago
JSON representation
generate typescript files from a directory of images with width, height and srcset attributes
- Host: GitHub
- URL: https://github.com/schpet/srcset-codegen
- Owner: schpet
- Created: 2024-04-30T17:23:46.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-31T14:56:42.000Z (over 1 year ago)
- Last Synced: 2025-07-22T13:57:16.887Z (4 months ago)
- Topics: codegen, react, srcset, vite
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/srcset-codegen
- Size: 247 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
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
│ ├── smile@2x.png
│ └── smile@3x.png
+├── single.ts
+├── smile.ts
+├── vector.ts
├── single.png
├── smile.png
├── smile@2x.png
```
example of generated code:
```ts
// generated by srcset-codegen
import src from "./smile.png";
import src2x from "./smile@2x.png";
import src3x from "./smile@3x.png";
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).