MCPcopy Index your code
hub / github.com/IndexXuan/vite-plugin-mpa

github.com/IndexXuan/vite-plugin-mpa @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
16 symbols 60 edges 20 files 5 documented · 31%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

vite-plugin-mpa

Out-of-the-box multi-page-application (MPA) support for Vite - supports Vue2/3, React and others

wakatime NPM Publish downloads npm version License: MIT

Motivation

  • Vite natively supports multi-page apps, but you must configure rollupOptions.input manually
  • When running vite dev, you must open localhost:3000/src/pages/index/xxx.html for $projectRoot/src/pages/index/xxx.html
  • Similar to vue-cli, this plugin helps rewrite urls for MPA and auto open the first page for you
  • Experimental: when building, organize the folder for you (like vue-cli) - e.g dist/src/pages/subpage/index.html will move to dist/subpage/index.html

Usage

yarn add vite-plugin-mpa
// vite.config.ts
import mpa from 'vite-plugin-mpa'

// @see https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    // ...other plugins
    mpa(/* options */),
  ],
})

Options

{
  /**
   * open url path when server starts (customizable)
   * @default path of first-page
   */
  open: string
  /**
   * where to locate pages
   * @default 'src/pages', e.g. src/views
   */
  scanDir: string
  /**
   * how to locate page files (passed to fast-glob), e.g. index.{js,jsx}
   * @default 'main.{js,ts,jsx,tsx}'
   */
  scanFile: string
  /**
   * what is your html file name, e.g. index.html / main.html / entry.html / template.html
   * @default 'index.html'
   */
  filename: string
}

Examples

  • see src/examples

  • use shelljs after-build to organize dist folder (may be a better approach - help wanted)

How It Works

  • Uses fast-glob to collect all pages, e.g. src/pages/*/main.{js,ts}, and calc MPA entries
  • The result is passed into vite#rollupOptions#input

Further Info

Extension points exported contracts — how you extend this code

MpaOptions (Interface)
(no doc)
src/lib/options.ts

Core symbols most depended-on inside this repo

resolve
called by 5
src/index.ts
mpa
called by 3
src/index.ts
scanFile2Html
called by 2
src/lib/utils.ts
getPagesInfo
called by 2
src/lib/utils.ts
getFirstPage
called by 1
src/lib/utils.ts
genFileName
called by 1
src/lib/utils.ts
parseEntryFile
called by 1
src/lib/utils.ts
parseFiles
called by 1
src/lib/utils.ts

Shape

Function 15
Interface 1

Languages

TypeScript100%

Modules by API surface

src/lib/utils.ts8 symbols
src/index.ts5 symbols
src/lib/options.ts1 symbols
examples/react-mpa-app/src/pages/subpage/App.tsx1 symbols
examples/react-mpa-app/src/pages/index/App.tsx1 symbols

For agents

$ claude mcp add vite-plugin-mpa \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page