Skip to content

Delivering static assets from source directory #3708

Answered by brc-dd
magoerlich asked this question in Q&A
Discussion options

You must be logged in to vote

Copying with correct directory structure is the only way IMO:

// .vitepress/config.ts

import fg from 'fast-glob'
import fs from 'node:fs/promises'
import { dirname } from 'node:path'
import { defineConfig } from 'vitepress'

export default defineConfig({
  // ...

  async buildEnd({ srcDir: src, outDir: dest }) {
    const files = await fg(['**/*', '!**/*.md'], { cwd: src, absolute: true })
    await Promise.all(
      files.map(async (file) => {
        const destFile = file.replace(src, dest)
        await fs.mkdir(dirname(destFile), { recursive: true })
        await fs.copyFile(file, destFile)
      })
    )
  }
})

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@brc-dd
Comment options

Answer selected by magoerlich
@magoerlich
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants