vite-plugin-manifest

raw JSON →
0.0.1 verified Mon Apr 27 auth: no javascript

Vite plugin that generates an asset manifest JSON file during build, similar to webpack-manifest-plugin. Version 0.0.1 is the initial and only release. It provides hooks to customize manifest generation and allows specifying publicPath and output fileName. Minimal alternative to other manifest plugins for Vite.

error TypeError: vitePluginManifest is not a function
cause Using named import instead of default import in ESM or forgetting .default in CommonJS.
fix
Use default import: import vitePluginManifest from 'vite-plugin-manifest'
error Cannot find module 'vite-plugin-manifest' or its corresponding type declarations.
cause Package may not be installed or TypeScript cannot resolve types since package has no types entry in package.json.
fix
Install with npm install vite-plugin-manifest and if using TypeScript, add a declare module 'vite-plugin-manifest' or use a .d.ts file.
error Error: [vite-plugin-manifest] publicPath is required
cause publicPath option was not provided but it's required for correct manifest generation.
fix
Add publicPath to plugin options, e.g., publicPath: '/'
gotcha publicPath option is required when assets are served from a subpath; if omitted, manifest uses relative paths which may break in production.
fix Set publicPath to your deployment subpath, e.g., '/my-app/'
gotcha The plugin is very early (v0.0.1) and may have bugs or missing features; not recommended for production use without testing.
fix Test thoroughly or consider more mature alternatives like vite-plugin-manifest-sri
gotcha No TypeScript definitions for the generate callback parameters; you may need to define custom types.
fix Define interfaces for manifest, entries, and chunks manually or use inferred types
gotcha Only works during build (vite build), not in dev mode; manifest will not be generated with vite dev.
fix Use only as part of your build step; for dev manifest, consider a custom middleware
npm install vite-plugin-manifest
yarn add vite-plugin-manifest
pnpm add vite-plugin-manifest

Basic setup of vite-plugin-manifest in a Vite project with custom publicPath and fileName, including optional generate callback.

// vite.config.ts
import { defineConfig } from 'vite';
import vitePluginManifest from 'vite-plugin-manifest';

export default defineConfig({
  plugins: [
    vitePluginManifest({
      publicPath: '/my-app/',
      fileName: 'asset-manifest.json',
      generate: (manifest, entries, chunks) => {
        // Customize manifest if needed
        return manifest;
      }
    })
  ]
});