Registry / web-framework / unplugin-inject-preload

unplugin-inject-preload

JSON →
library3.0.0jsnpmunverified

Universal plugin to inject <link rel='preload'> tags into HTML output for Vite 4/5, Webpack 5 (with HtmlWebpackPlugin), and Rspack 1.0 (with HtmlWebpackPlugin or HtmlRspackPlugin). Current stable version is 3.0.0, released with Rspack 1.0 support and dropped support for Rspack 0.x. Replaces separate packages vite-plugin-inject-preload and html-webpack-inject-preload. Ships TypeScript types. Release cadence is irregular, with minor releases featuring breaking changes. Key differentiator: single unified API across multiple bundlers.

npm install unplugin-inject-preload
INSTALL
IMPORT
SIG · UNPLUGIN-INJECT-PR
U
unplugin-inject-preload
web-frameworkjavascriptv3.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

UnpluginInjectPreload
import UnpluginInjectPreload from 'unplugin-inject-preload/vite'
const UnpluginInjectPreload = require('unplugin-inject-preload')
Import from subpath /vite for Vite, /webpack for Webpack, /rspack for Rspack. The plugin is ESM-only; CommonJS require may fail depending on bundler.
UnpluginInjectPreload
import UnpluginInjectPreload from 'unplugin-inject-preload/webpack'
const UnpluginInjectPreload = require('unplugin-inject-preload/webpack')
For Webpack: use subpath /webpack. Requires html-webpack-plugin ≥5.0.0.
UnpluginInjectPreload
import UnpluginInjectPreload from 'unplugin-inject-preload/rspack'
const UnpluginInjectPreload = require('unplugin-inject-preload/rspack')
For Rspack: use subpath /rspack. Supports both HtmlWebpackPlugin and HtmlRspackPlugin.
UnpluginInjectPreload
import UnpluginInjectPreload from 'unplugin-inject-preload'
Direct import exists but returns a generic factory; prefer specific subpath for clarity.

Configure Vite to inject preload links for all .woff2 and .woff font files built by the bundler.

// For Vite: vite.config.ts import UnpluginInjectPreload from 'unplugin-inject-preload/vite'; export default defineConfig({ plugins: [ UnpluginInjectPreload({ files: [ { match: /\.(woff2|woff)$/, }, ], }), ], });
Debug
Known issues
breakingDrop support for Rspack 0.x versions. v3.0.0 only supports Rspack 1.0.
fix
Upgrade Rspack to 1.0.x or later. For Rspack 0.x, stick with v2.x.
affects: >=3.0.0
breakingDrop support for Vite 3. v2.0.0 requires Vite 4 or 5.
fix
Upgrade to Vite 4 or 5.
affects: >=2.0.0
deprecatedRollup 4 (shipped with Vite 5) uses base64 hashes in file names instead of base16 hashes. This may break `outputMatch` patterns expecting base16.
fix
Update your `outputMatch` regex to handle base64 hashes (e.g., allow longer alphanumeric strings).
affects: >=2.0.0
gotchaThe Vite plugin only works on build (not dev server). Assets are not available during development.
fix
Test preload injection with `vite build` only. Dev server will not inject preload links.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'unplugin-inject-preload/vite'
Missing subpath export or using wrong bundler-specific import.
fix
Ensure you are using the correct import path: 'unplugin-inject-preload/vite', '/webpack', or '/rspack'. Also verify the package is installed.
TypeError: UnpluginInjectPreload is not a function
Importing from a wrong path or using a default import when only named export exists.
fix
Use default import: import UnpluginInjectPreload from 'unplugin-inject-preload/vite'
Error: html-webpack-plugin is required as a peer dependency
Missing html-webpack-plugin for Webpack/Rspack builds.
fix
Install html-webpack-plugin@>=5.0.0 as a devDependency.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
html-webpack-pluginoptionalRequired for Webpack and Rspack (when using HtmlWebpackPlugin) builds to inject preload links.
Agent activity
2 hits · last 30 days
node
2
Resources
unplugin-inject-preload — npm install unplugin-inject-preload · libregistry