{"id":29365507,"url":"https://github.com/natrim/esbuild-plugin-inline-image","last_synced_at":"2025-07-09T11:12:06.450Z","repository":{"id":44504051,"uuid":"432251273","full_name":"natrim/esbuild-plugin-inline-image","owner":"natrim","description":"esbuild plugin for inlining yout images conditionaly on size","archived":false,"fork":false,"pushed_at":"2025-04-08T10:32:52.000Z","size":19,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-11T20:42:39.664Z","etag":null,"topics":["esbuild","esbuild-plugin","image"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/natrim.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-11-26T17:12:35.000Z","updated_at":"2025-04-08T10:32:55.000Z","dependencies_parsed_at":"2022-09-05T04:50:32.422Z","dependency_job_id":null,"html_url":"https://github.com/natrim/esbuild-plugin-inline-image","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/natrim/esbuild-plugin-inline-image","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natrim%2Fesbuild-plugin-inline-image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natrim%2Fesbuild-plugin-inline-image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natrim%2Fesbuild-plugin-inline-image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natrim%2Fesbuild-plugin-inline-image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/natrim","download_url":"https://codeload.github.com/natrim/esbuild-plugin-inline-image/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/natrim%2Fesbuild-plugin-inline-image/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260670068,"owners_count":23044343,"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":["esbuild","esbuild-plugin","image"],"created_at":"2025-07-09T11:12:03.814Z","updated_at":"2025-07-09T11:12:06.438Z","avatar_url":"https://github.com/natrim.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# esbuild-plugin-inline-image\n\n[esbuild](https://esbuild.github.io/) plugin for inlining yout images conditionaly on size\n\nAka. switches loader for image between `file` and `dataurl` depending on size (as in Webpack)\n\n*Well, technically can be used even for non images (just set the right extensions), but who would want that?*\n\n## Instalation\n\n```sh\nyarn add esbuild-plugin-inline-image\n```\n\nor\n\n```sh\nnpm install esbuild-plugin-inline-image\n```\n\n## Usage\n\nAdd it to your `esbuild` plugins list:\n\n```js\nconst esbuild = require(\"esbuild\");\nconst inlineImage = require(\"esbuild-plugin-inline-image\");\n\nesbuild.build({\n  ...\n  plugins: [\n    ...\n    inlineImage()\n  ]\n  ...\n});\n```\n\nYou can then import images\n\n```js\nimport logo from \"../assets/logo.png\";\n```\n\n## Options\n\nBy default it works for `jpg, png, gif, svg, webp, avif` extensions.\n\nYou can customize the options (ie. to disable svg loading if being handled by different plugin)\n\n```js\ninlineImage({\n  // options\n});\n```\n\n### Allowed options are:\n\n- `limit`: define image limit (in bytes) for size after which the image wll not be inline (default is `10000`)\n\n  - limit can also be set from env as `IMAGE_INLINE_SIZE_LIMIT`\n  - setting limit to 0 disables inlining, -1 will always inline\n  - in case you pass function, the image will be inlined if it returns `true` (or `Promise` that resolves to `true`)\n    - the function get's passed `onLoad` [args](https://esbuild.github.io/plugins/#load-arguments)\n\n- `extensions`: an array of extensions to work on (default is `[` `\"jpg\"`, `\"jpeg\"`, `\"png\"`, `\"gif\"`, `\"svg\"`, `\"webp\"`, `\"avif\"` `]`)\n\n- `filter`: you can also pass filter for onLoad directly, but in this case you need to manually set `esbuild` [loader](https://esbuild.github.io/api/#loader) option for the extensions to `file`\n\n- `namespace`: custom namespace for the plugin to operate on, default's to built-in `file`\n\n- `loaderRegisterExtensions`: register `extensions` to esbuild loader? default's to `true`, set `false` to disable\n\n## Examples\n\nUse plugin multiple times to have different size for different extensions\n\n```js\nesbuild.build({\n  ...\n  plugins: [\n    ...\n    inlineImage({\n      extensions: [\"svg\", \"webp\", \"avif\"]\n    }),\n    inlineImage({\n      limit: 5000,\n      extensions: [\"jpg\", \"jpeg\", \"gif\"]\n    }),\n    inlineImage({\n      limit: 2000,\n      extensions: [\"png\"]\n    })\n  ]\n  ...\n});\n```\n\nUse function to decide inlining\n\n```js\nesbuild.build({\n  ...\n  plugins: [\n    ...\n    inlineImage({\n      limit: ({ path }) =\u003e {\n        // inline only svg, other extensions get only loader set to file\n        return path.endsWith(\".svg\");\n      }\n    }),\n  ]\n  ...\n});\n```\n\nSet limit to -1 to inline all images\n\n```js\nesbuild.build({\n  ...\n  plugins: [\n    ...\n    inlineImage({\n      limit: -1\n    })\n  ]\n  ...\n});\n```\n\nSet limit to 0, to disable inlining (extensions will only get registed to `loader`)\n\n```js\nesbuild.build({\n  ...\n  plugins: [\n    ...\n    inlineImage({\n      limit: 0\n    })\n  ]\n  ...\n});\n```\n\n## License\n\nLicensed as MIT open source.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnatrim%2Fesbuild-plugin-inline-image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnatrim%2Fesbuild-plugin-inline-image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnatrim%2Fesbuild-plugin-inline-image/lists"}