Skip to content

Commit 0b05246

Browse files
committed
refactor: simplify rootDir option
1 parent 6c1f66e commit 0b05246

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

packages/nuxt/src/auto-hmr-plugin.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,13 @@ function nameFromDeclaration(node?: VariableDeclarator) {
1515
return node?.id.type === 'Identifier' && node.id.name
1616
}
1717

18-
export function autoRegisterHMRPlugin(
19-
nuxt: Nuxt,
20-
{ resolve }: { resolve: (...path: string[]) => string }
21-
) {
22-
const projectBasePath = resolve(nuxt.options.rootDir)
23-
18+
export function autoRegisterHMRPlugin(rootDir: string) {
2419
return {
2520
name: 'pinia:auto-hmr-registration',
2621

2722
transform(code, id) {
2823
if (id.startsWith('\x00')) return
29-
if (!id.startsWith(projectBasePath)) return
24+
if (!id.startsWith(rootDir)) return
3025
if (!code.includes('defineStore') || code.includes('acceptHMRUpdate')) {
3126
return
3227
}

packages/nuxt/src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({
8787

8888
// Register automatic hmr code plugin - dev mode only
8989
if (nuxt.options.dev) {
90-
addVitePlugin(autoRegisterHMRPlugin(nuxt, { resolve }))
90+
addVitePlugin(autoRegisterHMRPlugin(resolve(nuxt.options.rootDir)))
9191
}
9292
},
9393
})

0 commit comments

Comments
 (0)