{"id":15426801,"url":"https://github.com/porges/snowpack-plugin-image-resizer","last_synced_at":"2026-02-01T05:34:20.183Z","repository":{"id":38963219,"uuid":"414741964","full_name":"Porges/snowpack-plugin-image-resizer","owner":"Porges","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-08T01:57:30.000Z","size":650,"stargazers_count":0,"open_issues_count":10,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-02T05:44:17.948Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Porges.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-07T20:04:43.000Z","updated_at":"2021-11-14T16:22:06.000Z","dependencies_parsed_at":"2023-02-08T04:17:22.450Z","dependency_job_id":null,"html_url":"https://github.com/Porges/snowpack-plugin-image-resizer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Porges%2Fsnowpack-plugin-image-resizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Porges%2Fsnowpack-plugin-image-resizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Porges%2Fsnowpack-plugin-image-resizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Porges%2Fsnowpack-plugin-image-resizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Porges","download_url":"https://codeload.github.com/Porges/snowpack-plugin-image-resizer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245972671,"owners_count":20702721,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T17:58:04.306Z","updated_at":"2026-02-01T05:34:20.155Z","avatar_url":"https://github.com/Porges.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# snowpack-plugin-image-resizer\n\n[![npm](https://img.shields.io/npm/v/snowpack-plugin-image-resizer)](https://www.npmjs.com/package/snowpack-plugin-image-resizer)\n\nA [snowpack](https://github.com/snowpackjs/snowpack#readme) plugin for loading images and resizing them to use as responsive images.\n\n## ⚠️ Experimental ⚠️\n\nAt the moment I have only used this with [Astro](https://github.com/snowpackjs/astro#readme). It is somewhat inspired by [responsive-loader](https://github.com/dazuaz/responsive-loader#readme), which I used to use with `webpack`.\n\n## Usage\n\n### Installation\n\nFirst, install the package:\n\n```sh\nnpm install --save-dev snowpack-plugin-image-resizer\n```\n\nThen, add the plugin to your project’s config file:\n\n#### `snowpack.config.js`\n```js\n/** @type {import(\"snowpack\").SnowpackUserConfig } */\nmodule.exports = {\n  plugins: [\n    [\"snowpack-plugin-image-resizer\"]\n  ],\n};\n```\n\nDone! Now, any image imports (with the configured extensions) will be processed by the plugin and multiple outputs in different sizes will be generated.\n\nThe result of importing an image is a JavaScript structure with type `ImageImport`:\n\n```ts\ntype ImageImport = {\n    /** The original, unmodified, image URI. */\n    src: string;\n    /** The width of the original image. */\n    width: number;\n    /** The height of the original image. */\n    height: number;\n    /** The resized images in srcset format (for use on `\u003cimg\u003e`).\n     * Note that to use the `srcset` you will also need to provide your\n     * own `sizes` attribute, which this library cannot create for you.\n     * Refer to MDN’s Reponsive Images article for more. */\n    srcset: string;\n    /** The resized images in a structured format, in case\n     * you need to do anything else with them. */\n    images: {\n        src: string;\n        width: number;\n    }[];\n};\n```\n\nThis means you can use the imported image as follows:\n\n```ts\nimport myImage from \"./myImage.png\";\n…\nreturn (\n  \u003cimg\n   src={myImage.src}\n   width={myImage.width}\n   height={myImage.height}\n   srcset={myImage.srcset} \n   alt=\"…\" /\u003e\n);\n```\n\n### TypeScript Support\n\nIf you are using TypeScript, you can add support for these image imports by adding a file like this to your project:\n\n#### `images.d.ts`\n```ts\ndeclare module \"*.png\" {\n    import { ImageImport } from \"snowpack-plugin-image-resizer\";\n    const value: ImageImport;\n    export default value;\n}\n\ndeclare module \"*.jpeg\" {\n    import { ImageImport } from \"snowpack-plugin-image-resizer\";\n    const value: ImageImport;\n    export default value;\n}\n\ndeclare module \"*.jpg\" {\n    import { ImageImport } from \"snowpack-plugin-image-resizer\";\n    const value: ImageImport;\n    export default value;\n}\n\ndeclare module \"*.webp\" {\n    import { ImageImport } from \"snowpack-plugin-image-resizer\";\n    const value: ImageImport;\n    export default value;\n}\n```\n\n## Configuring\n\nYou can also set some options. Their defaults are shown below:\n\n#### `snowpack.config.js`\n```js\n/** @type {import(\"snowpack-plugin-image-resizer\").Options} */\nconst imageLoaderOptions = {\n  // file extensions to load\n  inputs: [\".jpg\", \".jpeg\", \".png\", \".webp\"],\n\n  // target sizes to resize to\n  sizes: [300, 600, 800, 1200, 1600],\n\n  // images smaller than this are turned into data: uris\n  inlineSizeLimit: 1024,\n};\n\n/** @type {import(\"snowpack\").SnowpackUserConfig } */\nmodule.exports = {\n  plugins: [\n    [\"snowpack-plugin-image-resizer\", imageLoaderOptions]\n  ],\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fporges%2Fsnowpack-plugin-image-resizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fporges%2Fsnowpack-plugin-image-resizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fporges%2Fsnowpack-plugin-image-resizer/lists"}