Skip to content

Commit 16e4123

Browse files
authored
fix: inconsistent handling of non-ASCII base in resolveConfig and dev server (#10247)
1 parent c22f50c commit 16e4123

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

packages/vite/src/node/config.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'node:fs'
22
import path from 'node:path'
3-
import { parse as parseUrl, pathToFileURL } from 'node:url'
3+
import { pathToFileURL } from 'node:url'
44
import { performance } from 'node:perf_hooks'
55
import { createRequire } from 'node:module'
66
import colors from 'picocolors'
@@ -808,33 +808,34 @@ export function resolveBaseUrl(
808808
)
809809
)
810810
)
811-
base = '/'
811+
return '/'
812812
}
813813

814-
// external URL
815-
if (isExternalUrl(base)) {
816-
if (!isBuild) {
817-
// get base from full url during dev
818-
const parsed = parseUrl(base)
819-
base = parsed.pathname || '/'
820-
}
821-
} else {
814+
// external URL flag
815+
const isExternal = isExternalUrl(base)
816+
// no leading slash warn
817+
if (!isExternal && !base.startsWith('/')) {
818+
logger.warn(
819+
colors.yellow(colors.bold(`(!) "base" option should start with a slash.`))
820+
)
821+
}
822+
// no ending slash warn
823+
if (!base.endsWith('/')) {
824+
logger.warn(
825+
colors.yellow(colors.bold(`(!) "base" option should end with a slash.`))
826+
)
827+
}
828+
829+
// parse base when command is serve or base is not External URL
830+
if (!isBuild || !isExternal) {
831+
base = new URL(base, 'http://vitejs.dev').pathname
822832
// ensure leading slash
823833
if (!base.startsWith('/')) {
824-
logger.warn(
825-
colors.yellow(
826-
colors.bold(`(!) "base" option should start with a slash.`)
827-
)
828-
)
829834
base = '/' + base
830835
}
831836
}
832-
833837
// ensure ending slash
834838
if (!base.endsWith('/')) {
835-
logger.warn(
836-
colors.yellow(colors.bold(`(!) "base" option should end with a slash.`))
837-
)
838839
base += '/'
839840
}
840841

0 commit comments

Comments
 (0)