vite-plugin-vue-layouts is a Vite plugin designed to simplify the implementation of router-based layouts in Vue 3 applications. It is currently at version 0.11.0 and is actively maintained, with regular updates and fixes. The plugin works by transforming Vue Router configurations, effectively wrapping page components within specified layout components as nested routes. It integrates seamlessly with `vite-plugin-pages` and `unplugin-vue-router`, allowing developers to define layouts for individual pages using route blocks (e.g., `<route lang="yaml"> meta: { layout: 'my-layout' } </route>`). Layout components, typically stored in `src/layouts`, are automatically discovered and asynchronously imported, providing a structured approach to managing application layouts.
npm install vite-plugin-vue-layoutsVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic setup, integrating the plugin with Vite, Vue, and Vue Router to enable router-based layouts using `vite-plugin-pages`.
Ensure your project's `vite`, `vue`, and `vue-router` versions meet the new peer dependency requirements (Vite ^4.0.0 || ^5.0.0, Vue ^3.2.4, Vue Router ^4.0.11). Revert to an earlier version of `vite-plugin-vue-layouts` if older environment support is strictly necessary.
Set `pagesDir: null` in the plugin configuration to revert to the old behavior of watching all files, or specify an array of paths/globs if your pages are in multiple non-default locations, e.g., `pagesDir: ['src/pages', 'src/**/pages']`.
Always define a `default.vue` layout component in your `layoutsDirs` (e.g., `src/layouts/default.vue`) to ensure all pages have a fallback layout. Alternatively, explicitly set the `defaultLayout` option in the plugin configuration.
Add `"vite-plugin-vue-layouts/client"` to the `compilerOptions.types` array in your `tsconfig.json`. Ensure the plugin is correctly instantiated in `vite.config.ts` and that your `main.ts` imports `setupLayouts` from `virtual:generated-layouts`.
Verify that `Layouts()` is included in your `plugins` array in `vite.config.js` (or `.ts`). Ensure there are no syntax errors in your Vite configuration file that might prevent the plugin from initializing.
Double-check your `pagesDir` and `layoutsDirs` options in the plugin configuration. If you moved your pages or layouts, update these paths. Remember that `pagesDir` changed default in v0.9.0; setting `pagesDir: null` might resolve issues if you need broader file watching.