Skip to content

Commit

Permalink
fix: use virtual: for virtual module (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed May 7, 2023
1 parent 400ecde commit ec4366d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-swans-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vite-plugin-checker": patch
---

use `virtual:` for virtual module
2 changes: 2 additions & 0 deletions packages/vite-plugin-checker/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const _require = createRequire(import.meta.url)
export const RUNTIME_CLIENT_RUNTIME_PATH = '/@vite-plugin-checker-runtime'
export const RUNTIME_CLIENT_ENTRY_PATH = '/@vite-plugin-checker-runtime-entry'

export const wrapVirtualPrefix = (id: `/${string}`): `virtual:${string}` =>
`virtual:${id.slice('/'.length)}`
export const composePreambleCode = (base = '/', config: Record<string, any>) => `
import { inject } from "${base}${RUNTIME_CLIENT_RUNTIME_PATH.slice(1)}";
inject({
Expand Down
7 changes: 4 additions & 3 deletions packages/vite-plugin-checker/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
RUNTIME_CLIENT_ENTRY_PATH,
RUNTIME_CLIENT_RUNTIME_PATH,
runtimeCode,
wrapVirtualPrefix,
WS_CHECKER_RECONNECT_EVENT,
} from './client/index.js'
import {
Expand Down Expand Up @@ -114,17 +115,17 @@ export function checker(userConfig: UserPluginConfig): Plugin {
},
resolveId(id) {
if (id === RUNTIME_CLIENT_RUNTIME_PATH || id === RUNTIME_CLIENT_ENTRY_PATH) {
return id
return wrapVirtualPrefix(id)
}

return
},
load(id) {
if (id === RUNTIME_CLIENT_RUNTIME_PATH) {
if (id === wrapVirtualPrefix(RUNTIME_CLIENT_RUNTIME_PATH)) {
return runtimeCode
}

if (id === RUNTIME_CLIENT_ENTRY_PATH) {
if (id === wrapVirtualPrefix(RUNTIME_CLIENT_ENTRY_PATH)) {
return composePreambleCode(devBase, overlayConfig)
}

Expand Down

0 comments on commit ec4366d

Please sign in to comment.