Rollup plugin that adds modulepreload link tags to HTML files for dynamically imported chunks, improving loading performance by hinting the browser to preload ES modules before they are needed. Current version 2.0.0 (released 2021, maintained). Allows customization of which chunks to preload via a synchronous or asynchronous predicate, with default that preloads dynamic entry points and intermediate chunks with exports. Differentiates from generic HTML injectors by focusing specifically on modulepreload semantics and Rollup's chunk metadata.
npm install rollup-plugin-modulepreloadVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage with Rollup config: sets up modulepreload for all chunks, writes <link modulepreload> tags into public/index.html.
Provide an index path (relative to project root) or use output.dir and ensure index exists.
Override shouldPreload to restrict to certain chunks based on your app's structure.
Explicitly set prefix to a URL path (e.g., 'modules') that matches where chunks are served from.
Use synchronous predicate if possible, or cache file reads.
Run npm install rollup-plugin-modulepreload --save-dev
Use const modulepreload = require('rollup-plugin-modulepreload').defaultEnsure the index file exists and the path is relative to the project root (not the output directory).
Add output.dir to your Rollup output options.