fix(build): respect srcExclude in content loader (#2963)

Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
pull/2975/head
huluobotx 1 year ago committed by GitHub
parent 3174f2193f
commit 3023b5c76b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -97,6 +97,7 @@ export async function resolveConfig(
const config: SiteConfig = { const config: SiteConfig = {
root, root,
srcDir, srcDir,
srcExclude: userConfig.srcExclude || [],
assetsDir, assetsDir,
site, site,
themeDir, themeDir,

@ -106,7 +106,8 @@ export function createContentLoader<T = ContentData[]>(
// the loader is being called directly, do a fresh glob // the loader is being called directly, do a fresh glob
files = ( files = (
await glob(pattern, { await glob(pattern, {
ignore: ['**/node_modules/**', '**/dist/**'] cwd: config.srcDir,
ignore: ['**/node_modules/**', '**/dist/**', ...config.srcExclude]
}) })
).sort() ).sort()
} }

@ -28,12 +28,6 @@ import { webFontsPlugin } from './plugins/webFontsPlugin'
import { slash, type PageDataPayload } from './shared' import { slash, type PageDataPayload } from './shared'
import { deserializeFunctions, serializeFunctions } from './utils/fnSerialize' import { deserializeFunctions, serializeFunctions } from './utils/fnSerialize'
declare module 'vite' {
interface UserConfig {
vitepress?: SiteConfig
}
}
const themeRE = /\/\.vitepress\/theme\/index\.(m|c)?(j|t)s$/ const themeRE = /\/\.vitepress\/theme\/index\.(m|c)?(j|t)s$/
const hashRE = /\.(\w+)\.js$/ const hashRE = /\.(\w+)\.js$/
const staticInjectMarkerRE = const staticInjectMarkerRE =

@ -7,7 +7,7 @@ import {
import fs from 'fs-extra' import fs from 'fs-extra'
import c from 'picocolors' import c from 'picocolors'
import path from 'path' import path from 'path'
import fg from 'fast-glob' import glob from 'fast-glob'
import { type SiteConfig, type UserConfig } from '../siteConfig' import { type SiteConfig, type UserConfig } from '../siteConfig'
import { resolveRewrites } from './rewritesPlugin' import { resolveRewrites } from './rewritesPlugin'
@ -21,9 +21,13 @@ export async function resolvePages(srcDir: string, userConfig: UserConfig) {
// JavaScript built-in sort() is mandated to be stable as of ES2019 and // JavaScript built-in sort() is mandated to be stable as of ES2019 and
// supported in Node 12+, which is required by Vite. // supported in Node 12+, which is required by Vite.
const allMarkdownFiles = ( const allMarkdownFiles = (
await fg(['**.md'], { await glob(['**.md'], {
cwd: srcDir, cwd: srcDir,
ignore: ['**/node_modules', ...(userConfig.srcExclude || [])] ignore: [
'**/node_modules/**',
'**/dist/**',
...(userConfig.srcExclude || [])
]
}) })
).sort() ).sort()

@ -0,0 +1,7 @@
import 'vite'
declare module 'vite' {
interface UserConfig {
vitepress?: import('./config').SiteConfig
}
}

@ -216,6 +216,7 @@ export interface SiteConfig<ThemeConfig = any>
> { > {
root: string root: string
srcDir: string srcDir: string
srcExclude: string[]
site: SiteData<ThemeConfig> site: SiteData<ThemeConfig>
configPath: string | undefined configPath: string | undefined
configDeps: string[] configDeps: string[]

Loading…
Cancel
Save