Vite Vue Layouts Next Plugin

2.1.0 · active · verified Sun Apr 19

vite-plugin-vue-layouts-next is a Vite plugin designed to streamline layout management for Vue 3 applications, particularly when integrated with Vue Router. It's a maintained and improved fork of the original `vite-plugin-vue-layouts`, providing robust support for the latest ecosystem versions including Vite 8, Vue 3, and Vue Router 5. The plugin automatically processes Vue components in a designated `layouts` directory, allowing pages to declare their desired layout via route meta fields (e.g., using `lang="yaml"` blocks). It currently stands at version 2.1.0, with a recent release cadence demonstrating active development to keep pace with its peer dependencies. A key differentiator is its explicit compatibility with newer major versions of Vite and Vue Router, making it a suitable choice for projects on these updated stacks. It is also designed to work seamlessly with `vite-plugin-pages` for comprehensive auto-routing and layout solutions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate `vite-plugin-vue-layouts-next` into a Vite project using `vite.config.ts` and how to set up the generated layouts with Vue Router, specifically showing integration with `vite-plugin-pages` generated routes and the necessary TypeScript client types.

import Vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'
import Pages from 'vite-plugin-pages'
import Layouts from 'vite-plugin-vue-layouts-next'

export default defineConfig({
  plugins: [Vue(), Pages(), Layouts()],
})

// main.ts (or your router setup file)
import { setupLayouts } from 'virtual:generated-layouts'
import { createRouter, createWebHistory } from 'vue-router'
import generatedRoutes from '~pages'

// For vite-plugin-pages integration
const routes = setupLayouts(generatedRoutes)

// Or for vue-router 5's auto-routes:
// import { routes } from 'vue-router/auto-routes'
// const routes = setupLayouts(routes)

const router = createRouter({
  history: createWebHistory(),
  routes,
})

// In your tsconfig.json:
/*
{
  "compilerOptions": {
    "types": [
      "vite-plugin-vue-layouts-next/client",
      // ... other types
    ]
  }
}
*/

view raw JSON →