Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
vite-plugin-virtual-mpa
Advanced tools
Out-of-the-box MPA plugin for Vite, with html template engine and virtaul files support.
Out-of-the-box MPA plugin for Vite, with html template engine and virtaul files support.
There are so many MPA plugins for vite on the market, but it seems no one can do both of below at the same time:
rollupOptions.input
and SPA history fallback.pnpm add vite-plugin-virtual-mpa # or npm/yarn
// vite.config.ts
import { createMpaPlugin } from 'vite-plugin-virtual-mpa'
// @see https://vitejs.dev/config/
export default defineConfig({
plugins: [
createMpaPlugin({
pages: [
// your configuration
]
}),
],
})
interface MpaOptions {
/**
* whether to print log
*/
verbose?: boolean,
/**
* default template file
* @default index.html
*/
template?: `${string}.html`,
/**
* Configure your rewrite rules, only proceed fallback html requests.
* further: https://github.com/bripkens/connect-history-api-fallback
*/
rewrites?: Rewrite[],
/**
* your MPA core configurations
*/
pages: Array<{
/**
* Required page name.
*/
name: string;
/**
* Relative path to the output directory, which should end with .html
* @default `${name}.html`
*/
filename?: `${string}.html`;
/**
* Higher priority template file, which will overwrite the default template.
*/
template?: string;
/**
* Entry file that will append to body. which you should remove from the html template file.
*/
entry?: string;
/**
* Data to inject with ejs.
*/
data?: Record<string, any>,
}>
}
// vite.config.ts
import { createMpaPlugin } from 'vite-plugin-virtual-mpa'
// @see https://vitejs.dev/config/
export default defineConfig({
base: '/fruits/',
build: {
outDir: 'sites'
},
plugins: [
createMpaPlugin({
// This define the spa fallback rewrite rules
rewrites: [
{
from: /\/fruits\/(apple|banana|strawberries)/,
to: ctx => `/fruits/${ctx.match[1]}.html`
},
],
pages: [
{
name: 'apple',
// filename is optional, default is apple.html, which will output into sites/apple.html
filename: 'fruits/apple.html', // output into sites/fruits/apple.html
data: {
title: 'This is Apple page',
},
},
{
name: 'banana',
filename: 'fruits/banana.html',
data: {
title: 'This is Banana page',
},
},
{
name: 'strawberries',
filename: 'fruits/strawberries.html',
data: {
title: 'This is Strawberries page',
},
},
],
}),
],
})
rollupOptions.input
.build.outDir
.1.0.0
connect-history-fallback-api
for DevServer to rewrite requests.FAQs
Out-of-box MPA plugin for Vite, with html template engine and virtual files support.
The npm package vite-plugin-virtual-mpa receives a total of 1,949 weekly downloads. As such, vite-plugin-virtual-mpa popularity was classified as popular.
We found that vite-plugin-virtual-mpa demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.