mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-23 10:58:13 +08:00
fix(theme): fix theme config hmr fail (#820)
This commit is contained in:
parent
1dfbb872f7
commit
48970dd559
@ -3,7 +3,7 @@ import type { App } from 'vuepress'
|
||||
import type { ThemeOptions } from '../../shared/index.js'
|
||||
import EventEmitter from 'node:events'
|
||||
import process from 'node:process'
|
||||
import { deepMerge } from '@pengzhanbo/utils'
|
||||
import { deepMerge, difference } from '@pengzhanbo/utils'
|
||||
import { watch } from 'chokidar'
|
||||
import { colors } from 'vuepress/utils'
|
||||
import { initThemeOptions } from '../config/index.js'
|
||||
@ -50,11 +50,15 @@ export class ConfigLoader extends EventEmitter {
|
||||
const watcher = watch([this.configFile, ...this.dependencies], {
|
||||
ignoreInitial: true,
|
||||
cwd,
|
||||
ignored: (filepath, stats) => {
|
||||
const isFile = Boolean(stats?.isFile())
|
||||
return isFile && filepath.includes('node_modules')
|
||||
},
|
||||
})
|
||||
|
||||
watcher.on('change', async (filepath) => {
|
||||
const dependencies = await this.load()
|
||||
watcher.add(dependencies.filter(dep => !this.dependencies.includes(dep)))
|
||||
watcher.add(difference(dependencies, this.dependencies))
|
||||
this.dependencies = [...dependencies]
|
||||
this.emit('change', this.config)
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ import process from 'node:process'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import { build } from 'esbuild'
|
||||
import { importFileDefault } from 'vuepress/utils'
|
||||
import { hash } from '../utils/index.js'
|
||||
import { hash, normalizePath } from '../utils/index.js'
|
||||
|
||||
export async function compiler(configPath?: string,
|
||||
): Promise<{
|
||||
@ -88,6 +88,8 @@ export async function compiler(configPath?: string,
|
||||
return {
|
||||
config,
|
||||
// local deps
|
||||
dependencies: Object.keys(result.metafile?.inputs ?? {}).filter(dep => dep[0] === '.'),
|
||||
dependencies: Object.keys(result.metafile?.inputs ?? {})
|
||||
.filter(dep => dep[0] === '.')
|
||||
.map(normalizePath),
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user