Skip to content

Commit 0d396af

Browse files
authored
fix: inspector url (#4707)
1 parent bd9c968 commit 0d396af

File tree

1 file changed

+9
-2
lines changed
  • packages-integrations/inspector/src

1 file changed

+9
-2
lines changed

packages-integrations/inspector/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,15 @@ export default function UnocssInspector(ctx: UnocssPluginContext): Plugin {
115115
server.printUrls = () => {
116116
_printUrls()
117117
for (const localUrl of server.resolvedUrls?.local ?? []) {
118-
const url = server.config.base ? localUrl.replace(server.config.base, '') : localUrl
119-
const inspectorUrl = url.endsWith('/') ? `${url}${baseUrl}/` : `${url}/${baseUrl}/`
118+
// server.config.base will be normalized with leading and trailing slashes,
119+
// but localUrl might not have a trailing slash
120+
const appUrl = localUrl.endsWith('/') ? localUrl : `${localUrl}/`
121+
// remove the base path from appUrl if possible
122+
const serverUrl = server.config.base && appUrl.endsWith(server.config.base)
123+
? appUrl.slice(0, -server.config.base.length)
124+
: appUrl.slice(0, -1) // remove the trailing slash
125+
// we removed the trailing slash from serverUrl when removing the base, add it back
126+
const inspectorUrl = `${serverUrl}/${baseUrl}/`
120127
// eslint-disable-next-line no-console
121128
console.log(` ${green('➜')} ${bold('UnoCSS Inspector')}: ${colorUrl(`${inspectorUrl}`)}`)
122129
}

0 commit comments

Comments
 (0)