Registry /
web-framework / vite-static-assets-plugin
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
muslnode 18–223 runs
build_error
glibcnode 18–223 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
staticAssetsPlugin (default)
✓ import staticAssetsPlugin from 'vite-static-assets-plugin'
✗ import { staticAssetsPlugin } from 'vite-static-assets-plugin'
Plugin is exported as default export only. Named import will be undefined.
staticAssets
✓ import { staticAssets } from './static-assets'
✗ import { staticAssets } from 'vite-static-assets-plugin'
staticAssets is generated by the plugin in the output file, not exported by the package itself.
StaticAssetPath (type)
✓ import { StaticAssetPath } from './static-assets'
✗ import { StaticAssetPath } from 'vite-static-assets-plugin'
Type is generated by the plugin, not from the package. Path must match output file.
FilesInFolder (generic)
✓ import { FilesInFolder } from './static-assets'
Must provide a string literal directory path as generic parameter, e.g. FilesInFolder<'images/'>.
Configures the plugin in vite.config.ts and imports generated types/functions.
// vite.config.ts
import { defineConfig } from 'vite';
import staticAssetsPlugin from 'vite-static-assets-plugin';
export default defineConfig({
plugins: [
staticAssetsPlugin({
directory: 'public', // default
outputFile: 'static-assets.ts', // default
include: ['**\/*'], // default: all files
exclude: [], // default: none
debounceMs: 100, // default: 100
scanDepth: 10, // default: 10
emptyDirBehaviour: 'skip', // default: skip
leadingSlash: true, // default: true
})
]
});
// After running Vite dev/build, import from generated file:
import { staticAssets, StaticAssetPath, FilesInFolder } from './static-assets';
const url = staticAssets('images/logo.svg'); // returns '/images/logo.svg'
const path: StaticAssetPath = 'fonts/roboto.woff2';
type SvgIcons = FilesInFolder<'icons/'>; // union of paths like 'icons/circle.svg' | 'icons/square.svg'
Errors
Common errors & fixes
Cannot find module './static-assets' or its corresponding type declarations.
The generated file may not exist (forgot to run Vite dev/build) or the path is incorrect.
fixRun 'vite' or 'vite build' once to generate the file, then check the output path matches your import.
TypeError: staticAssets is not a function
Importing from the wrong module (e.g., from 'vite-static-assets-plugin' instead of generated file).
fixImport { staticAssets } from './static-assets' (or your configured output file). TS2582: Cannot find name 'StaticAssetPath'.
Type import path is incorrect or missing generated file.
fixAdd import type { StaticAssetPath } from './static-assets'; and ensure the generated file is in your tsconfig includes. Audit
Dependencies
typescriptrequiredPeer dependency for type generation; plugin requires TypeScript >=5.0
viterequiredPeer dependency; requires Vite >=6.2