From 3023b5c76be50da1cb8837ac93671d5288b863f2 Mon Sep 17 00:00:00 2001 From: huluobotx Date: Sat, 16 Sep 2023 16:53:08 +0800 Subject: [PATCH] fix(build): respect srcExclude in content loader (#2963) Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> --- src/node/config.ts | 1 + src/node/contentLoader.ts | 3 ++- src/node/plugin.ts | 6 ------ src/node/plugins/dynamicRoutesPlugin.ts | 10 +++++++--- src/node/shims.d.ts | 7 +++++++ src/node/siteConfig.ts | 1 + 6 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 src/node/shims.d.ts diff --git a/src/node/config.ts b/src/node/config.ts index b2425c3e..1a6fe9e1 100644 --- a/src/node/config.ts +++ b/src/node/config.ts @@ -97,6 +97,7 @@ export async function resolveConfig( const config: SiteConfig = { root, srcDir, + srcExclude: userConfig.srcExclude || [], assetsDir, site, themeDir, diff --git a/src/node/contentLoader.ts b/src/node/contentLoader.ts index 228d83a5..69802c22 100644 --- a/src/node/contentLoader.ts +++ b/src/node/contentLoader.ts @@ -106,7 +106,8 @@ export function createContentLoader( // the loader is being called directly, do a fresh glob files = ( await glob(pattern, { - ignore: ['**/node_modules/**', '**/dist/**'] + cwd: config.srcDir, + ignore: ['**/node_modules/**', '**/dist/**', ...config.srcExclude] }) ).sort() } diff --git a/src/node/plugin.ts b/src/node/plugin.ts index 70eb9aea..6566c781 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -28,12 +28,6 @@ import { webFontsPlugin } from './plugins/webFontsPlugin' import { slash, type PageDataPayload } from './shared' import { deserializeFunctions, serializeFunctions } from './utils/fnSerialize' -declare module 'vite' { - interface UserConfig { - vitepress?: SiteConfig - } -} - const themeRE = /\/\.vitepress\/theme\/index\.(m|c)?(j|t)s$/ const hashRE = /\.(\w+)\.js$/ const staticInjectMarkerRE = diff --git a/src/node/plugins/dynamicRoutesPlugin.ts b/src/node/plugins/dynamicRoutesPlugin.ts index 5003af23..62fac771 100644 --- a/src/node/plugins/dynamicRoutesPlugin.ts +++ b/src/node/plugins/dynamicRoutesPlugin.ts @@ -7,7 +7,7 @@ import { import fs from 'fs-extra' import c from 'picocolors' import path from 'path' -import fg from 'fast-glob' +import glob from 'fast-glob' import { type SiteConfig, type UserConfig } from '../siteConfig' 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 // supported in Node 12+, which is required by Vite. const allMarkdownFiles = ( - await fg(['**.md'], { + await glob(['**.md'], { cwd: srcDir, - ignore: ['**/node_modules', ...(userConfig.srcExclude || [])] + ignore: [ + '**/node_modules/**', + '**/dist/**', + ...(userConfig.srcExclude || []) + ] }) ).sort() diff --git a/src/node/shims.d.ts b/src/node/shims.d.ts new file mode 100644 index 00000000..645841c6 --- /dev/null +++ b/src/node/shims.d.ts @@ -0,0 +1,7 @@ +import 'vite' + +declare module 'vite' { + interface UserConfig { + vitepress?: import('./config').SiteConfig + } +} diff --git a/src/node/siteConfig.ts b/src/node/siteConfig.ts index d5ec6b83..39aa1a01 100644 --- a/src/node/siteConfig.ts +++ b/src/node/siteConfig.ts @@ -216,6 +216,7 @@ export interface SiteConfig > { root: string srcDir: string + srcExclude: string[] site: SiteData configPath: string | undefined configDeps: string[]