diff --git a/packages/histoire/src/node/markdown.ts b/packages/histoire/src/node/markdown.ts index 7e5eb8d2..2559bdb1 100644 --- a/packages/histoire/src/node/markdown.ts +++ b/packages/histoire/src/node/markdown.ts @@ -9,6 +9,7 @@ import MarkdownIt from 'markdown-it' import anchor from 'markdown-it-anchor' import attrs from 'markdown-it-attrs' import { full as emoji } from 'markdown-it-emoji' +import micromatch from 'micromatch' import path from 'pathe' import pc from 'picocolors' import { getHighlighter } from 'shiki-es' @@ -137,9 +138,18 @@ export async function createMarkdownPlugins(ctx: Context) { export async function createMarkdownFilesWatcher(ctx: Context) { const md = await createMarkdownRendererWithPlugins(ctx) - const watcher = chokidar.watch(['**/*.story.md'], { + const watcher = chokidar.watch('.', { cwd: ctx.root, - ignored: ctx.config.storyIgnored, + ignored: (path, stats) => { + if (ctx.config.storyIgnored.some(pattern => micromatch.isMatch(path, pattern))) { + return true + } + if (micromatch.isMatch(path, '**/*.story.md')) { + return false + } + + return stats?.isFile() + }, }) /** diff --git a/packages/histoire/src/node/stories.ts b/packages/histoire/src/node/stories.ts index 171e9b93..3ed51797 100644 --- a/packages/histoire/src/node/stories.ts +++ b/packages/histoire/src/node/stories.ts @@ -46,6 +46,7 @@ export async function watchStories(newContext: Context) { context = newContext const watcher = chokidar.watch('.', { + cwd: context.root, ignored: (path, stats) => { if (context.config.storyIgnored.some(pattern => micromatch.isMatch(path, pattern))) { return true @@ -56,7 +57,6 @@ export async function watchStories(newContext: Context) { return stats?.isFile() }, - cwd: context.root, }) watcher