Skip to content

Commit 0acd96f

Browse files
committed
wip
1 parent c2ab5b0 commit 0acd96f

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/node/plugins/dynamicRoutesPlugin.ts

+12-14
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import path from 'node:path'
33
import c from 'picocolors'
44
import { glob } from 'tinyglobby'
55
import {
6+
EnvironmentModuleNode,
67
loadConfigFromFile,
78
normalizePath,
89
type Logger,
9-
type Plugin,
10-
type ViteDevServer
10+
type Plugin
1111
} from 'vite'
1212
import { type SiteConfig, type UserConfig } from '../siteConfig'
1313
import { resolveRewrites } from './rewritesPlugin'
@@ -96,15 +96,9 @@ export type ResolvedRouteConfig = UserRouteConfig & {
9696
export const dynamicRoutesPlugin = async (
9797
config: SiteConfig
9898
): Promise<Plugin> => {
99-
let server: ViteDevServer
100-
10199
return {
102100
name: 'vitepress:dynamic-routes',
103101

104-
configureServer(_server) {
105-
server = _server
106-
},
107-
108102
resolveId(id) {
109103
if (!id.endsWith('.md')) return
110104
const normalizedId = id.startsWith(config.srcDir)
@@ -139,28 +133,32 @@ export const dynamicRoutesPlugin = async (
139133
}
140134

141135
// params are injected with special markers and extracted as part of
142-
// __pageData in ../markdownTovue.ts
136+
// __pageData in ../markdownToVue.ts
143137
return `__VP_PARAMS_START${JSON.stringify(
144138
params
145139
)}__VP_PARAMS_END__${baseContent}`
146140
}
147141
},
148142

149-
async handleHotUpdate(ctx) {
150-
routeModuleCache.delete(ctx.file)
151-
const mods = config.dynamicRoutes.fileToModulesMap[ctx.file]
143+
async hotUpdate(ctx) {
144+
const file = ctx.file
145+
const modules: EnvironmentModuleNode[] = []
146+
147+
const mods = config.dynamicRoutes.fileToModulesMap[file]
152148
if (mods) {
153149
// path loader module or deps updated, reset loaded routes
154-
if (!ctx.file.endsWith('.md')) {
150+
if (!file.endsWith('.md')) {
155151
Object.assign(
156152
config,
157153
await resolvePages(config.srcDir, config.userConfig, config.logger)
158154
)
159155
}
160156
for (const id of mods) {
161-
ctx.modules.push(server.moduleGraph.getModuleById(id)!)
157+
modules.push(this.environment.moduleGraph.getModuleById(id)!)
162158
}
163159
}
160+
161+
return modules.length > 0 ? [...ctx.modules, ...modules] : undefined
164162
}
165163
}
166164
}

src/node/plugins/staticDataPlugin.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const staticDataPlugin: Plugin = {
7070
if (existing) {
7171
;({ watch, load } = existing)
7272
} else {
73-
// use vite's load config util as a away to load Node.js file with
73+
// use vite's load config util as a way to load Node.js file with
7474
// TS & native ESM support
7575
const res = await loadConfigFromFile({} as any, id.replace(/\?.*$/, ''))
7676

@@ -125,8 +125,8 @@ export const staticDataPlugin: Plugin = {
125125

126126
hotUpdate(ctx) {
127127
const file = ctx.file
128-
129128
const modules: EnvironmentModuleNode[] = []
129+
130130
// dependency of data loader changed
131131
// (note the dep array includes the loader file itself)
132132
if (file in depToLoaderModuleIdMap) {

0 commit comments

Comments
 (0)