{"id":13774327,"url":"https://github.com/vikerman/rollup-plugin-hoist-import-deps","last_synced_at":"2025-05-11T06:32:53.246Z","repository":{"id":40790699,"uuid":"265164262","full_name":"vikerman/rollup-plugin-hoist-import-deps","owner":"vikerman","description":"A rollup plugin to speed up lazy loading","archived":false,"fork":false,"pushed_at":"2025-05-02T15:17:09.000Z","size":280,"stargazers_count":67,"open_issues_count":19,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-02T16:27:00.743Z","etag":null,"topics":["code-splitting","rollup","rollup-plugins"],"latest_commit_sha":null,"homepage":null,"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/vikerman.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,"zenodo":null}},"created_at":"2020-05-19T06:28:57.000Z","updated_at":"2024-11-05T06:21:50.000Z","dependencies_parsed_at":"2024-02-16T17:51:29.819Z","dependency_job_id":"33677bb7-3c51-468e-9729-054e1cf2d20c","html_url":"https://github.com/vikerman/rollup-plugin-hoist-import-deps","commit_stats":{"total_commits":87,"total_committers":6,"mean_commits":14.5,"dds":0.5747126436781609,"last_synced_commit":"a40352ed89603a1f89bdc55d429a97c970f577cb"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vikerman%2Frollup-plugin-hoist-import-deps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vikerman%2Frollup-plugin-hoist-import-deps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vikerman%2Frollup-plugin-hoist-import-deps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vikerman%2Frollup-plugin-hoist-import-deps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vikerman","download_url":"https://codeload.github.com/vikerman/rollup-plugin-hoist-import-deps/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253528400,"owners_count":21922623,"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":["code-splitting","rollup","rollup-plugins"],"created_at":"2024-08-03T17:01:25.710Z","updated_at":"2025-05-11T06:32:52.991Z","avatar_url":"https://github.com/vikerman.png","language":"JavaScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Modules"],"readme":"# rollup-plugin-hoist-import-deps\n\nChange dynamic import call sites to also parallely load the static imports of the dynamic chunk being loaded.\n\nThis can avoid waterfalls when dynamically importing chunks and can improve performance of lazy loading chunks, especially on slow/high latency connections.\n\n## Install\n\n```sh\nnpm i --save-dev rollup-plugin-hoist-import-deps\n```\n\nor\n\n```sh\nyarn add -D rollup-plugin-hoist-import-deps\n```\n\n## Usage\n\n```js\nimport { hoistImportDeps } from 'rollup-plugin-hoist-import-deps';\n\nexport default {\n  entry: 'src/main.js',\n  output: {\n    dir: 'output',\n    format: 'es',\n  },\n  plugins: [hoistImportDeps()],\n};\n```\n\n## Options\n\n### `baseUrl`\n\nType: `String`\u003cbr\u003e\nDefault: `''`\n\nThe `baseUrl` of be used when preloading the JavaScript files. This is the path of the JS files relative to the `index.html` (or whatever HTML that is loading the scripts).\n\nValid only when `method` is `preload`.\n\nExample - If your index.html is served from `/` and the JS is served from `/client`, set `baseUrl` to `'client'` so that the\n`href` in the preload links are properly preficed with `/client'.\n\n```js\n    plugins: [hoistImportDeps({baseUrl: 'client'})],\n```\n\n### `setAnonymousCrossOrigin`\n\nType: `boolean`\u003cbr\u003e\nDefault: `true`\n\nWhether to set the crossorigin attribute of the link element to `'anonymous'` when using the link preload method. In certain cases setting this flag to `false` becomes necessary (See https://github.com/vikerman/rollup-plugin-hoist-import-deps/issues/12).\n\nValid only when `method` is `preload`.\n\nDon't set this option to `false` unless you know what you are doing.\n\nExample:\n\n```js\n    plugins: [hoistImportDeps({setAnonymousCrossOrigin: false})],\n```\n\n## Example\n\nLets say you have a entry-point file `a.js` that dynamically imports `b.js`\nand `b.js` in turn statically imports `c.js`.\n\n```js\n// a.js\nexport async function myFunction(x) {\n  const { inc } = await import('./b.js'); // Dynamic import\n\n  return x * inc(x);\n}\n```\n\n```js\n// b.js\nimport { add } from './c.js'; // Static import\n\nexport function inc(x) {\n  return add(x, 1);\n}\n```\n\n```js\n// c.js\nexport function add(x, y) {\n  return x + y;\n}\n```\n\nWithout this plugin, the output chunk for `a.js` would look something like:\n\n```js\n// output/a.js\nasync function myFunction(x) {\n  const { inc } = await import('./b-467ea706.js');\n\n  return x * inc(x);\n}\n\nexport { myFunction };\n```\n\nWith the plugin the output chunks for `a.js` would be transformed to look\nsomething like:\n\n```js\nfunction __loadDeps(baseImport, ...deps) {\n  for (const dep of deps) {\n     // Preload code goes here.\n     ...\n  }\n  return import(baseImport);\n}\n\nasync function myFunction(x) {\n  const { inc } = await __loadDeps('./b-467ea706.js', './c-a66d9c36.js');\n\n  return x * inc(x);\n}\n\nexport { myFunction };\n```\n\nSo when `./b-467ea706.js` is dynamically imported it avoids the JS load\nwaterfall where its static import `./c-a66d9c36.js` is loaded in parallel\ninstead of sequentially after downloading and parsing the chunk\n`./b-467ea706.js`.\n\nThis plugin can make a significant (positive) difference when say lazily\nloading code over a slow/high latency 3G connection (in the order of 1-2\nseconds).\n\n## Preload fallback\n\nThe preload code first tried to use link preload as the method to preload the\nstatic dependencies. If that's not supported in the browser it just falls back\nto using `fetch` to preload the dependencies.\n\n## Prefetch support\n\nThis plugin also allows you to prefetch the script specified by your dynamic\nimport, by setting `window.HOIST_PREFETCH`. This puts the preloader code in\nprefetch mode where both dependencies and the actual import are prefetched\nistead of actually being loaded. This tries to use the browser link prefetch\nmethod which will download the scripts in lower priority. When link prefetch\nis unavailable it just uses fetch with requestIdleCallback.\n\nIn the following example instead of loading `b.js` and preload it's\ndependencies, it will prefetch `b.js` and its dependencies.\n\nLater when actual `import('./b.js')` is executed without the prefetch, it\nwill load the modules from the prefetch cache instead of going to the\nnetwork.\n\n```js\nwindow.HOIST_PREFETCH = true;\ntry {\n  import('./b.js');\n} finally {\n  window.HOIST_PREFETCH = undefined;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvikerman%2Frollup-plugin-hoist-import-deps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvikerman%2Frollup-plugin-hoist-import-deps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvikerman%2Frollup-plugin-hoist-import-deps/lists"}