{"id":15638709,"url":"https://github.com/bluwy/svelte-preprocess-import-assets","last_synced_at":"2025-04-07T08:28:51.585Z","repository":{"id":44966851,"uuid":"362004111","full_name":"bluwy/svelte-preprocess-import-assets","owner":"bluwy","description":"Import assets directly in your markup","archived":false,"fork":false,"pushed_at":"2024-08-19T04:48:45.000Z","size":136,"stargazers_count":97,"open_issues_count":4,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T06:07:29.314Z","etag":null,"topics":["assets","preprocess","svelte"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/svelte-preprocess-import-assets","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/bluwy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"bluwy"}},"created_at":"2021-04-27T06:26:18.000Z","updated_at":"2025-03-04T15:03:19.000Z","dependencies_parsed_at":"2023-11-06T06:21:46.270Z","dependency_job_id":"25ec110d-5243-4abd-ab8f-32937c80d382","html_url":"https://github.com/bluwy/svelte-preprocess-import-assets","commit_stats":{"total_commits":55,"total_committers":4,"mean_commits":13.75,"dds":0.07272727272727275,"last_synced_commit":"050dcdc7ca45bc9c69959a850bc84c8f1c8871e3"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluwy%2Fsvelte-preprocess-import-assets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluwy%2Fsvelte-preprocess-import-assets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluwy%2Fsvelte-preprocess-import-assets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluwy%2Fsvelte-preprocess-import-assets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bluwy","download_url":"https://codeload.github.com/bluwy/svelte-preprocess-import-assets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247618513,"owners_count":20967795,"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":["assets","preprocess","svelte"],"created_at":"2024-10-03T11:22:35.292Z","updated_at":"2025-04-07T08:28:51.562Z","avatar_url":"https://github.com/bluwy.png","language":"JavaScript","funding_links":["https://github.com/sponsors/bluwy"],"categories":[],"sub_categories":[],"readme":"# svelte-preprocess-import-assets\n\nImport assets directly in the markup. Supports Svelte 3, 4, and 5.\n\n\u003e NOTE: Svelte 5 support is experimental and may break between versions.\n\n**Convert this:**\n\n```svelte\n\u003ch1\u003eLook at this image\u003c/h1\u003e\n\u003cimg src=\"./assets/cool-image.png\" alt=\"cool image\" /\u003e\n```\n\n**Into this:**\n\n```svelte\n\u003cscript\u003e\n  import ___ASSET___0 from './assets/cool-image.png'\n\u003c/script\u003e\n\n\u003ch1\u003eLook at this image\u003c/h1\u003e\n\u003cimg src={___ASSET___0} alt=\"cool image\" /\u003e\n```\n\n## Usage\n\nInstall with your package manager:\n\n```bash\nnpm install --save-dev svelte-preprocess-import-assets\n```\n\nInclude the preprocessor in your bundler's Svelte plugin `preprocess` option:\n\n```js\nimport { importAssets } from 'svelte-preprocess-import-assets'\n\nsvelte({ preprocess: [importAssets()] })\n\n// or in svelte.config.js\nexport default {\n  preprocess: [importAssets()],\n  // ... other svelte options\n}\n```\n\n## API\n\nThe `importAssets()` function receives an optional options object for its first parameter. The object may contain these properties:\n\n### sources\n\n- **Type:** `AssetSource[] | ((defaultSources: AssetSource[]) =\u003e AssetSource[])`\n\n  ```ts\n  interface AssetSource {\n    tag: string\n    srcAttributes?: string[]\n    srcsetAttributes?: string[]\n    filter?: (metadata: FilterMetadata) =\u003e boolean\n  }\n\n  interface FilterMetadata {\n    tag: string\n    attribute: string\n    value: string\n    attributes: Record\u003cstring, string\u003e\n  }\n  ```\n\n- **Default:** See `DEFAULT_SOURCES` in [src/constants.js](./src/constants.js)\n\n  These are the sources to look for when scanning for imports. You can provide an entirely different list of sources, or declare a function to access the default sources and augment it. The supported tags and attributes are based on [html-loader](https://github.com/webpack-contrib/html-loader#sources) (except `icon-uri`). Component name as `tag` is also supported.\n\n  ```js\n  {\n    sources: (defaultSources) =\u003e {\n      return [\n        ...defaultSources,\n        // Also scan `data-src` and `data-srcset` of an img tag\n        {\n          tag: 'img',\n          srcAttributes: ['data-src'],\n          srcsetAttributes: ['data-srcset'],\n        },\n      ]\n    },\n  }\n  ```\n\n### importPrefix\n\n- **Type:** `string`\n- **Default:** `___ASSET___`\n\n  The string to be prefixed for asset import names, e.g. `___ASSET___0` and `___ASSET___1`.\n\n### http\n\n- **Type:** `boolean`\n- **Default:** `false`\n\n  Whether a URL with http/https protocol should be converted to an import.\n\n### urlFilter\n\n- **Type:** `(url: string) =\u003e boolean`\n\n  Whether a URL should be converted into an import.\n\n  ```js\n  {\n    // Include URLs with specific extensions only\n    urlFilter: (url) =\u003e /\\.(png|jpg|gif|webp)$/.test(url),\n  }\n  ```\n\n## Recipes\n\n### Ignore an element\n\n```svelte\n\u003c!-- svelte-preprocess-import-assets-ignore --\u003e\n\u003cimg src=\"./assets/cool-image.png\" alt=\"cool image\" /\u003e\n```\n\n## Attributions\n\n- [svelte-assets-preprocessor](https://github.com/pchynoweth/svelte-assets-preprocessor): Initial motivation to reduce dependencies.\n\n## Sponsors\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://bjornlu.com/sponsors.svg\"\u003e\n    \u003cimg src=\"https://bjornlu.com/sponsors.svg\" alt=\"Sponsors\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluwy%2Fsvelte-preprocess-import-assets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbluwy%2Fsvelte-preprocess-import-assets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluwy%2Fsvelte-preprocess-import-assets/lists"}