{"id":15376707,"url":"https://github.com/bennypowers/rollup-plugin-modulepreload","last_synced_at":"2025-04-15T16:54:23.443Z","repository":{"id":40827570,"uuid":"169171132","full_name":"bennypowers/rollup-plugin-modulepreload","owner":"bennypowers","description":"Rollup plugin to add modulepreload links from generated chunks.","archived":false,"fork":false,"pushed_at":"2023-05-28T07:24:21.000Z","size":210,"stargazers_count":17,"open_issues_count":11,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-19T12:51:19.439Z","etag":null,"topics":["es-modules","hacktoberfest","module","preload","rollup","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/bennypowers.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}},"created_at":"2019-02-05T00:30:30.000Z","updated_at":"2024-10-20T03:44:27.000Z","dependencies_parsed_at":"2024-06-19T09:26:47.455Z","dependency_job_id":null,"html_url":"https://github.com/bennypowers/rollup-plugin-modulepreload","commit_stats":{"total_commits":15,"total_committers":2,"mean_commits":7.5,"dds":0.06666666666666665,"last_synced_commit":"dc6a3c8cd401c2e2ad8537e6665965b2f4fca428"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bennypowers%2Frollup-plugin-modulepreload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bennypowers%2Frollup-plugin-modulepreload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bennypowers%2Frollup-plugin-modulepreload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bennypowers%2Frollup-plugin-modulepreload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bennypowers","download_url":"https://codeload.github.com/bennypowers/rollup-plugin-modulepreload/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240317416,"owners_count":19782388,"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":["es-modules","hacktoberfest","module","preload","rollup","rollup-plugin"],"created_at":"2024-10-01T14:08:43.697Z","updated_at":"2025-03-03T04:30:44.456Z","avatar_url":"https://github.com/bennypowers.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rollup-plugin-modulepreload\nRollup plugin to add [modulepreload links](https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload) from generated chunks. Users may customize which chunks are preloaded using the `shouldPreload` option.\n\n## Usage\n\n```js\nimport config from './rollup.config.rest.js'\nimport modulepreload from 'rollup-plugin-modulepreload';\n\nexport default {\n  plugins: [\n    modulepreload({\n      prefix: 'modules',\n      index: 'public/index.html',\n    })\n  ]\n}\n```\n\nThis will write something like the following to the `\u003chead\u003e` of index.html\n```html\n\u003clink rel=\"modulepreload\" href=\"modules/chunk-47ckl37a.js\"\u003e\n```\n\n## Options\n\n|Name|Accepts|Default|\n|-----|-----|-----|\n|`index`|Path to index.html to modify.|`undefined`|\n|`prefix`|Path to prepend to chunk filenames in link tag `href` attribute.|your bundle's `dir` option|\n|`shouldPreload`|Predicate which takes a [`ChunkInfo`](https://rollupjs.org/guide/en#generatebundle)|[Default predicate](#default-predicate)|\n\n### Determining Which Chunks to Preload\nYou can customize the function which determines whether or not to preload a chunk by passing a `shouldPreload` predicate, which takes a [`ChunkInfo`](https://rollupjs.org/guide/en#generatebundle) object.\n\nIt can be synchronous:\n```js\nfunction shouldPreload({ code }) {\n  return !!code \u0026\u0026 code.includes('INCLUDE THIS CHUNK');\n}\n\nexport default {\n  input: 'src/index.js',\n  plugins: [\n    modulepreload({\n      index: 'public/index.html',\n      prefix: 'modules',\n      shouldPreload,\n    })\n  ]\n}\n```\n\nor asynchronous:\n```js\nimport { readFile } from 'fs/promises'; // node ^14\n\nasync function shouldPreload(chunk) {\n  if (!chunk.facadeModuleId)\n    return false;\n\n  const file =\n    await readFile(chunk.facadeModuleId, 'utf-8');\n\n  return file.includes('INCLUDE THIS CHUNK');\n}\n\nexport default {\n  input: 'src/index.js',\n  plugins: [\n    modulepreload({\n      index: 'public/index.html',\n      prefix: 'modules',\n      shouldPreload,\n    })\n  ]\n}\n```\n\nThe \u003ca name=\"default-predicate\"\u003eDefault Predicate\u003c/a\u003e is :\n```js\nconst defaultShouldPreload =\n  ({ exports, facadeModuleId, isDynamicEntry }) =\u003e\n    !!(\n      // preload dynamically imported chunks\n      isDynamicEntry ||\n      // preload generated intermediate chunks\n      (exports \u0026\u0026 exports.length \u0026\u0026 !facadeModuleId)\n    );\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbennypowers%2Frollup-plugin-modulepreload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbennypowers%2Frollup-plugin-modulepreload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbennypowers%2Frollup-plugin-modulepreload/lists"}