{"id":13447659,"url":"https://github.com/sormy/rollup-plugin-smart-asset","last_synced_at":"2026-03-02T22:10:42.809Z","repository":{"id":38274286,"uuid":"160303643","full_name":"sormy/rollup-plugin-smart-asset","owner":"sormy","description":"Rollup plugin to rebase, inline or copy assets referenced from the code","archived":false,"fork":false,"pushed_at":"2024-02-28T15:39:20.000Z","size":1219,"stargazers_count":33,"open_issues_count":14,"forks_count":11,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-29T09:26:13.115Z","etag":null,"topics":["rollup-plugin"],"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/sormy.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-04T05:29:36.000Z","updated_at":"2024-04-24T17:47:21.000Z","dependencies_parsed_at":"2024-06-18T14:15:18.415Z","dependency_job_id":null,"html_url":"https://github.com/sormy/rollup-plugin-smart-asset","commit_stats":{"total_commits":48,"total_committers":7,"mean_commits":6.857142857142857,"dds":0.5,"last_synced_commit":"2cd752d41522e974e91279a919de1dc4a4bf6429"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sormy%2Frollup-plugin-smart-asset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sormy%2Frollup-plugin-smart-asset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sormy%2Frollup-plugin-smart-asset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sormy%2Frollup-plugin-smart-asset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sormy","download_url":"https://codeload.github.com/sormy/rollup-plugin-smart-asset/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243718764,"owners_count":20336589,"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":["rollup-plugin"],"created_at":"2024-07-31T05:01:23.718Z","updated_at":"2026-03-02T22:10:37.772Z","avatar_url":"https://github.com/sormy.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Plugins"],"sub_categories":["Other File Imports"],"readme":"# Rollup Smart Asset Plugin\n\n## Overview\n\nRollup plugin to rebase, inline or copy assets referenced from the JavaScript code.\n\n## Usage\n\n```js\nimport smartAsset from \"rollup-plugin-smart-asset\"\n\nconst smartAssetOpts = { ... }\n\nexport default {\n  input: \"src/index.tsx\",\n  output: {\n    file: \"dist/index.js\",\n    format: \"iife\"\n  },\n  plugins: [\n    ...\n    smartAsset(smartAssetOpts)\n    ...\n  ]\n}\n```\n\n## Configuration\n\nFor libraries it is recommended to use `inline` or `copy` mode with `keepImport`\noption to delegate bundling to consumer's package bundler. Asset hashing is not\nneeded for this case and it is safe to set `useHash: false` and `keepName: true`.\n\nFor applications it is also recommended to use `inline` or `copy` mode with\nenabled by default hashing.\n\nDefault settings are set to be the same as in `postcss-smart-asset` to have one\nconfig for both of them.\n\nMain options:\n\n- `url`: Mode: `rebase` (default), `inline` and `copy`\n- `extensions`: What file extensions to process, defaults to\n  `[\".svg\", \".gif\", \".png\", \".jpg\"]` unless `exclude` or `include` are used.\n  This option is ignored if `include` or `exclude` options are used.\n- `include`: Micromatch pattern or array of micromatch patterns for files that\n  need to be processed by this plugin.\n- `exclude`: Micromatch pattern or array of micromatch patterns for files that\n  NOT need to be processed by this plugin.\n- `emitFiles`: Disable generating files if `false`, by default it's `true` -\n  useful when generating bundle for SSR.\n\nFor more details about `include` / `exclude` syntax please refer to:\n\u003chttps://github.com/micromatch/micromatch\u003e\n\n## Mode: rebase\n\nRebase asset references to be relative to specific directory.\n\nOutput:\n\n```js\n// without keepImport (inside wrapper)\nexport default \"public_path_to_asset\"\n\n// with keepImport and cjs module format\nconst myAsset = require(\"relative_path_to_asset_from_bundle\")\n\n// with keepImport and esm module format\nimport myAsset from \"relative_path_to_asset_from_bundle\"\n```\n\nOptions:\n\n- `publicPath`: Reference file from JS using this path, relative to html page\n  where asset is referenced. Could be relative, absolute or CDN.\n- `rebasePath`: Rebase all asset urls to this directory, defaults to current directory.\n- `keepImport`: Keep import, so consumer of your package could define their own\n  bundle configuration.\n- `sourceMap`: Set to `true` to keep source map.\n\n## Mode: inline\n\nInline assets as base64 urls directly in source code.\n\nKeep in mind, all options for `copy` mode will be used if falled back to `copy` mode.\n\nOutput:\n\n```js\nexport default \"data:{mimeType};base64,{data}\"\n```\n\nOptions:\n\n- `maxSize`: Max file size to inline (in kb), fallback is `copy` mode,\n  defaults to `14` kbytes.\n\n## Mode: copy\n\nCopy asset to target directory and rebase original references to point to target path\ndepending on provided configuration.\n\nOutput:\n\n```js\n// without keepImport (inside wrapper)\nexport default \"public_path_to_asset\"\n\n// with keepImport and cjs module format\nconst myAsset = require(\"relative_path_to_asset_from_bundle\")\n// + file is copied to target directory\n\n// with keepImport and esm module format\nimport myAsset from \"relative_path_to_asset_from_bundle\"\n// + file is copied to target directory\n```\n\nOptions:\n\n- `publicPath`: Reference file from JS using this path, relative to html page\n  where asset is referenced. Could be relative, absolute or CDN.\n- `assetsPath`: Copy assets to this directory, relative to rollup output.\n- `useHash`: Enable to use `[hash][ext]` instead of default `[name][ext]`.\n- `keepName`: Use both hash and name `[name]~[hash][ext]` if `useHash` is `true`.\n- `nameFormat`: Use custom name format using these patterns `[name]`, `[ext]`,\n  `[hash]`.\n- `hashOptions`: Hash options.\n  - `hash`: Any valid Node's crypto hashing algorithm e.g. `sha1`, `md5` etc,\n    Hash-like class (see: https://nodejs.org/api/crypto.html#crypto_class_hash),\n    `metrohash64` or `metrohash128` if `metrohash` is installed,\n    `xxhash32` or `xxhash64` if `xxhash` is installed.\n    Default is `sha1`.\n  - `encoding`: Hash encoding `hex`, `base64` `base62`, `base58`, `base52`,\n    `base49`, `base36`, `base32`, `base26`. Default is `base52`.\n  - `maxLength`: Maximum length of returned digest. Keep in mind that\n    reducing it increases collison probability. Default is `8`.\n- `keepImport`: Keep import, so consumer of your package could define their own\n  bundle configuration.\n\n**Preserve Modules**\n\nRollup `preserveModules: true` is supported but additional context is required\nfor the plugin to properly detect rebased path to the asset.\n\nAdditional options needed:\n\n- `outputDir`: Path to output dir, should be the same as `output.dir`, can't be\n  automatically detected and neeed to be explicitly passed.\n- (optional) `preserveModules`: Set to `true` to activate mode, can be\n  automatically detected.\n- (optional) `inputFile`: Path to main entry, should be the same as `input.file`,\n  can be automatically detected. Object and array values for `input.file` are not\n  supported.\n\n## Migration\n\n### Migration from v1.x to v2.x\n\nChanges:\n\n- Option `hashOptions.hash` defaults to `sha1` instead of `metrohash128`.\n- Removed dependencies: `asset-hash`.\n- These dependencies are now optional: `xxhash` and `metrohash`.\n\nThe default configuration is changed in favor of default hash functions\nthat are available in NodeJS without requirement to build any native\nextensions during `npm install`.\n\nIf you would like to use ultra fast `metrohash64` or `metrohash128` hashes\nthen do `npm install metrohash` and set `hashOptions.hash` to `metrohash64`\nor `metrohash128`.\n\nIf you would like to use ultra fast `xxhash32` or `xxhash64` hashes\nthen do `npm install xxhash` and set `hashOptions.hash` to `xxhash32`\nor `xxhash64`.\n\n## Alternatives\n\n## @rollup/plugin-url (ex rollup-plugin-url)\n\n\u003chttps://github.com/rollup/rollup-plugin-url\u003e\nor\n\u003chttps://github.com/rollup/plugins/tree/master/packages/url\u003e\n\nThis Rollup plugin has fewer options, doesn't work if asset is already loaded\nby another plugin (by sourcemaps, for example) and doesn't have `keepImport`\nlike option (designed for applications).\n\n## postcss-smart-asset\n\n\u003chttps://github.com/sebastian-software/postcss-smart-asset\u003e\n\nThis PostCSS plugin works for assets referenced from CSS, but doesn't work for\nassets imported from JavaScript.\n\n## rollup-plugin-rebase\n\n\u003chttps://github.com/sebastian-software/rollup-plugin-rebase\u003e\n\nThis Rollup plugin is designed for libraries, has `keepImport` like option\nenabled by default so can't be used for applications.\n\n## Contribution\n\nPRs are very welcome!\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsormy%2Frollup-plugin-smart-asset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsormy%2Frollup-plugin-smart-asset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsormy%2Frollup-plugin-smart-asset/lists"}