New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

vite-plugin-collections

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-collections

A vite plugin for working with directories of markdown

latest
npmnpm
Version
1.0.0-beta.8
Version published
Maintainers
0
Created
Source

vite-plugin-collections

A Vite plugin for working with folders of markdown content.

A simple solution for building blog and docs sites.

Getting Started

Install the plugin:

pnpm install -D vite-plugin-collections

Add plugin to vite.config.ts:

import { defineConfig } from 'vite'
import collection from 'vite-plugin-collections'
import * as z from 'zod'

export default defineConfig({
  plugins: [
    // matches src/posts/*.md
    collection({
      // use folder src/posts
      base: 'posts',

      // front matter fields use a Zod schema
      fields: z.object({
        title: z.string().nonempty(),
        banner: z.url(),
        summary: z.string().optional(),
        date: z.iso.date(),
        tags: z.array(z.string()).optional(),
      })
    })
  ]
})

[!NOTE] This will add an import alias #posts, use that to access the markdown files.

Loading files

To load the list of markdown files:

import { list } from '#posts'

const posts = await list()

To load a single markdown file:

import { get } from '#posts'

const post = await get(slug)

Types

Types definitions are generated in collections.d.ts.

Add it to your tsconfig.json:

"files": [
  "collections.d.ts"
]

License

MIT

Keywords

vite

FAQs

Package last updated on 30 Jul 2025

Did you know?

Socket

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.

Install

Related posts