Registry / web-framework / vite-plugin-virtual-mpa

vite-plugin-virtual-mpa

JSON →
library1.12.1jsnpmunverified

Vite plugin for building multi-page applications (MPA) with virtual file support and EJS templating. Current stable version 1.12.1, active development with regular minor/patch releases. Key differentiators: provides out-of-box MPA support without boilerplate, uses virtual HTML files (no physical templates needed), offers EJS template rendering, TypeScript types included, supports scan-based page auto-generation, and includes history fallback for dev/preview servers. Compatible with Vite >=2.0.0.

npm install vite-plugin-virtual-mpa
INSTALL
IMPORT
SIG · VITE-PLUGIN-VIRTUA
V
vite-plugin-virtual-mpa
web-frameworkjavascriptv1.12.1
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 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

createMpaPlugin
import { createMpaPlugin } from 'vite-plugin-virtual-mpa'
const createMpaPlugin = require('vite-plugin-virtual-mpa')
ESM-only; the plugin ships ESM and TypeScript definitions. CJS require will fail.
createPages
import { createPages } from 'vite-plugin-virtual-mpa'
Helper function for typed page creation; entirely optional.
MpaOptions
import type { MpaOptions } from 'vite-plugin-virtual-mpa'
Type-only import; can be used to type the options object externally.
default
import vitePluginVirtualMpa from 'vite-plugin-virtual-mpa'
import { default } from 'vite-plugin-virtual-mpa'
Default export is not exposed; use named import 'createMpaPlugin' instead.

Minimal MPA setup with two pages (index, about) using EJS template and custom rewrite rule.

// vite.config.ts import { defineConfig } from 'vite'; import { createMpaPlugin, createPages } from 'vite-plugin-virtual-mpa'; const pages = createPages([ { name: 'index', filename: 'index.html', entry: 'src/pages/index/main.ts', }, { name: 'about', filename: 'about.html', entry: 'src/pages/about/main.ts', template: 'src/pages/about/template.html', // custom EJS template }, ]); export default defineConfig({ plugins: [ createMpaPlugin({ pages, verbose: true, rewrites: [ { from: '/about', to: '/about.html' }, ], transformHtml: (html, { page }) => { // inject page-specific meta tags return html.replace('</head>', `<meta name="page" content="${page.name}"></head>`); }, }), ], });
Debug
Known issues
breakingv1.0.0 removed support for CommonJS require; ESM import is required.
fix
Use import instead of require().
affects: >=1.0.0
gotchapage 'name' must not contain '/' characters; it is used for default redirect rules.
fix
Use only alphanumeric characters, hyphens, or underscores for page names.
affects: >=1.0.0
deprecatedThe 'pages' option was previously required to be passed directly; now can be built via createPages or scanOptions.
fix
Use the modern API: createPages([]) or scanOptions.
affects: <0.9.0
gotchaWhen using scanOptions, scanned pages with same name as explicit pages will be ignored.
fix
Ensure explicit page names are unique to avoid unexpected overrides.
affects: >=1.0.0
breakingVite 2 used a different transformIndexHtml API; plugin is designed for Vite >=2, but behavior may differ.
fix
Use Vite >=3 for full compatibility; the plugin is tested with Vite 4 and 5.
affects: >=2.0.0
Errors
Common errors & fixes
Error: [vite-plugin-virtual-mpa] Failed to compile EJS template: Could not find matching close tag for "<% %>"
EJS syntax error in a template file (e.g., unclosed tag).
fix
Fix EJS syntax (e.g., close all <% %> tags). Check for missing closing '%>'. The plugin stops dev server on EJS error in recent versions.
TypeError: createMpaPlugin is not a function
CommonJS require() used instead of ESM import.
fix
Replace `const { createMpaPlugin } = require(...)` with `import { createMpaPlugin } from 'vite-plugin-virtual-mpa'`.
[plugin:vite-plugin-virtual-mpa] Cannot find module 'src/pages/.../main.ts'
Entry file specified in page config does not exist at the given path.
fix
Check the 'entry' path relative to project root. Ensure the file exists.
Error: Page name must not contain '/'
Page 'name' contains a slash character.
fix
Remove slashes from page name; use only alphanumerics, hyphens, underscores.
Upgrade
Version history
1.12.1latest on npm
Audit
Dependencies
viterequiredPeer dependency, core build tool
Agent activity
12 hits · last 30 days
node
8
OpenAI (training)
2
Resources
vite-plugin-virtual-mpa — npm install vite-plugin-virtual-mpa · libregistry